diff --git a/android/src/main/java/com/twilio/voice/flutter/TwilioVoiceFlutterPlugin.java b/android/src/main/java/com/twilio/voice/flutter/TwilioVoiceFlutterPlugin.java index 6a77cad..cc2a15f 100644 --- a/android/src/main/java/com/twilio/voice/flutter/TwilioVoiceFlutterPlugin.java +++ b/android/src/main/java/com/twilio/voice/flutter/TwilioVoiceFlutterPlugin.java @@ -107,7 +107,8 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) { break; case "makeCall": String to = call.argument("to"); - makeCall(to, result); + Map data = call.argument("data"); + makeCall(to, data, result); break; case "activeCall": result.success(getCallDetails()); @@ -178,7 +179,7 @@ public void onError(RegistrationException error, String accessToken, String fcmT }); } - private void makeCall(String to, Result result) { + private void makeCall(String to, Map data, Result result) { String accessToken = preferencesUtils.getAccessToken(); if (accessToken == null) { result.error("NO_ACCESS_TOKEN", "No access token available", null); @@ -187,10 +188,9 @@ private void makeCall(String to, Result result) { sendEvent("callConnecting", ""); - Map params = new HashMap<>(); - params.put("to", to); + data.put("to", to); ConnectOptions connectOptions = new ConnectOptions.Builder(accessToken) - .params(params) + .params(data) .build(); activeCall = Voice.connect(context, connectOptions, callListener); diff --git a/lib/twilio_voice_flutter.dart b/lib/twilio_voice_flutter.dart index d68614f..e3c19bb 100644 --- a/lib/twilio_voice_flutter.dart +++ b/lib/twilio_voice_flutter.dart @@ -13,8 +13,8 @@ class TwilioVoiceFlutter { static const MethodChannel _channel = MethodChannel('twilio_voice_flutter'); /// Method channel used to listen for responses from the native platform regarding Twilio voice events. - static const MethodChannel _eventChannel = - MethodChannel('twilio_voice_flutter_response'); + static const EventChannel _eventChannel = + EventChannel('twilio_voice_flutter_events'); /// StreamController for managing the stream of [TwilioVoiceFlutterEvent] events. static late StreamController _streamController; @@ -31,18 +31,20 @@ class TwilioVoiceFlutter { _streamController = StreamController.broadcast(); /// Set the method call handler for the event channel to process events coming from the native platform. - _eventChannel.setMethodCallHandler((event) async { - log("Call event: ${event.method} . Arguments: ${event.arguments}"); + _eventChannel.receiveBroadcastStream().listen((event) async { + final method = event["event"]; + final arguments = event["data"]; + log("Call event: $method . Arguments: $arguments"); try { /// Get the event type based on the event method name. - final eventType = getEventType(event.method); + final eventType = getEventType(method); TwilioVoiceFlutterCall? call; /// Try to create a TwilioVoiceFlutterCall object from the event arguments. try { call = TwilioVoiceFlutterCall.fromMap( - Map.from(event.arguments)); + Map.from(arguments)); } catch (error) { log("$error"); @@ -53,7 +55,7 @@ class TwilioVoiceFlutter { _streamController.add(TwilioVoiceFlutterEvent(eventType, call)); } catch (error, stack) { /// Log any error encountered during the event handling process. - log("Error parsing call event. ${event.arguments}", + log("Error parsing call event. ${arguments}", error: error, stackTrace: stack); } }); @@ -125,7 +127,7 @@ class TwilioVoiceFlutter { /// [data] is optional and can include additional information to send with the call; defaults to an empty map. static Future makeCall({ required String to, - Map data = const {}, + Map data = const {}, }) async { final args = { "to": to.trim().replaceAll(" ", ""),