File tree Expand file tree Collapse file tree 4 files changed +36
-1
lines changed
Expand file tree Collapse file tree 4 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 1+ ## Next Release
2+
3+ * Feat: [ Web] Add Twilio Device [ DeviceState] accessor protecting un/registration.
4+ * Docs: update CHANGELOG
5+
16## 0.3.2+2
27
38* Fix: [ iOS] show caller number or interpretted client name for performStartCallAction
Original file line number Diff line number Diff line change @@ -82,6 +82,11 @@ class Device extends Twilio {
8282 /// Documentation: https://www.twilio.com/docs/voice/sdks/javascript/twiliodevice#deviceupdateoptionsoptions
8383 @JS ("updateOptions" )
8484 external void updateOptions (DeviceOptions options);
85+
86+ /// Get current call status, see [DeviceState]
87+ /// Documentation: https://www.twilio.com/docs/voice/sdks/javascript/twiliodevice#devicestate
88+ @JS ("status" )
89+ external String state ();
8590}
8691
8792/// Device options
Original file line number Diff line number Diff line change 1+ enum DeviceState {
2+ destroyed,
3+ unregistered,
4+ registering,
5+ registered,
6+ }
7+
8+ DeviceState parseDeviceState (String state) {
9+ final lower = state.toLowerCase ();
10+ return DeviceState .values.firstWhere (
11+ (e) => e.name == lower,
12+ orElse: () => DeviceState .unregistered,
13+ );
14+ }
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import 'package:web_callkit/web_callkit_web.dart';
2929import '../twilio_voice.dart' ;
3030import './js/js.dart' as twilio_js;
3131import 'js/core/enums/device_sound_name.dart' ;
32+ import 'js/device/device_status.dart' ;
3233import 'js/utils/js_object_utils.dart' ;
3334import 'local_storage_web/local_storage_web.dart' ;
3435import 'method_channel/twilio_call_method_channel.dart' ;
@@ -310,7 +311,12 @@ class TwilioVoiceWeb extends MethodChannelTwilioVoice {
310311 @override
311312 Future <bool ?> unregister ({String ? accessToken}) async {
312313 if (device == null ) {
313- return false ;
314+ return true ;
315+ }
316+ final state = getDeviceState (device! );
317+ if (state != DeviceState .registered) {
318+ printDebug ("Device is not registered, cannot unregister" );
319+ return true ;
314320 }
315321 try {
316322 device? .unregister ();
@@ -551,6 +557,11 @@ class TwilioVoiceWeb extends MethodChannelTwilioVoice {
551557 sounds: js_util.jsify (_soundMap),
552558 );
553559 }
560+
561+ DeviceState getDeviceState (twilio_js.Device device) {
562+ final status = device.state ();
563+ return parseDeviceState (status);
564+ }
554565}
555566
556567class Call extends MethodChannelTwilioCall {
You can’t perform that action at this time.
0 commit comments