setTokens method
Creates and registered the Twilio Device. Returns true if successful, false otherwise.
See twilio_js.Device.new
Note: deviceToken
is ignored for web
Implementation
@override
Future<bool?> setTokens({required String accessToken, String? deviceToken}) async {
// TODO use updateOptions for Twilio device
assert(accessToken.isNotEmpty, "Access token cannot be empty");
// assert(deviceToken != null && deviceToken.isNotEmpty, "Device token cannot be null or empty");
// if (device != null) {
// // check active calls?
// printDebug("Twilio device already active, unregistering...");
// try {
// await device!.unregister();
//
// } catch (e) {
// printDebug("Failed to unregister device: $e");
// return false;
// }
// }
try {
/// opus set as primary code
/// https://www.twilio.com/blog/client-javascript-sdk-1-7-ga
List<String> codecs = ["opus", "pcmu"];
twilio_js.DeviceInitOptions options = twilio_js.DeviceInitOptions(
codecPreferences: codecs,
closeProtection: true,
);
/// create new Twilio device
device = twilio_js.Device(accessToken, options);
_call.device = device;
_attachDeviceListeners(device!);
// Register device to accept notifications
device!.register();
return true;
} catch (e) {
printDebug("Failed to set Twilio Device token: $e");
return false;
}
}