Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> data = call.argument("data");
makeCall(to, data, result);
break;
case "activeCall":
result.success(getCallDetails());
Expand Down Expand Up @@ -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<String, String> data, Result result) {
String accessToken = preferencesUtils.getAccessToken();
if (accessToken == null) {
result.error("NO_ACCESS_TOKEN", "No access token available", null);
Expand All @@ -187,10 +188,9 @@ private void makeCall(String to, Result result) {

sendEvent("callConnecting", "");

Map<String, String> 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);

Expand Down
18 changes: 10 additions & 8 deletions lib/twilio_voice_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<TwilioVoiceFlutterEvent> _streamController;
Expand All @@ -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<String, dynamic>.from(event.arguments));
Map<String, dynamic>.from(arguments));
} catch (error) {
log("$error");

Expand All @@ -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);
}
});
Expand Down Expand Up @@ -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<TwilioVoiceFlutterCall> makeCall({
required String to,
Map<String, dynamic> data = const <String, dynamic>{},
Map<String, String> data = const <String, String>{},
}) async {
final args = <String, Object>{
"to": to.trim().replaceAll(" ", ""),
Expand Down