@wazo/sdk 0.37.27 → 0.37.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/README.md +3 -2
  2. package/dist/wazo-sdk.js +4 -4
  3. package/esm/__tests__/web-rtc-client.test.js +9 -1
  4. package/esm/checker/Checker.js +9 -1
  5. package/esm/checker/checks/index.js +9 -1
  6. package/esm/checker/checks/webrtc-transport.js +9 -1
  7. package/esm/checker/checks/webrtc.js +9 -1
  8. package/esm/domain/CallSession.js +29 -2
  9. package/esm/domain/Phone/CTIPhone.js +29 -2
  10. package/esm/domain/Phone/WebRTCPhone.js +57 -4
  11. package/esm/domain/SFUNotAvailableError.js +9 -0
  12. package/esm/domain/__tests__/CallSession.test.js +46 -2
  13. package/esm/domain/__tests__/IndirectTransfer.test.js +29 -2
  14. package/esm/domain/__tests__/Room.test.js +29 -2
  15. package/esm/index.js +77 -5
  16. package/esm/simple/Auth.js +76 -5
  17. package/esm/simple/Configuration.js +76 -5
  18. package/esm/simple/Phone.js +76 -5
  19. package/esm/simple/index.js +76 -5
  20. package/esm/simple/room/LocalParticipant.js +76 -5
  21. package/esm/simple/room/Participant.js +76 -5
  22. package/esm/simple/room/RemoteParticipant.js +76 -5
  23. package/esm/simple/room/Room.js +76 -5
  24. package/esm/simple/room/SipRoom.js +76 -5
  25. package/esm/simple/room/Stream.js +76 -5
  26. package/esm/simple/room/__tests__/RemoteParticipant.test.js +76 -5
  27. package/esm/simple/utils.js +76 -5
  28. package/esm/web-rtc-client.js +9 -1
  29. package/lib/__tests__/web-rtc-client.test.js +9 -1
  30. package/lib/checker/Checker.js +9 -1
  31. package/lib/checker/checks/index.js +9 -1
  32. package/lib/checker/checks/webrtc-transport.js +9 -1
  33. package/lib/checker/checks/webrtc.js +9 -1
  34. package/lib/domain/CallSession.js +29 -2
  35. package/lib/domain/Phone/CTIPhone.js +29 -2
  36. package/lib/domain/Phone/WebRTCPhone.js +57 -3
  37. package/lib/domain/SFUNotAvailableError.js +11 -0
  38. package/lib/domain/__tests__/CallSession.test.js +46 -2
  39. package/lib/domain/__tests__/IndirectTransfer.test.js +29 -2
  40. package/lib/domain/__tests__/Room.test.js +29 -2
  41. package/lib/index.js +77 -5
  42. package/lib/simple/Auth.js +76 -5
  43. package/lib/simple/Configuration.js +76 -5
  44. package/lib/simple/Phone.js +76 -5
  45. package/lib/simple/index.js +76 -5
  46. package/lib/simple/room/LocalParticipant.js +76 -5
  47. package/lib/simple/room/Participant.js +76 -5
  48. package/lib/simple/room/RemoteParticipant.js +76 -5
  49. package/lib/simple/room/Room.js +76 -5
  50. package/lib/simple/room/SipRoom.js +76 -5
  51. package/lib/simple/room/Stream.js +76 -5
  52. package/lib/simple/room/__tests__/RemoteParticipant.test.js +76 -5
  53. package/lib/simple/utils.js +76 -5
  54. package/lib/web-rtc-client.js +9 -1
  55. package/package.json +1 -1
  56. package/src/domain/CallSession.js +32 -4
  57. package/src/domain/Phone/WebRTCPhone.js +27 -1
  58. package/src/domain/SFUNotAvailableError.js +7 -0
  59. package/src/domain/__tests__/CallSession.test.js +17 -0
  60. package/src/index.js +2 -0
  61. package/src/simple/Phone.js +2 -1
  62. package/src/simple/index.js +2 -0
  63. package/src/web-rtc-client.js +9 -1
@@ -34,13 +34,16 @@ var updateFrom = (instance , from ) => {
34
34
 
35
35
 
36
36
 
37
+
37
38
 
38
39
 
39
40
 
40
41
 
41
42
 
43
+
42
44
 
43
45
 
46
+
44
47
 
45
48
 
46
49
 
@@ -57,6 +60,7 @@ var updateFrom = (instance , from ) => {
57
60
 
58
61
 
59
62
 
63
+
60
64
 
61
65
 
62
66
  class CallSession {
@@ -76,10 +80,14 @@ class CallSession {
76
80
 
77
81
 
78
82
 
79
-
83
+
84
+
85
+ // = creationTime
80
86
 
81
87
 
82
88
 
89
+
90
+
83
91
 
84
92
 
85
93
 
@@ -115,6 +123,8 @@ class CallSession {
115
123
 
116
124
 
117
125
 
126
+
127
+
118
128
 
119
129
  constructor({
120
130
  answered,
@@ -128,6 +138,8 @@ class CallSession {
128
138
  paused,
129
139
  ringing,
130
140
  startTime,
141
+ creationTime,
142
+ endTime,
131
143
  cameraEnabled,
132
144
  dialedExtension,
133
145
  sipCallId,
@@ -140,12 +152,16 @@ class CallSession {
140
152
  recording,
141
153
  recordingPaused,
142
154
  videoRemotelyDowngraded,
155
+ sipSession,
156
+ answerTime,
143
157
  } ) {
144
158
  this.callId = callId;
145
159
  this.sipCallId = sipCallId;
146
160
  this.displayName = displayName;
147
161
  this.number = number;
162
+ this.creationTime = creationTime;
148
163
  this.startTime = startTime;
164
+ this.endTime = endTime;
149
165
  this.isCaller = isCaller;
150
166
  this.answered = answered;
151
167
  this.answeredBySystem = answeredBySystem;
@@ -164,6 +180,8 @@ class CallSession {
164
180
  this.recording = recording || false;
165
181
  this.recordingPaused = recordingPaused || false;
166
182
  this.videoRemotelyDowngraded = videoRemotelyDowngraded;
183
+ this.sipSession = sipSession;
184
+ this.answerTime = answerTime || this.answerTime;
167
185
 
168
186
  // Useful to compare instead of instanceof with minified code
169
187
  this.type = 'CallSession';
@@ -194,7 +212,7 @@ class CallSession {
194
212
  }
195
213
 
196
214
  answer() {
197
- this.answered = true;
215
+ this.answerTime = new Date();
198
216
  }
199
217
 
200
218
  systemAnswer() {
@@ -350,6 +368,15 @@ class CallSession {
350
368
  return newFrom(callSession, CallSession);
351
369
  }
352
370
 
371
+ // Retro-compatibility: `answered` was a boolean before. We can reproduce the behaviour with a getter/setter
372
+ set answered(value ) {
373
+ this.answerTime = value ? this.answerTime || new Date() : null;
374
+ }
375
+
376
+ get answered() {
377
+ return !!this.answerTime;
378
+ }
379
+
353
380
  static parseCall(call ) {
354
381
  return new CallSession({
355
382
  callId: call.id,
@@ -34,13 +34,16 @@ var updateFrom = (instance , from ) => {
34
34
 
35
35
 
36
36
 
37
+
37
38
 
38
39
 
39
40
 
40
41
 
41
42
 
43
+
42
44
 
43
45
 
46
+
44
47
 
45
48
 
46
49
 
@@ -57,6 +60,7 @@ var updateFrom = (instance , from ) => {
57
60
 
58
61
 
59
62
 
63
+
60
64
 
61
65
 
62
66
  class CallSession {
@@ -76,10 +80,14 @@ class CallSession {
76
80
 
77
81
 
78
82
 
79
-
83
+
84
+
85
+ // = creationTime
80
86
 
81
87
 
82
88
 
89
+
90
+
83
91
 
84
92
 
85
93
 
@@ -115,6 +123,8 @@ class CallSession {
115
123
 
116
124
 
117
125
 
126
+
127
+
118
128
 
119
129
  constructor({
120
130
  answered,
@@ -128,6 +138,8 @@ class CallSession {
128
138
  paused,
129
139
  ringing,
130
140
  startTime,
141
+ creationTime,
142
+ endTime,
131
143
  cameraEnabled,
132
144
  dialedExtension,
133
145
  sipCallId,
@@ -140,12 +152,16 @@ class CallSession {
140
152
  recording,
141
153
  recordingPaused,
142
154
  videoRemotelyDowngraded,
155
+ sipSession,
156
+ answerTime,
143
157
  } ) {
144
158
  this.callId = callId;
145
159
  this.sipCallId = sipCallId;
146
160
  this.displayName = displayName;
147
161
  this.number = number;
162
+ this.creationTime = creationTime;
148
163
  this.startTime = startTime;
164
+ this.endTime = endTime;
149
165
  this.isCaller = isCaller;
150
166
  this.answered = answered;
151
167
  this.answeredBySystem = answeredBySystem;
@@ -164,6 +180,8 @@ class CallSession {
164
180
  this.recording = recording || false;
165
181
  this.recordingPaused = recordingPaused || false;
166
182
  this.videoRemotelyDowngraded = videoRemotelyDowngraded;
183
+ this.sipSession = sipSession;
184
+ this.answerTime = answerTime || this.answerTime;
167
185
 
168
186
  // Useful to compare instead of instanceof with minified code
169
187
  this.type = 'CallSession';
@@ -194,7 +212,7 @@ class CallSession {
194
212
  }
195
213
 
196
214
  answer() {
197
- this.answered = true;
215
+ this.answerTime = new Date();
198
216
  }
199
217
 
200
218
  systemAnswer() {
@@ -350,6 +368,15 @@ class CallSession {
350
368
  return newFrom(callSession, CallSession);
351
369
  }
352
370
 
371
+ // Retro-compatibility: `answered` was a boolean before. We can reproduce the behaviour with a getter/setter
372
+ set answered(value ) {
373
+ this.answerTime = value ? this.answerTime || new Date() : null;
374
+ }
375
+
376
+ get answered() {
377
+ return !!this.answerTime;
378
+ }
379
+
353
380
  static parseCall(call ) {
354
381
  return new CallSession({
355
382
  callId: call.id,
package/lib/index.js CHANGED
@@ -3260,13 +3260,16 @@ var updateFrom = (instance , from ) => {
3260
3260
 
3261
3261
 
3262
3262
 
3263
+
3263
3264
 
3264
3265
 
3265
3266
 
3266
3267
 
3267
3268
 
3269
+
3268
3270
 
3269
3271
 
3272
+
3270
3273
 
3271
3274
 
3272
3275
 
@@ -3283,6 +3286,7 @@ var updateFrom = (instance , from ) => {
3283
3286
 
3284
3287
 
3285
3288
 
3289
+
3286
3290
 
3287
3291
 
3288
3292
  class CallSession {
@@ -3302,10 +3306,14 @@ class CallSession {
3302
3306
 
3303
3307
 
3304
3308
 
3305
-
3309
+
3310
+
3311
+ // = creationTime
3306
3312
 
3307
3313
 
3308
3314
 
3315
+
3316
+
3309
3317
 
3310
3318
 
3311
3319
 
@@ -3341,6 +3349,8 @@ class CallSession {
3341
3349
 
3342
3350
 
3343
3351
 
3352
+
3353
+
3344
3354
 
3345
3355
  constructor({
3346
3356
  answered,
@@ -3354,6 +3364,8 @@ class CallSession {
3354
3364
  paused,
3355
3365
  ringing,
3356
3366
  startTime,
3367
+ creationTime,
3368
+ endTime,
3357
3369
  cameraEnabled,
3358
3370
  dialedExtension,
3359
3371
  sipCallId,
@@ -3366,12 +3378,16 @@ class CallSession {
3366
3378
  recording,
3367
3379
  recordingPaused,
3368
3380
  videoRemotelyDowngraded,
3381
+ sipSession,
3382
+ answerTime,
3369
3383
  } ) {
3370
3384
  this.callId = callId;
3371
3385
  this.sipCallId = sipCallId;
3372
3386
  this.displayName = displayName;
3373
3387
  this.number = number;
3388
+ this.creationTime = creationTime;
3374
3389
  this.startTime = startTime;
3390
+ this.endTime = endTime;
3375
3391
  this.isCaller = isCaller;
3376
3392
  this.answered = answered;
3377
3393
  this.answeredBySystem = answeredBySystem;
@@ -3390,6 +3406,8 @@ class CallSession {
3390
3406
  this.recording = recording || false;
3391
3407
  this.recordingPaused = recordingPaused || false;
3392
3408
  this.videoRemotelyDowngraded = videoRemotelyDowngraded;
3409
+ this.sipSession = sipSession;
3410
+ this.answerTime = answerTime || this.answerTime;
3393
3411
 
3394
3412
  // Useful to compare instead of instanceof with minified code
3395
3413
  this.type = 'CallSession';
@@ -3420,7 +3438,7 @@ class CallSession {
3420
3438
  }
3421
3439
 
3422
3440
  answer() {
3423
- this.answered = true;
3441
+ this.answerTime = new Date();
3424
3442
  }
3425
3443
 
3426
3444
  systemAnswer() {
@@ -3576,6 +3594,15 @@ class CallSession {
3576
3594
  return newFrom(callSession, CallSession);
3577
3595
  }
3578
3596
 
3597
+ // Retro-compatibility: `answered` was a boolean before. We can reproduce the behaviour with a getter/setter
3598
+ set answered(value ) {
3599
+ this.answerTime = value ? this.answerTime || new Date() : null;
3600
+ }
3601
+
3602
+ get answered() {
3603
+ return !!this.answerTime;
3604
+ }
3605
+
3579
3606
  static parseCall(call ) {
3580
3607
  return new CallSession({
3581
3608
  callId: call.id,
@@ -6183,6 +6210,7 @@ const MAX_REGISTER_TRIES = 10;
6183
6210
 
6184
6211
 
6185
6212
 
6213
+
6186
6214
 
6187
6215
 
6188
6216
 
@@ -7799,6 +7827,13 @@ class WebRTCClient extends Emitter {
7799
7827
  }
7800
7828
 
7801
7829
  _createWebRTCConfiguration(configOverrides = {}) {
7830
+ let { host } = this.config;
7831
+ let port = this.config.port || 443;
7832
+
7833
+ if (this.config.websocketSip) {
7834
+ [host, port = 443] = this.config.websocketSip.split(':');
7835
+ }
7836
+
7802
7837
  const config = {
7803
7838
  authorizationUsername: this.config.authorizationUser,
7804
7839
  authorizationPassword: this.config.password,
@@ -7834,7 +7869,7 @@ class WebRTCClient extends Emitter {
7834
7869
  },
7835
7870
  transportOptions: {
7836
7871
  traceSip: configOverrides.traceSip || false,
7837
- wsServers: `wss://${this.config.host}:${this.config.port || 443}/api/asterisk/ws`,
7872
+ wsServers: `wss://${host}:${port}/api/asterisk/ws`,
7838
7873
  },
7839
7874
  sessionDescriptionHandlerFactoryOptions: {
7840
7875
  modifiers: [replaceLocalIpModifier],
@@ -8792,6 +8827,14 @@ var WebSocketClient$1 = /*#__PURE__*/Object.freeze({
8792
8827
  'default': WebSocketClient
8793
8828
  });
8794
8829
 
8830
+ /* */
8831
+ class SFUNotAvailableError extends Error {
8832
+ constructor(message = 'Sorry your user is not configured to support video conference') {
8833
+ super(message);
8834
+ this.name = 'SFUNotAvailableError';
8835
+ }
8836
+ }
8837
+
8795
8838
  var COUNTRIES = {
8796
8839
  BELGIUM: 'BE',
8797
8840
  CANADA: 'CA',
@@ -9189,6 +9232,7 @@ const ON_CAMERA_DISABLED = 'onCameraDisabled';
9189
9232
  const ON_CAMERA_RESUMED = 'onCameraResumed';
9190
9233
  const ON_CALL_CANCELED = 'onCallCanceled';
9191
9234
  const ON_CALL_FAILED = 'onCallFailed';
9235
+ const ON_CALL_REJECTED = 'onCallRejected';
9192
9236
  const ON_CALL_ENDED = 'onCallEnded';
9193
9237
  const ON_CALL_ENDING = 'onCallEnding';
9194
9238
  const ON_MESSAGE = 'onMessage';
@@ -9233,6 +9277,7 @@ const events = [
9233
9277
  ON_CAMERA_DISABLED,
9234
9278
  ON_CALL_FAILED,
9235
9279
  ON_CALL_ENDED,
9280
+ ON_CALL_REJECTED,
9236
9281
  ON_MESSAGE,
9237
9282
  ON_REINVITE,
9238
9283
  ON_TRACK,
@@ -9589,6 +9634,7 @@ class WebRTCPhone extends Emitter {
9589
9634
 
9590
9635
  // Should be called before `_onCallTerminated` or the callCount will not decrement...
9591
9636
  const callSession = this._createCallSession(sipSession);
9637
+ callSession.endTime = new Date();
9592
9638
  const wasCurrentSession = this._onCallTerminated(sipSession);
9593
9639
 
9594
9640
  return this.eventEmitter.emit(ON_CALL_ENDED, callSession, wasCurrentSession);
@@ -9784,6 +9830,8 @@ class WebRTCPhone extends Emitter {
9784
9830
  this.removeIncomingSessions(sipSessionId);
9785
9831
  }
9786
9832
 
9833
+ callSession.answerTime = new Date();
9834
+ this._updateCallSession(callSession);
9787
9835
  this.eventEmitter.emit(ON_CALL_ACCEPTED, callSession, cameraEnabled);
9788
9836
 
9789
9837
  return callSession;
@@ -9999,6 +10047,8 @@ class WebRTCPhone extends Emitter {
9999
10047
  }
10000
10048
 
10001
10049
  this.shouldSendReinvite = false;
10050
+ callSession.answerTime = new Date();
10051
+ this._updateCallSession(callSession);
10002
10052
  this.acceptedSessions[callSession.getId()] = true;
10003
10053
 
10004
10054
  this.eventEmitter.emit(ON_CALL_ANSWERED, callSession);
@@ -10098,7 +10148,7 @@ class WebRTCPhone extends Emitter {
10098
10148
  // Hold current session if different from the current one (we don't want 2 sessions active at the same time).
10099
10149
  if (this.currentSipSession && this.currentSipSession.id !== sipSession.id) {
10100
10150
  logger$7.info('WebRTC hold call after resume', { id: this.currentSipSession.id });
10101
- this.holdSipSession(this.currentSipSession, callSession);
10151
+ this.holdSipSession(this.currentSipSession, this.currentCallSession);
10102
10152
  }
10103
10153
 
10104
10154
  const promise = this.unholdSipSession(sipSession, callSession, withEvent, isConference);
@@ -10308,6 +10358,8 @@ class WebRTCPhone extends Emitter {
10308
10358
  return Promise.resolve(null);
10309
10359
  }
10310
10360
  const callSession = this._createOutgoingCallSession(sipSession, cameraEnabled || false);
10361
+ callSession.creationTime = new Date();
10362
+ this._updateCallSession(callSession);
10311
10363
 
10312
10364
  this.eventEmitter.emit(ON_PLAY_PROGRESS_SOUND, this.audioOutputDeviceId, this.audioOutputVolume);
10313
10365
 
@@ -10586,6 +10638,9 @@ class WebRTCPhone extends Emitter {
10586
10638
  callSession);
10587
10639
  }
10588
10640
 
10641
+ callSession.creationTime = new Date();
10642
+ this._updateCallSession(callSession);
10643
+
10589
10644
  this.eventEmitter.emit(ON_CALL_INCOMING, callSession, wantsToDoVideo);
10590
10645
  });
10591
10646
 
@@ -10625,6 +10680,15 @@ class WebRTCPhone extends Emitter {
10625
10680
  this.eventEmitter.emit(ON_CALL_ERROR, e);
10626
10681
  });
10627
10682
 
10683
+ this.client.on(this.client.REJECTED, session => {
10684
+ logger$7.info('WebRTC call rejected', session.id);
10685
+ const callSession = this._createCallSession(session);
10686
+ callSession.endTime = new Date();
10687
+ this._updateCallSession(callSession);
10688
+
10689
+ this.eventEmitter.emit(ON_CALL_REJECTED, callSession);
10690
+ });
10691
+
10628
10692
  this.client.on(this.client.UNREGISTERED, () => {
10629
10693
  logger$7.info('WebRTC unregistered');
10630
10694
  this.eventEmitter.emit(ON_UNREGISTERED);
@@ -10837,6 +10901,7 @@ class WebRTCPhone extends Emitter {
10837
10901
  const number = identity ? identity.uri._normal.user : null;
10838
10902
  const { state } = sipSession || {};
10839
10903
  const sessionId = this.getSipSessionId(sipSession);
10904
+ fromSession = fromSession || this.callSessions[sessionId];
10840
10905
 
10841
10906
  const callSession = new CallSession({
10842
10907
  callId: fromSession && fromSession.callId,
@@ -10844,6 +10909,9 @@ class WebRTCPhone extends Emitter {
10844
10909
  sipStatus: state,
10845
10910
  displayName: identity ? identity.displayName || number : number,
10846
10911
  startTime: fromSession ? fromSession.startTime : new Date(),
10912
+ creationTime: fromSession ? fromSession.creationTime : null,
10913
+ answerTime: fromSession ? fromSession.answerTime : null,
10914
+ endTime: fromSession ? fromSession.endTime : null,
10847
10915
  answered: state === sessionState.SessionState.Established,
10848
10916
  paused: this.client.isCallHeld(sipSession),
10849
10917
  isCaller: 'incoming' in extra ? !extra.incoming : false,
@@ -10854,6 +10922,7 @@ class WebRTCPhone extends Emitter {
10854
10922
  videoMuted: fromSession ? fromSession.isVideoMuted() : false,
10855
10923
  recording: fromSession ? fromSession.isRecording() : false,
10856
10924
  recordingPaused: false, // @TODO
10925
+ sipSession,
10857
10926
  ...extra,
10858
10927
  });
10859
10928
 
@@ -10882,6 +10951,7 @@ var PHONE_EVENTS = /*#__PURE__*/Object.freeze({
10882
10951
  ON_CAMERA_RESUMED: ON_CAMERA_RESUMED,
10883
10952
  ON_CALL_CANCELED: ON_CALL_CANCELED,
10884
10953
  ON_CALL_FAILED: ON_CALL_FAILED,
10954
+ ON_CALL_REJECTED: ON_CALL_REJECTED,
10885
10955
  ON_CALL_ENDED: ON_CALL_ENDED,
10886
10956
  ON_CALL_ENDING: ON_CALL_ENDING,
10887
10957
  ON_MESSAGE: ON_MESSAGE,
@@ -12330,7 +12400,7 @@ class Phone extends Emitter {
12330
12400
 
12331
12401
  checkSfu() {
12332
12402
  if (!this.hasSfu()) {
12333
- throw new Error('Sorry your user is not configured to support video conference');
12403
+ throw new SFUNotAvailableError();
12334
12404
  }
12335
12405
  }
12336
12406
 
@@ -13891,6 +13961,7 @@ const Wazo = {
13891
13961
  InvalidSubscription,
13892
13962
  InvalidAuthorization,
13893
13963
  CanceledCallError,
13964
+ SFUNotAvailableError,
13894
13965
  };
13895
13966
 
13896
13967
  if (window) {
@@ -13933,6 +14004,7 @@ var index = {
13933
14004
  WazoWebSocketClient: WebSocketClient,
13934
14005
  BadResponse,
13935
14006
  ServerError,
14007
+ SFUNotAvailableError,
13936
14008
  Call,
13937
14009
  CallSession,
13938
14010
  CTIPhone,