Skip to content

Commit

Permalink
Merge branch 'feat_connect_raw_params'
Browse files Browse the repository at this point in the history
  • Loading branch information
cybex-dev committed May 14, 2024
2 parents 211b082 + c3e3e21 commit e4b4c2b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* [Web] Added environment registration support
* Added `defines.config.json` file to example to support environment configuration used with ```flutter run --dart-defines-file=defines.config.json```
* [Web] Added `FIREBASE_ENABLE` defines to initialize Firebase only if set to true
* [Web] Added raw `Connect({Map<String, dynamic>?})` sent to TwiML webhook.

## 0.1.3
* Added: CallEvents:
Expand Down
6 changes: 6 additions & 0 deletions lib/_internal/method_channel/twilio_call_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,10 @@ class MethodChannelTwilioCall extends TwilioCallPlatform {
Future<bool?> isBluetoothOn() {
return _channel.invokeMethod('isBluetoothOn', <String, dynamic>{});
}

/// Only web supported for now.
@override
Future<bool?> connect({Map<String, dynamic>? extraOptions}) {
return Future.value(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ abstract class TwilioCallPlatform extends SharedPlatformInterface {
/// [extraOptions] will be added to the callPayload sent to your server
Future<bool?> place({required String from, required String to, Map<String, dynamic>? extraOptions});

/// Place outgoing call with raw parameters. Returns true if successful, false otherwise.
/// Parameters send to Twilio's REST API endpoint 'makeCall' can be passed in [extraOptions];
/// Parameters are reduced to this format
/// <code>
/// {
/// ...extraOptions
/// }
/// </code>
/// [extraOptions] will be added to the call payload sent to your server
Future<bool?> connect({Map<String, dynamic>? extraOptions});

/// Hangs up active call
Future<bool?> hangUp();

Expand Down
35 changes: 35 additions & 0 deletions lib/_internal/twilio_voice_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,41 @@ class Call extends MethodChannelTwilioCall {
return true;
}

/// Place outgoing call with raw parameters. Returns true if successful, false otherwise.
/// Parameters send to Twilio's REST API endpoint 'makeCall' can be passed in [extraOptions];
/// Parameters are reduced to this format
/// <code>
/// {
/// ...extraOptions
/// }
/// </code>
/// See [twilio_js.Device.connect]
@override
Future<bool?> connect({Map<String, dynamic>? extraOptions}) async {
assert(device != null,
"Twilio device is null, make sure you have initialized the device first by calling [ setTokens({required String accessToken, String? deviceToken}) ] ");

Logger.logLocalEvent("Making new call with Connect");
// handle parameters
final params = <String, String>{};
extraOptions?.forEach((key, value) {
params[key] = value.toString();
});

try {
final callParams = js_util.jsify(params);
final options = twilio_js.DeviceConnectOptions(params: callParams);
final promise = _device!.connect(options);
nativeCall = await js_util.promiseToFuture(promise);

_attachCallEventListeners(_jsCall!);
} catch (e) {
printDebug("Failed to place call: $e");
return false;
}
return true;
}

/// Attach event listeners to the active call
/// See [twilio_js.Call.on]
void _attachCallEventListeners(twilio_js.Call call) {
Expand Down

0 comments on commit e4b4c2b

Please sign in to comment.