place method
Place outgoing call from
to to
. Returns true if successful, false otherwise.
Generally accepted format is e164 (e.g. US number +15555555555)
alternatively, use 'client:${clientId}' to call a Twilio Client connection
Parameters send to Twilio's REST API endpoint 'makeCall' can be passed in extraOptions
;
Parameters are reduced to this format
{
"From": from,
"To": to,
...extraOptions
}
See twilio_js.Device.connect
Implementation
@override
Future<bool?> place({required String from, required String to, 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}) ] ");
assert(from.isNotEmpty, "From cannot be empty");
assert(to.isNotEmpty, "To cannot be empty");
assert(extraOptions?.keys.contains("From") ?? true, "From cannot be passed in extraOptions");
assert(extraOptions?.keys.contains("To") ?? true, "To cannot be passed in extraOptions");
Logger.logLocalEvent("Making new call");
// handle parameters
final params = <String, String>{
"From": from,
"To": to,
};
extraOptions?.forEach((key, value) {
params[key] = value.toString();
});
// this.callOutgoing = true;
// Log.d(TAG, "calling to " + call.argument("To").toString());
// final options = twilioJs.DeviceConnectOptions(params);
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;
}