|
|
@ -11,13 +11,13 @@ class DjPrinter {
|
|
|
|
factory DjPrinter() => _instance;
|
|
|
|
factory DjPrinter() => _instance;
|
|
|
|
static const MethodChannel _channel = MethodChannel('dj_printer');
|
|
|
|
static const MethodChannel _channel = MethodChannel('dj_printer');
|
|
|
|
static const EventChannel _deviceChannel =
|
|
|
|
static const EventChannel _deviceChannel =
|
|
|
|
EventChannel("com.discovery.devices");
|
|
|
|
EventChannel("com.discovery.devices");
|
|
|
|
StreamSubscription? _discoveryStream;
|
|
|
|
StreamSubscription? _discoveryStream;
|
|
|
|
|
|
|
|
|
|
|
|
StreamSubscription addDiscoveryListen(
|
|
|
|
StreamSubscription addDiscoveryListen(
|
|
|
|
{required void Function(dynamic data) onReceive,
|
|
|
|
{required void Function(dynamic data) onReceive,
|
|
|
|
void Function()? onStart,
|
|
|
|
void Function()? onStart,
|
|
|
|
void Function()? onFinish}) {
|
|
|
|
void Function()? onFinish}) {
|
|
|
|
if (_discoveryStream == null) {
|
|
|
|
if (_discoveryStream == null) {
|
|
|
|
return _deviceChannel.receiveBroadcastStream().listen((data) {
|
|
|
|
return _deviceChannel.receiveBroadcastStream().listen((data) {
|
|
|
|
if (data == "start" && onStart != null) {
|
|
|
|
if (data == "start" && onStart != null) {
|
|
|
@ -34,18 +34,17 @@ class DjPrinter {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cancelDiscovery() {
|
|
|
|
void cancelDiscovery() {
|
|
|
|
if (_discoveryStream != null) {
|
|
|
|
_discoveryStream?.cancel();
|
|
|
|
_discoveryStream!.cancel();
|
|
|
|
_discoveryStream = null;
|
|
|
|
_discoveryStream = null;
|
|
|
|
print('结束搜索');
|
|
|
|
}
|
|
|
|
disposeDiscovery();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const EventChannel _connectChannel = EventChannel("com.connect");
|
|
|
|
static const EventChannel _connectChannel = EventChannel("com.connect");
|
|
|
|
StreamSubscription? _connectStream;
|
|
|
|
StreamSubscription? _connectStream;
|
|
|
|
|
|
|
|
|
|
|
|
StreamSubscription addConnectListen(
|
|
|
|
StreamSubscription addConnectListen({required void Function() onConnect,
|
|
|
|
{required void Function() onConnect,
|
|
|
|
required void Function() onDisconnect}) {
|
|
|
|
required void Function() onDisconnect}) {
|
|
|
|
|
|
|
|
if (_connectStream == null) {
|
|
|
|
if (_connectStream == null) {
|
|
|
|
return _connectChannel.receiveBroadcastStream().listen((data) {
|
|
|
|
return _connectChannel.receiveBroadcastStream().listen((data) {
|
|
|
|
if (data == 'connected') {
|
|
|
|
if (data == 'connected') {
|
|
|
@ -66,9 +65,8 @@ class DjPrinter {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<bool?> get startSearch async {
|
|
|
|
void get startSearch {
|
|
|
|
final res = await _channel.invokeMethod('startSearch');
|
|
|
|
final res = _channel.invokeMethod('startSearch');
|
|
|
|
return res;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<bool?> connect(String address) async {
|
|
|
|
Future<bool?> connect(String address) async {
|
|
|
@ -76,6 +74,16 @@ class DjPrinter {
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void disposeDiscovery() {
|
|
|
|
|
|
|
|
print('disposeDiscovery');
|
|
|
|
|
|
|
|
final res = _channel.invokeMethod('disposeDiscovery');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<bool?> disposeConnect() async {
|
|
|
|
|
|
|
|
final res = await _channel.invokeMethod('disposeConnect');
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<bool?> init() async {
|
|
|
|
Future<bool?> init() async {
|
|
|
|
final res = await _channel.invokeMethod('init');
|
|
|
|
final res = await _channel.invokeMethod('init');
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
@ -104,13 +112,12 @@ class DjPrinter {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<bool?> print(
|
|
|
|
Future<bool?> printAScode({required String code,
|
|
|
|
{required String code,
|
|
|
|
required String channel,
|
|
|
|
required String channel,
|
|
|
|
required String country,
|
|
|
|
required String country,
|
|
|
|
required String countStr,
|
|
|
|
required String countStr,
|
|
|
|
required int offset,
|
|
|
|
required int offset,
|
|
|
|
required bool hasPlan}) async {
|
|
|
|
required bool hasPlan}) async {
|
|
|
|
|
|
|
|
final res = await _channel.invokeMethod('print', {
|
|
|
|
final res = await _channel.invokeMethod('print', {
|
|
|
|
'code': code,
|
|
|
|
'code': code,
|
|
|
|
'channel': channel,
|
|
|
|
'channel': channel,
|
|
|
|