@wazo/sdk 0.37.25 → 0.37.29

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 (125) hide show
  1. package/README.md +96 -58
  2. package/dist/wazo-sdk.js +3 -3
  3. package/esm/__tests__/api-client.test.js +2 -2
  4. package/esm/__tests__/web-rtc-client.test.js +10 -5
  5. package/esm/api/agentd.js +1 -1
  6. package/esm/api/amid.js +1 -1
  7. package/esm/api/application.js +1 -1
  8. package/esm/api/auth.js +1 -1
  9. package/esm/api/call-logd.js +1 -1
  10. package/esm/api/calld.js +1 -1
  11. package/esm/api/chatd.js +1 -1
  12. package/esm/api/confd.js +1 -1
  13. package/esm/api/ctid-ng.js +1 -1
  14. package/esm/api/dird.js +2 -2
  15. package/esm/api/webhookd.js +1 -1
  16. package/esm/api-client.js +2 -2
  17. package/esm/checker/Checker.js +10 -5
  18. package/esm/checker/checks/aor.js +2 -2
  19. package/esm/checker/checks/api.js +2 -2
  20. package/esm/checker/checks/index.js +10 -5
  21. package/esm/checker/checks/wazo-websocket.js +1 -1
  22. package/esm/checker/checks/webrtc-transport.js +10 -5
  23. package/esm/checker/checks/webrtc.js +10 -5
  24. package/esm/domain/AdHocAPIConference.js +2 -2
  25. package/esm/domain/CallSession.js +29 -2
  26. package/esm/domain/Contact.js +1 -1
  27. package/esm/domain/Features.js +2 -2
  28. package/esm/domain/Phone/CTIPhone.js +31 -4
  29. package/esm/domain/Phone/WebRTCPhone.js +55 -6
  30. package/esm/domain/SFUNotAvailableError.js +9 -0
  31. package/esm/domain/__tests__/CallSession.test.js +46 -2
  32. package/esm/domain/__tests__/Contact.test.js +1 -1
  33. package/esm/domain/__tests__/IndirectTransfer.test.js +29 -2
  34. package/esm/domain/__tests__/Room.test.js +29 -2
  35. package/esm/index.js +75 -10
  36. package/esm/lib/WazoSessionDescriptionHandler.js +9 -4
  37. package/esm/service/CallApi.js +2 -2
  38. package/esm/service/IssueReporter.js +1 -1
  39. package/esm/service/__tests__/IssueReporter.test.js +1 -1
  40. package/esm/service/getApiClient.js +2 -2
  41. package/esm/simple/Auth.js +74 -10
  42. package/esm/simple/Configuration.js +74 -10
  43. package/esm/simple/Directory.js +2 -2
  44. package/esm/simple/Phone.js +74 -10
  45. package/esm/simple/Websocket.js +1 -1
  46. package/esm/simple/index.js +74 -10
  47. package/esm/simple/room/LocalParticipant.js +74 -10
  48. package/esm/simple/room/Participant.js +74 -10
  49. package/esm/simple/room/RemoteParticipant.js +74 -10
  50. package/esm/simple/room/Room.js +74 -10
  51. package/esm/simple/room/SipRoom.js +74 -10
  52. package/esm/simple/room/Stream.js +74 -10
  53. package/esm/simple/room/__tests__/RemoteParticipant.test.js +74 -10
  54. package/esm/simple/utils.js +74 -10
  55. package/esm/utils/__tests__/api-requester.test.js +1 -1
  56. package/esm/utils/api-requester.js +1 -1
  57. package/esm/web-rtc-client.js +10 -5
  58. package/esm/websocket-client.js +1 -1
  59. package/lib/__tests__/api-client.test.js +2 -2
  60. package/lib/__tests__/web-rtc-client.test.js +10 -5
  61. package/lib/api/agentd.js +1 -1
  62. package/lib/api/amid.js +1 -1
  63. package/lib/api/application.js +1 -1
  64. package/lib/api/auth.js +1 -1
  65. package/lib/api/call-logd.js +1 -1
  66. package/lib/api/calld.js +1 -1
  67. package/lib/api/chatd.js +1 -1
  68. package/lib/api/confd.js +1 -1
  69. package/lib/api/ctid-ng.js +1 -1
  70. package/lib/api/dird.js +2 -2
  71. package/lib/api/webhookd.js +1 -1
  72. package/lib/api-client.js +2 -2
  73. package/lib/checker/Checker.js +10 -5
  74. package/lib/checker/checks/aor.js +2 -2
  75. package/lib/checker/checks/api.js +2 -2
  76. package/lib/checker/checks/index.js +10 -5
  77. package/lib/checker/checks/wazo-websocket.js +1 -1
  78. package/lib/checker/checks/webrtc-transport.js +10 -5
  79. package/lib/checker/checks/webrtc.js +10 -5
  80. package/lib/domain/AdHocAPIConference.js +2 -2
  81. package/lib/domain/CallSession.js +29 -2
  82. package/lib/domain/Contact.js +1 -1
  83. package/lib/domain/Features.js +2 -2
  84. package/lib/domain/Phone/CTIPhone.js +31 -4
  85. package/lib/domain/Phone/WebRTCPhone.js +55 -5
  86. package/lib/domain/SFUNotAvailableError.js +11 -0
  87. package/lib/domain/__tests__/CallSession.test.js +46 -2
  88. package/lib/domain/__tests__/Contact.test.js +1 -1
  89. package/lib/domain/__tests__/IndirectTransfer.test.js +29 -2
  90. package/lib/domain/__tests__/Room.test.js +29 -2
  91. package/lib/index.js +75 -10
  92. package/lib/lib/WazoSessionDescriptionHandler.js +9 -4
  93. package/lib/service/CallApi.js +2 -2
  94. package/lib/service/IssueReporter.js +1 -1
  95. package/lib/service/__tests__/IssueReporter.test.js +1 -1
  96. package/lib/service/getApiClient.js +2 -2
  97. package/lib/simple/Auth.js +74 -10
  98. package/lib/simple/Configuration.js +74 -10
  99. package/lib/simple/Directory.js +2 -2
  100. package/lib/simple/Phone.js +74 -10
  101. package/lib/simple/Websocket.js +1 -1
  102. package/lib/simple/index.js +74 -10
  103. package/lib/simple/room/LocalParticipant.js +74 -10
  104. package/lib/simple/room/Participant.js +74 -10
  105. package/lib/simple/room/RemoteParticipant.js +74 -10
  106. package/lib/simple/room/Room.js +74 -10
  107. package/lib/simple/room/SipRoom.js +74 -10
  108. package/lib/simple/room/Stream.js +74 -10
  109. package/lib/simple/room/__tests__/RemoteParticipant.test.js +74 -10
  110. package/lib/simple/utils.js +74 -10
  111. package/lib/utils/__tests__/api-requester.test.js +1 -1
  112. package/lib/utils/api-requester.js +1 -1
  113. package/lib/web-rtc-client.js +10 -5
  114. package/lib/websocket-client.js +1 -1
  115. package/package.json +1 -1
  116. package/src/domain/CallSession.js +32 -4
  117. package/src/domain/Contact.js +1 -1
  118. package/src/domain/Phone/WebRTCPhone.js +24 -2
  119. package/src/domain/SFUNotAvailableError.js +7 -0
  120. package/src/domain/__tests__/CallSession.test.js +17 -0
  121. package/src/index.js +2 -0
  122. package/src/lib/WazoSessionDescriptionHandler.js +8 -3
  123. package/src/simple/Phone.js +2 -1
  124. package/src/simple/index.js +2 -0
  125. package/src/utils/api-requester.js +1 -1
@@ -17,7 +17,7 @@ IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
17
17
 
18
18
  // Use a function here to be able to mock it in tests
19
19
  const realFetch = () => {
20
- if (typeof document !== 'undefined') {
20
+ if (typeof document !== 'undefined' && window.fetch) {
21
21
  // Browser
22
22
  return window.fetch;
23
23
  }
@@ -17,7 +17,7 @@ IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
17
17
 
18
18
  // Use a function here to be able to mock it in tests
19
19
  const realFetch = () => {
20
- if (typeof document !== 'undefined') {
20
+ if (typeof document !== 'undefined' && window.fetch) {
21
21
  // Browser
22
22
  return window.fetch;
23
23
  }
@@ -452,7 +452,7 @@ const logger$1 = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
452
452
 
453
453
  // Use a function here to be able to mock it in tests
454
454
  const realFetch = () => {
455
- if (typeof document !== 'undefined') {
455
+ if (typeof document !== 'undefined' && window.fetch) {
456
456
  // Browser
457
457
  return window.fetch;
458
458
  }
@@ -1912,7 +1912,7 @@ class Contact {
1912
1912
  this[key] = old[key] || this[key];
1913
1913
  });
1914
1914
 
1915
- if (old.lineState && !this.lineState) {
1915
+ if (old.lineState) {
1916
1916
  this.lineState = old.lineState;
1917
1917
  }
1918
1918
 
@@ -1248,7 +1248,7 @@ class Contact {
1248
1248
  this[key] = old[key] || this[key];
1249
1249
  });
1250
1250
 
1251
- if (old.lineState && !this.lineState) {
1251
+ if (old.lineState) {
1252
1252
  this.lineState = old.lineState;
1253
1253
  }
1254
1254
 
@@ -1963,7 +1963,7 @@ const logger$c = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
1963
1963
 
1964
1964
  // Use a function here to be able to mock it in tests
1965
1965
  const realFetch = () => {
1966
- if (typeof document !== 'undefined') {
1966
+ if (typeof document !== 'undefined' && window.fetch) {
1967
1967
  // Browser
1968
1968
  return window.fetch;
1969
1969
  }
@@ -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 ? 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,
@@ -5810,11 +5837,16 @@ class WazoSessionDescriptionHandler extends sessionDescriptionHandler.SessionDes
5810
5837
 
5811
5838
  // $FlowFixMe
5812
5839
  setRemoteSessionDescription(sessionDescription ) {
5813
- const result = super.setRemoteSessionDescription(sessionDescription);
5840
+ try {
5841
+ const result = super.setRemoteSessionDescription(sessionDescription);
5814
5842
 
5815
- this.eventEmitter.emit('setDescription', sessionDescription);
5843
+ this.eventEmitter.emit('setDescription', sessionDescription);
5816
5844
 
5817
- return result;
5845
+ return result;
5846
+ } catch (error) {
5847
+ this.logger.error('SessionDescriptionHandler.setRemoteSessionDescription error', error);
5848
+ throw error;
5849
+ }
5818
5850
  }
5819
5851
 
5820
5852
  // Overridden to avoid to fix ice-candidates missing in the SDP in react-native and chrome canary.
@@ -8466,6 +8498,7 @@ const ON_CAMERA_DISABLED = 'onCameraDisabled';
8466
8498
  const ON_CAMERA_RESUMED = 'onCameraResumed';
8467
8499
  const ON_CALL_CANCELED = 'onCallCanceled';
8468
8500
  const ON_CALL_FAILED = 'onCallFailed';
8501
+ const ON_CALL_REJECTED = 'onCallRejected';
8469
8502
  const ON_CALL_ENDED = 'onCallEnded';
8470
8503
  const ON_CALL_ENDING = 'onCallEnding';
8471
8504
  const ON_MESSAGE = 'onMessage';
@@ -8510,6 +8543,7 @@ const events = [
8510
8543
  ON_CAMERA_DISABLED,
8511
8544
  ON_CALL_FAILED,
8512
8545
  ON_CALL_ENDED,
8546
+ ON_CALL_REJECTED,
8513
8547
  ON_MESSAGE,
8514
8548
  ON_REINVITE,
8515
8549
  ON_TRACK,
@@ -8866,6 +8900,7 @@ class WebRTCPhone extends Emitter {
8866
8900
 
8867
8901
  // Should be called before `_onCallTerminated` or the callCount will not decrement...
8868
8902
  const callSession = this._createCallSession(sipSession);
8903
+ callSession.endTime = new Date();
8869
8904
  const wasCurrentSession = this._onCallTerminated(sipSession);
8870
8905
 
8871
8906
  return this.eventEmitter.emit(ON_CALL_ENDED, callSession, wasCurrentSession);
@@ -9061,6 +9096,7 @@ class WebRTCPhone extends Emitter {
9061
9096
  this.removeIncomingSessions(sipSessionId);
9062
9097
  }
9063
9098
 
9099
+ callSession.answerTime = new Date();
9064
9100
  this.eventEmitter.emit(ON_CALL_ACCEPTED, callSession, cameraEnabled);
9065
9101
 
9066
9102
  return callSession;
@@ -9118,6 +9154,7 @@ class WebRTCPhone extends Emitter {
9118
9154
  _onCallTerminated(sipSession ) {
9119
9155
  logger$8.info('WebRTC phone - on call terminated', { sipId: sipSession.id });
9120
9156
 
9157
+ const sipSessionId = this.getSipSessionId(sipSession);
9121
9158
  const callSession = this._createCallSession(sipSession);
9122
9159
  const isCurrentSession = this.isCurrentCallSipSession(callSession);
9123
9160
  const isCurrentIncomingCall = callSession.is(this.getIncomingCallSession());
@@ -9135,7 +9172,6 @@ class WebRTCPhone extends Emitter {
9135
9172
  }, 5);
9136
9173
  }
9137
9174
 
9138
- const sipSessionId = this.getSipSessionId(sipSession);
9139
9175
  if (sipSessionId) {
9140
9176
  this.removeIncomingSessions(sipSessionId);
9141
9177
  }
@@ -9276,6 +9312,7 @@ class WebRTCPhone extends Emitter {
9276
9312
  }
9277
9313
 
9278
9314
  this.shouldSendReinvite = false;
9315
+ callSession.answerTime = new Date();
9279
9316
  this.acceptedSessions[callSession.getId()] = true;
9280
9317
 
9281
9318
  this.eventEmitter.emit(ON_CALL_ANSWERED, callSession);
@@ -9585,6 +9622,7 @@ class WebRTCPhone extends Emitter {
9585
9622
  return Promise.resolve(null);
9586
9623
  }
9587
9624
  const callSession = this._createOutgoingCallSession(sipSession, cameraEnabled || false);
9625
+ callSession.creationTime = new Date();
9588
9626
 
9589
9627
  this.eventEmitter.emit(ON_PLAY_PROGRESS_SOUND, this.audioOutputDeviceId, this.audioOutputVolume);
9590
9628
 
@@ -9780,8 +9818,12 @@ class WebRTCPhone extends Emitter {
9780
9818
  }
9781
9819
 
9782
9820
  const sessionId = this.incomingSessions[0];
9821
+ const sipSession = this.client.getSipSession(sessionId);
9822
+ if (!sipSession) {
9823
+ return null;
9824
+ }
9783
9825
 
9784
- return this._createCallSession(this.client.getSipSession(sessionId));
9826
+ return this._createCallSession(sipSession);
9785
9827
  }
9786
9828
 
9787
9829
  sendMessage(sipSession = null, body , contentType = 'text/plain') {
@@ -9859,6 +9901,7 @@ class WebRTCPhone extends Emitter {
9859
9901
  callSession);
9860
9902
  }
9861
9903
 
9904
+ callSession.creationTime = new Date();
9862
9905
  this.eventEmitter.emit(ON_CALL_INCOMING, callSession, wantsToDoVideo);
9863
9906
  });
9864
9907
 
@@ -9898,6 +9941,13 @@ class WebRTCPhone extends Emitter {
9898
9941
  this.eventEmitter.emit(ON_CALL_ERROR, e);
9899
9942
  });
9900
9943
 
9944
+ this.client.on(this.client.REJECTED, session => {
9945
+ logger$8.info('WebRTC call rejected', session.id);
9946
+ const callSession = this._createCallSession(session);
9947
+ callSession.endTime = new Date();
9948
+ this.eventEmitter.emit(ON_CALL_REJECTED, callSession);
9949
+ });
9950
+
9901
9951
  this.client.on(this.client.UNREGISTERED, () => {
9902
9952
  logger$8.info('WebRTC unregistered');
9903
9953
  this.eventEmitter.emit(ON_UNREGISTERED);
@@ -10110,6 +10160,7 @@ class WebRTCPhone extends Emitter {
10110
10160
  const number = identity ? identity.uri._normal.user : null;
10111
10161
  const { state } = sipSession || {};
10112
10162
  const sessionId = this.getSipSessionId(sipSession);
10163
+ fromSession = fromSession || this.callSessions[sessionId];
10113
10164
 
10114
10165
  const callSession = new CallSession({
10115
10166
  callId: fromSession && fromSession.callId,
@@ -10117,6 +10168,8 @@ class WebRTCPhone extends Emitter {
10117
10168
  sipStatus: state,
10118
10169
  displayName: identity ? identity.displayName || number : number,
10119
10170
  startTime: fromSession ? fromSession.startTime : new Date(),
10171
+ creationTime: fromSession ? fromSession.creationTime : null,
10172
+ endTime: fromSession ? fromSession.endTime : null,
10120
10173
  answered: state === sessionState.SessionState.Established,
10121
10174
  paused: this.client.isCallHeld(sipSession),
10122
10175
  isCaller: 'incoming' in extra ? !extra.incoming : false,
@@ -10127,6 +10180,7 @@ class WebRTCPhone extends Emitter {
10127
10180
  videoMuted: fromSession ? fromSession.isVideoMuted() : false,
10128
10181
  recording: fromSession ? fromSession.isRecording() : false,
10129
10182
  recordingPaused: false, // @TODO
10183
+ sipSession,
10130
10184
  ...extra,
10131
10185
  });
10132
10186
 
@@ -10155,6 +10209,7 @@ var PHONE_EVENTS = /*#__PURE__*/Object.freeze({
10155
10209
  ON_CAMERA_RESUMED: ON_CAMERA_RESUMED,
10156
10210
  ON_CALL_CANCELED: ON_CALL_CANCELED,
10157
10211
  ON_CALL_FAILED: ON_CALL_FAILED,
10212
+ ON_CALL_REJECTED: ON_CALL_REJECTED,
10158
10213
  ON_CALL_ENDED: ON_CALL_ENDED,
10159
10214
  ON_CALL_ENDING: ON_CALL_ENDING,
10160
10215
  ON_MESSAGE: ON_MESSAGE,
@@ -10184,6 +10239,14 @@ var PHONE_EVENTS = /*#__PURE__*/Object.freeze({
10184
10239
  'default': WebRTCPhone
10185
10240
  });
10186
10241
 
10242
+ /* */
10243
+ class SFUNotAvailableError extends Error {
10244
+ constructor(message = 'Sorry your user is not configured to support video conference') {
10245
+ super(message);
10246
+ this.name = 'SFUNotAvailableError';
10247
+ }
10248
+ }
10249
+
10187
10250
  //
10188
10251
 
10189
10252
  const logger$7 = IssueReporter$1.loggerFor('simple-phone');
@@ -10568,7 +10631,7 @@ class Phone extends Emitter {
10568
10631
 
10569
10632
  checkSfu() {
10570
10633
  if (!this.hasSfu()) {
10571
- throw new Error('Sorry your user is not configured to support video conference');
10634
+ throw new SFUNotAvailableError();
10572
10635
  }
10573
10636
  }
10574
10637
 
@@ -13481,6 +13544,7 @@ const Wazo = {
13481
13544
  InvalidSubscription,
13482
13545
  InvalidAuthorization,
13483
13546
  CanceledCallError,
13547
+ SFUNotAvailableError,
13484
13548
  };
13485
13549
 
13486
13550
  if (window) {
@@ -1246,7 +1246,7 @@ class Contact {
1246
1246
  this[key] = old[key] || this[key];
1247
1247
  });
1248
1248
 
1249
- if (old.lineState && !this.lineState) {
1249
+ if (old.lineState) {
1250
1250
  this.lineState = old.lineState;
1251
1251
  }
1252
1252
 
@@ -1961,7 +1961,7 @@ const logger$c = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
1961
1961
 
1962
1962
  // Use a function here to be able to mock it in tests
1963
1963
  const realFetch = () => {
1964
- if (typeof document !== 'undefined') {
1964
+ if (typeof document !== 'undefined' && window.fetch) {
1965
1965
  // Browser
1966
1966
  return window.fetch;
1967
1967
  }
@@ -3258,13 +3258,16 @@ var updateFrom = (instance , from ) => {
3258
3258
 
3259
3259
 
3260
3260
 
3261
+
3261
3262
 
3262
3263
 
3263
3264
 
3264
3265
 
3265
3266
 
3267
+
3266
3268
 
3267
3269
 
3270
+
3268
3271
 
3269
3272
 
3270
3273
 
@@ -3281,6 +3284,7 @@ var updateFrom = (instance , from ) => {
3281
3284
 
3282
3285
 
3283
3286
 
3287
+
3284
3288
 
3285
3289
 
3286
3290
  class CallSession {
@@ -3300,10 +3304,14 @@ class CallSession {
3300
3304
 
3301
3305
 
3302
3306
 
3303
-
3307
+
3308
+
3309
+ // = creationTime
3304
3310
 
3305
3311
 
3306
3312
 
3313
+
3314
+
3307
3315
 
3308
3316
 
3309
3317
 
@@ -3339,6 +3347,8 @@ class CallSession {
3339
3347
 
3340
3348
 
3341
3349
 
3350
+
3351
+
3342
3352
 
3343
3353
  constructor({
3344
3354
  answered,
@@ -3352,6 +3362,8 @@ class CallSession {
3352
3362
  paused,
3353
3363
  ringing,
3354
3364
  startTime,
3365
+ creationTime,
3366
+ endTime,
3355
3367
  cameraEnabled,
3356
3368
  dialedExtension,
3357
3369
  sipCallId,
@@ -3364,12 +3376,16 @@ class CallSession {
3364
3376
  recording,
3365
3377
  recordingPaused,
3366
3378
  videoRemotelyDowngraded,
3379
+ sipSession,
3380
+ answerTime,
3367
3381
  } ) {
3368
3382
  this.callId = callId;
3369
3383
  this.sipCallId = sipCallId;
3370
3384
  this.displayName = displayName;
3371
3385
  this.number = number;
3386
+ this.creationTime = creationTime;
3372
3387
  this.startTime = startTime;
3388
+ this.endTime = endTime;
3373
3389
  this.isCaller = isCaller;
3374
3390
  this.answered = answered;
3375
3391
  this.answeredBySystem = answeredBySystem;
@@ -3388,6 +3404,8 @@ class CallSession {
3388
3404
  this.recording = recording || false;
3389
3405
  this.recordingPaused = recordingPaused || false;
3390
3406
  this.videoRemotelyDowngraded = videoRemotelyDowngraded;
3407
+ this.sipSession = sipSession;
3408
+ this.answerTime = answerTime || this.answerTime;
3391
3409
 
3392
3410
  // Useful to compare instead of instanceof with minified code
3393
3411
  this.type = 'CallSession';
@@ -3418,7 +3436,7 @@ class CallSession {
3418
3436
  }
3419
3437
 
3420
3438
  answer() {
3421
- this.answered = true;
3439
+ this.answerTime = new Date();
3422
3440
  }
3423
3441
 
3424
3442
  systemAnswer() {
@@ -3574,6 +3592,15 @@ class CallSession {
3574
3592
  return newFrom(callSession, CallSession);
3575
3593
  }
3576
3594
 
3595
+ // Retro-compatibility: `answered` was a boolean before. We can reproduce the behaviour with a getter/setter
3596
+ set answered(value ) {
3597
+ this.answerTime = value ? new Date() : null;
3598
+ }
3599
+
3600
+ get answered() {
3601
+ return !!this.answerTime;
3602
+ }
3603
+
3577
3604
  static parseCall(call ) {
3578
3605
  return new CallSession({
3579
3606
  callId: call.id,
@@ -5808,11 +5835,16 @@ class WazoSessionDescriptionHandler extends sessionDescriptionHandler.SessionDes
5808
5835
 
5809
5836
  // $FlowFixMe
5810
5837
  setRemoteSessionDescription(sessionDescription ) {
5811
- const result = super.setRemoteSessionDescription(sessionDescription);
5838
+ try {
5839
+ const result = super.setRemoteSessionDescription(sessionDescription);
5812
5840
 
5813
- this.eventEmitter.emit('setDescription', sessionDescription);
5841
+ this.eventEmitter.emit('setDescription', sessionDescription);
5814
5842
 
5815
- return result;
5843
+ return result;
5844
+ } catch (error) {
5845
+ this.logger.error('SessionDescriptionHandler.setRemoteSessionDescription error', error);
5846
+ throw error;
5847
+ }
5816
5848
  }
5817
5849
 
5818
5850
  // Overridden to avoid to fix ice-candidates missing in the SDP in react-native and chrome canary.
@@ -8464,6 +8496,7 @@ const ON_CAMERA_DISABLED = 'onCameraDisabled';
8464
8496
  const ON_CAMERA_RESUMED = 'onCameraResumed';
8465
8497
  const ON_CALL_CANCELED = 'onCallCanceled';
8466
8498
  const ON_CALL_FAILED = 'onCallFailed';
8499
+ const ON_CALL_REJECTED = 'onCallRejected';
8467
8500
  const ON_CALL_ENDED = 'onCallEnded';
8468
8501
  const ON_CALL_ENDING = 'onCallEnding';
8469
8502
  const ON_MESSAGE = 'onMessage';
@@ -8508,6 +8541,7 @@ const events = [
8508
8541
  ON_CAMERA_DISABLED,
8509
8542
  ON_CALL_FAILED,
8510
8543
  ON_CALL_ENDED,
8544
+ ON_CALL_REJECTED,
8511
8545
  ON_MESSAGE,
8512
8546
  ON_REINVITE,
8513
8547
  ON_TRACK,
@@ -8864,6 +8898,7 @@ class WebRTCPhone extends Emitter {
8864
8898
 
8865
8899
  // Should be called before `_onCallTerminated` or the callCount will not decrement...
8866
8900
  const callSession = this._createCallSession(sipSession);
8901
+ callSession.endTime = new Date();
8867
8902
  const wasCurrentSession = this._onCallTerminated(sipSession);
8868
8903
 
8869
8904
  return this.eventEmitter.emit(ON_CALL_ENDED, callSession, wasCurrentSession);
@@ -9059,6 +9094,7 @@ class WebRTCPhone extends Emitter {
9059
9094
  this.removeIncomingSessions(sipSessionId);
9060
9095
  }
9061
9096
 
9097
+ callSession.answerTime = new Date();
9062
9098
  this.eventEmitter.emit(ON_CALL_ACCEPTED, callSession, cameraEnabled);
9063
9099
 
9064
9100
  return callSession;
@@ -9116,6 +9152,7 @@ class WebRTCPhone extends Emitter {
9116
9152
  _onCallTerminated(sipSession ) {
9117
9153
  logger$8.info('WebRTC phone - on call terminated', { sipId: sipSession.id });
9118
9154
 
9155
+ const sipSessionId = this.getSipSessionId(sipSession);
9119
9156
  const callSession = this._createCallSession(sipSession);
9120
9157
  const isCurrentSession = this.isCurrentCallSipSession(callSession);
9121
9158
  const isCurrentIncomingCall = callSession.is(this.getIncomingCallSession());
@@ -9133,7 +9170,6 @@ class WebRTCPhone extends Emitter {
9133
9170
  }, 5);
9134
9171
  }
9135
9172
 
9136
- const sipSessionId = this.getSipSessionId(sipSession);
9137
9173
  if (sipSessionId) {
9138
9174
  this.removeIncomingSessions(sipSessionId);
9139
9175
  }
@@ -9274,6 +9310,7 @@ class WebRTCPhone extends Emitter {
9274
9310
  }
9275
9311
 
9276
9312
  this.shouldSendReinvite = false;
9313
+ callSession.answerTime = new Date();
9277
9314
  this.acceptedSessions[callSession.getId()] = true;
9278
9315
 
9279
9316
  this.eventEmitter.emit(ON_CALL_ANSWERED, callSession);
@@ -9583,6 +9620,7 @@ class WebRTCPhone extends Emitter {
9583
9620
  return Promise.resolve(null);
9584
9621
  }
9585
9622
  const callSession = this._createOutgoingCallSession(sipSession, cameraEnabled || false);
9623
+ callSession.creationTime = new Date();
9586
9624
 
9587
9625
  this.eventEmitter.emit(ON_PLAY_PROGRESS_SOUND, this.audioOutputDeviceId, this.audioOutputVolume);
9588
9626
 
@@ -9778,8 +9816,12 @@ class WebRTCPhone extends Emitter {
9778
9816
  }
9779
9817
 
9780
9818
  const sessionId = this.incomingSessions[0];
9819
+ const sipSession = this.client.getSipSession(sessionId);
9820
+ if (!sipSession) {
9821
+ return null;
9822
+ }
9781
9823
 
9782
- return this._createCallSession(this.client.getSipSession(sessionId));
9824
+ return this._createCallSession(sipSession);
9783
9825
  }
9784
9826
 
9785
9827
  sendMessage(sipSession = null, body , contentType = 'text/plain') {
@@ -9857,6 +9899,7 @@ class WebRTCPhone extends Emitter {
9857
9899
  callSession);
9858
9900
  }
9859
9901
 
9902
+ callSession.creationTime = new Date();
9860
9903
  this.eventEmitter.emit(ON_CALL_INCOMING, callSession, wantsToDoVideo);
9861
9904
  });
9862
9905
 
@@ -9896,6 +9939,13 @@ class WebRTCPhone extends Emitter {
9896
9939
  this.eventEmitter.emit(ON_CALL_ERROR, e);
9897
9940
  });
9898
9941
 
9942
+ this.client.on(this.client.REJECTED, session => {
9943
+ logger$8.info('WebRTC call rejected', session.id);
9944
+ const callSession = this._createCallSession(session);
9945
+ callSession.endTime = new Date();
9946
+ this.eventEmitter.emit(ON_CALL_REJECTED, callSession);
9947
+ });
9948
+
9899
9949
  this.client.on(this.client.UNREGISTERED, () => {
9900
9950
  logger$8.info('WebRTC unregistered');
9901
9951
  this.eventEmitter.emit(ON_UNREGISTERED);
@@ -10108,6 +10158,7 @@ class WebRTCPhone extends Emitter {
10108
10158
  const number = identity ? identity.uri._normal.user : null;
10109
10159
  const { state } = sipSession || {};
10110
10160
  const sessionId = this.getSipSessionId(sipSession);
10161
+ fromSession = fromSession || this.callSessions[sessionId];
10111
10162
 
10112
10163
  const callSession = new CallSession({
10113
10164
  callId: fromSession && fromSession.callId,
@@ -10115,6 +10166,8 @@ class WebRTCPhone extends Emitter {
10115
10166
  sipStatus: state,
10116
10167
  displayName: identity ? identity.displayName || number : number,
10117
10168
  startTime: fromSession ? fromSession.startTime : new Date(),
10169
+ creationTime: fromSession ? fromSession.creationTime : null,
10170
+ endTime: fromSession ? fromSession.endTime : null,
10118
10171
  answered: state === sessionState.SessionState.Established,
10119
10172
  paused: this.client.isCallHeld(sipSession),
10120
10173
  isCaller: 'incoming' in extra ? !extra.incoming : false,
@@ -10125,6 +10178,7 @@ class WebRTCPhone extends Emitter {
10125
10178
  videoMuted: fromSession ? fromSession.isVideoMuted() : false,
10126
10179
  recording: fromSession ? fromSession.isRecording() : false,
10127
10180
  recordingPaused: false, // @TODO
10181
+ sipSession,
10128
10182
  ...extra,
10129
10183
  });
10130
10184
 
@@ -10153,6 +10207,7 @@ var PHONE_EVENTS = /*#__PURE__*/Object.freeze({
10153
10207
  ON_CAMERA_RESUMED: ON_CAMERA_RESUMED,
10154
10208
  ON_CALL_CANCELED: ON_CALL_CANCELED,
10155
10209
  ON_CALL_FAILED: ON_CALL_FAILED,
10210
+ ON_CALL_REJECTED: ON_CALL_REJECTED,
10156
10211
  ON_CALL_ENDED: ON_CALL_ENDED,
10157
10212
  ON_CALL_ENDING: ON_CALL_ENDING,
10158
10213
  ON_MESSAGE: ON_MESSAGE,
@@ -10182,6 +10237,14 @@ var PHONE_EVENTS = /*#__PURE__*/Object.freeze({
10182
10237
  'default': WebRTCPhone
10183
10238
  });
10184
10239
 
10240
+ /* */
10241
+ class SFUNotAvailableError extends Error {
10242
+ constructor(message = 'Sorry your user is not configured to support video conference') {
10243
+ super(message);
10244
+ this.name = 'SFUNotAvailableError';
10245
+ }
10246
+ }
10247
+
10185
10248
  //
10186
10249
 
10187
10250
  const logger$7 = IssueReporter$1.loggerFor('simple-phone');
@@ -10566,7 +10629,7 @@ class Phone extends Emitter {
10566
10629
 
10567
10630
  checkSfu() {
10568
10631
  if (!this.hasSfu()) {
10569
- throw new Error('Sorry your user is not configured to support video conference');
10632
+ throw new SFUNotAvailableError();
10570
10633
  }
10571
10634
  }
10572
10635
 
@@ -13462,6 +13525,7 @@ const Wazo = {
13462
13525
  InvalidSubscription,
13463
13526
  InvalidAuthorization,
13464
13527
  CanceledCallError,
13528
+ SFUNotAvailableError,
13465
13529
  };
13466
13530
 
13467
13531
  if (window) {
@@ -450,7 +450,7 @@ const logger$1 = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
450
450
 
451
451
  // Use a function here to be able to mock it in tests
452
452
  const realFetch = () => {
453
- if (typeof document !== 'undefined') {
453
+ if (typeof document !== 'undefined' && window.fetch) {
454
454
  // Browser
455
455
  return window.fetch;
456
456
  }
@@ -1910,7 +1910,7 @@ class Contact {
1910
1910
  this[key] = old[key] || this[key];
1911
1911
  });
1912
1912
 
1913
- if (old.lineState && !this.lineState) {
1913
+ if (old.lineState) {
1914
1914
  this.lineState = old.lineState;
1915
1915
  }
1916
1916