configure method

Future<void> configure({
  1. required String developerId,
  2. required String appKeyIOS,
  3. required String appIdIOS,
  4. required String appKeyAndroid,
  5. required String appIdAndroid,
})

Implementation

Future<void> configure({
  required String developerId,
  required String appKeyIOS,
  required String appIdIOS,
  required String appKeyAndroid,
  required String appIdAndroid,
}) async {
  Map<String, dynamic> params;

  if (Platform.isIOS) {
    params = {
      'developerId': developerId,
      'appKey': appKeyIOS,
      'appId': appIdIOS,
    };
  } else {
    params = {
      'developerId': developerId,
      'appKey': appKeyAndroid,
      'appId': appIdAndroid,
    };
  }

  _channel.setMethodCallHandler((MethodCall call) async {
    if (call.method == 'devices') {
      final devicesJson = call.arguments as List;
      final devices = devicesJson.map((x) => x as Map).map((x) => SocketMobileDevice.fromJson(x)).toList();

      this.devices = devices;
      _devicesController.sink.add(devices);
    } else if (call.method == 'data') {
      final String text = call.arguments['message'];
      final Map deviceJson = call.arguments['device'];
      final device = SocketMobileDevice.fromJson(deviceJson);
      final message = SocketMobileMessage(text, device);

      _messageController.sink.add(message);
    } else {
      print('[SocketMobile] unknown method ${call.method}');
    }
  });

  await _channel.invokeMethod('configure', params);
}