Skip to content

Commit d59b2ca

Browse files
committed
fix: prevent duplicate TwilioVoiceWeb instances
1 parent a4e7395 commit d59b2ca

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Feat: [Web] Check unnecessary updating device with the same token.
77
* Feat: [Web] Update internal [CallStatus] mapping method.
88
* Fix: [Web] Await Twilio Device `register()` and `unregister()` method calls.
9+
* Fix: [Web] Prevent duplicate `TwilioVoiceWeb` instances.
910
* Feat: update example.
1011
* Docs: update CHANGELOG
1112

lib/_internal/twilio_voice_web.dart

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Logger {
8484

8585
/// The web implementation of [TwilioVoicePlatform].
8686
class TwilioVoiceWeb extends MethodChannelTwilioVoice {
87-
87+
8888
static const _codecs = ["opus", "pcmu"];
8989
static const _closeProtection = true;
9090
final Map<String, String> _soundMap = {};
@@ -171,8 +171,10 @@ class TwilioVoiceWeb extends MethodChannelTwilioVoice {
171171
@override
172172
Call get call => _call;
173173

174+
static final TwilioVoicePlatform _instance = TwilioVoiceWeb();
175+
174176
static void registerWith(Registrar registrar) {
175-
TwilioVoicePlatform.instance = TwilioVoiceWeb();
177+
TwilioVoicePlatform.instance = _instance;
176178
}
177179

178180
Stream<CallEvent>? _callEventsListener;
@@ -373,16 +375,16 @@ class TwilioVoiceWeb extends MethodChannelTwilioVoice {
373375
device!.updateToken(accessToken);
374376
} else {
375377
/// opus set as primary code
376-
/// https://www.twilio.com/blog/client-javascript-sdk-1-7-ga
377-
List<String> codecs = ["opus", "pcmu"];
378-
twilio_js.DeviceOptions options = twilio_js.DeviceOptions(
379-
codecPreferences: codecs,
380-
closeProtection: true,
381-
);
382-
383-
/// create new Twilio device
384-
device = twilio_js.Device(accessToken, options);
385-
_call.device = device;
378+
/// https://www.twilio.com/blog/client-javascript-sdk-1-7-ga
379+
List<String> codecs = ["opus", "pcmu"];
380+
twilio_js.DeviceOptions options = twilio_js.DeviceOptions(
381+
codecPreferences: codecs,
382+
closeProtection: true,
383+
);
384+
385+
/// create new Twilio device
386+
device = twilio_js.Device(accessToken, options);
387+
_call.device = device;
386388
_attachDeviceListeners(device!);
387389

388390
// Register device to accept notifications

0 commit comments

Comments
 (0)