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
+
1
6
## 0.3.2+2
2
7
3
8
* 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 {
82
82
/// Documentation: https://www.twilio.com/docs/voice/sdks/javascript/twiliodevice#deviceupdateoptionsoptions
83
83
@JS ("updateOptions" )
84
84
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 ();
85
90
}
86
91
87
92
/// 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';
29
29
import '../twilio_voice.dart' ;
30
30
import './js/js.dart' as twilio_js;
31
31
import 'js/core/enums/device_sound_name.dart' ;
32
+ import 'js/device/device_status.dart' ;
32
33
import 'js/utils/js_object_utils.dart' ;
33
34
import 'local_storage_web/local_storage_web.dart' ;
34
35
import 'method_channel/twilio_call_method_channel.dart' ;
@@ -310,7 +311,12 @@ class TwilioVoiceWeb extends MethodChannelTwilioVoice {
310
311
@override
311
312
Future <bool ?> unregister ({String ? accessToken}) async {
312
313
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 ;
314
320
}
315
321
try {
316
322
device? .unregister ();
@@ -551,6 +557,11 @@ class TwilioVoiceWeb extends MethodChannelTwilioVoice {
551
557
sounds: js_util.jsify (_soundMap),
552
558
);
553
559
}
560
+
561
+ DeviceState getDeviceState (twilio_js.Device device) {
562
+ final status = device.state ();
563
+ return parseDeviceState (status);
564
+ }
554
565
}
555
566
556
567
class Call extends MethodChannelTwilioCall {
You can’t perform that action at this time.
0 commit comments