@wazo/sdk 0.37.29 → 0.37.33

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 (81) hide show
  1. package/README.md +2 -1
  2. package/dist/wazo-sdk.js +4 -4
  3. package/esm/__tests__/api-client.test.js +30 -0
  4. package/esm/__tests__/web-rtc-client.test.js +65 -6
  5. package/esm/api/calld.js +30 -0
  6. package/esm/api-client.js +30 -0
  7. package/esm/checker/Checker.js +65 -6
  8. package/esm/checker/checks/aor.js +30 -0
  9. package/esm/checker/checks/api.js +30 -0
  10. package/esm/checker/checks/index.js +65 -6
  11. package/esm/checker/checks/webrtc-transport.js +65 -6
  12. package/esm/checker/checks/webrtc.js +65 -6
  13. package/esm/domain/AdHocAPIConference.js +30 -0
  14. package/esm/domain/CallSession.js +9 -1
  15. package/esm/domain/Features.js +30 -0
  16. package/esm/domain/MeetingStatus.js +29 -0
  17. package/esm/domain/Phone/CTIPhone.js +39 -1
  18. package/esm/domain/Phone/WebRTCPhone.js +20 -4
  19. package/esm/domain/__tests__/CallSession.test.js +41 -5
  20. package/esm/domain/__tests__/IndirectTransfer.test.js +9 -1
  21. package/esm/domain/__tests__/Room.test.js +9 -1
  22. package/esm/index.js +85 -10
  23. package/esm/service/CallApi.js +30 -0
  24. package/esm/service/getApiClient.js +30 -0
  25. package/esm/simple/Auth.js +85 -10
  26. package/esm/simple/Configuration.js +85 -10
  27. package/esm/simple/Directory.js +30 -0
  28. package/esm/simple/Phone.js +85 -10
  29. package/esm/simple/index.js +85 -10
  30. package/esm/simple/room/LocalParticipant.js +85 -10
  31. package/esm/simple/room/Participant.js +85 -10
  32. package/esm/simple/room/RemoteParticipant.js +85 -10
  33. package/esm/simple/room/Room.js +85 -10
  34. package/esm/simple/room/SipRoom.js +85 -10
  35. package/esm/simple/room/Stream.js +85 -10
  36. package/esm/simple/room/__tests__/RemoteParticipant.test.js +85 -10
  37. package/esm/simple/utils.js +85 -10
  38. package/esm/web-rtc-client.js +65 -6
  39. package/lib/__tests__/api-client.test.js +30 -0
  40. package/lib/__tests__/web-rtc-client.test.js +65 -6
  41. package/lib/api/calld.js +30 -0
  42. package/lib/api-client.js +30 -0
  43. package/lib/checker/Checker.js +65 -6
  44. package/lib/checker/checks/aor.js +30 -0
  45. package/lib/checker/checks/api.js +30 -0
  46. package/lib/checker/checks/index.js +65 -6
  47. package/lib/checker/checks/webrtc-transport.js +65 -6
  48. package/lib/checker/checks/webrtc.js +65 -6
  49. package/lib/domain/AdHocAPIConference.js +30 -0
  50. package/lib/domain/CallSession.js +9 -1
  51. package/lib/domain/Features.js +30 -0
  52. package/lib/domain/MeetingStatus.js +31 -0
  53. package/lib/domain/Phone/CTIPhone.js +39 -1
  54. package/lib/domain/Phone/WebRTCPhone.js +20 -4
  55. package/lib/domain/__tests__/CallSession.test.js +41 -5
  56. package/lib/domain/__tests__/IndirectTransfer.test.js +9 -1
  57. package/lib/domain/__tests__/Room.test.js +9 -1
  58. package/lib/index.js +85 -10
  59. package/lib/service/CallApi.js +30 -0
  60. package/lib/service/getApiClient.js +30 -0
  61. package/lib/simple/Auth.js +85 -10
  62. package/lib/simple/Configuration.js +85 -10
  63. package/lib/simple/Directory.js +30 -0
  64. package/lib/simple/Phone.js +85 -10
  65. package/lib/simple/index.js +85 -10
  66. package/lib/simple/room/LocalParticipant.js +85 -10
  67. package/lib/simple/room/Participant.js +85 -10
  68. package/lib/simple/room/RemoteParticipant.js +85 -10
  69. package/lib/simple/room/Room.js +85 -10
  70. package/lib/simple/room/SipRoom.js +85 -10
  71. package/lib/simple/room/Stream.js +85 -10
  72. package/lib/simple/room/__tests__/RemoteParticipant.test.js +85 -10
  73. package/lib/simple/utils.js +85 -10
  74. package/lib/web-rtc-client.js +65 -6
  75. package/package.json +1 -1
  76. package/src/api/calld.js +3 -0
  77. package/src/domain/CallSession.js +9 -1
  78. package/src/domain/MeetingStatus.js +27 -0
  79. package/src/domain/Phone/WebRTCPhone.js +11 -3
  80. package/src/domain/__tests__/CallSession.test.js +32 -4
  81. package/src/web-rtc-client.js +35 -6
@@ -368,13 +368,21 @@ class CallSession {
368
368
 
369
369
  // Retro-compatibility: `answered` was a boolean before. We can reproduce the behaviour with a getter/setter
370
370
  set answered(value ) {
371
- this.answerTime = value ? new Date() : null;
371
+ this.answerTime = value ? this.answerTime || new Date() : null;
372
372
  }
373
373
 
374
374
  get answered() {
375
375
  return !!this.answerTime;
376
376
  }
377
377
 
378
+ toJSON() {
379
+ const jsonObj = { ...this };
380
+ // $FlowFixMe
381
+ jsonObj.answered = this.answered;
382
+
383
+ return jsonObj;
384
+ }
385
+
378
386
  static parseCall(call ) {
379
387
  return new CallSession({
380
388
  callId: call.id,
@@ -368,13 +368,21 @@ class CallSession {
368
368
 
369
369
  // Retro-compatibility: `answered` was a boolean before. We can reproduce the behaviour with a getter/setter
370
370
  set answered(value ) {
371
- this.answerTime = value ? new Date() : null;
371
+ this.answerTime = value ? this.answerTime || new Date() : null;
372
372
  }
373
373
 
374
374
  get answered() {
375
375
  return !!this.answerTime;
376
376
  }
377
377
 
378
+ toJSON() {
379
+ const jsonObj = { ...this };
380
+ // $FlowFixMe
381
+ jsonObj.answered = this.answered;
382
+
383
+ return jsonObj;
384
+ }
385
+
378
386
  static parseCall(call ) {
379
387
  return new CallSession({
380
388
  callId: call.id,
package/esm/index.js CHANGED
@@ -3585,13 +3585,21 @@ class CallSession {
3585
3585
 
3586
3586
  // Retro-compatibility: `answered` was a boolean before. We can reproduce the behaviour with a getter/setter
3587
3587
  set answered(value ) {
3588
- this.answerTime = value ? new Date() : null;
3588
+ this.answerTime = value ? this.answerTime || new Date() : null;
3589
3589
  }
3590
3590
 
3591
3591
  get answered() {
3592
3592
  return !!this.answerTime;
3593
3593
  }
3594
3594
 
3595
+ toJSON() {
3596
+ const jsonObj = { ...this };
3597
+ // $FlowFixMe
3598
+ jsonObj.answered = this.answered;
3599
+
3600
+ return jsonObj;
3601
+ }
3602
+
3595
3603
  static parseCall(call ) {
3596
3604
  return new CallSession({
3597
3605
  callId: call.id,
@@ -4926,6 +4934,34 @@ var chatdMethods = (client , baseUrl ) => ({
4926
4934
  client.get(`${baseUrl}/users/me/rooms/messages`, options),
4927
4935
  });
4928
4936
 
4937
+ //
4938
+
4939
+
4940
+
4941
+
4942
+
4943
+ class MeetingStatus {
4944
+
4945
+
4946
+
4947
+
4948
+ constructor({
4949
+ full,
4950
+ } = {}) {
4951
+ this.full = full;
4952
+
4953
+ // Useful to compare instead of instanceof with minified code
4954
+ this.type = 'MeetingStatus';
4955
+ }
4956
+
4957
+ static parse(plain ) {
4958
+ return new MeetingStatus({
4959
+ full: plain.full,
4960
+ });
4961
+ }
4962
+
4963
+ }
4964
+
4929
4965
  /* */
4930
4966
 
4931
4967
 
@@ -5120,6 +5156,8 @@ var calldMethods = (client , baseUrl ) => ({
5120
5156
  client.put(`${baseUrl}/users/me/calls/${callId}/record/resume`, null, null,
5121
5157
  ApiRequester.successResponseParser),
5122
5158
 
5159
+ guestGetMeetingStatus: (meetingUuid ) =>
5160
+ client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}/status`).then(MeetingStatus.parse),
5123
5161
  });
5124
5162
 
5125
5163
  //
@@ -6199,6 +6237,7 @@ const MAX_REGISTER_TRIES = 10;
6199
6237
 
6200
6238
 
6201
6239
 
6240
+
6202
6241
 
6203
6242
 
6204
6243
 
@@ -6240,6 +6279,7 @@ class WebRTCClient extends Emitter {
6240
6279
 
6241
6280
 
6242
6281
 
6282
+
6243
6283
 
6244
6284
  // sugar
6245
6285
 
@@ -6302,6 +6342,7 @@ class WebRTCClient extends Emitter {
6302
6342
  this.conferences = {};
6303
6343
  this.networkMonitoringInterval = {};
6304
6344
  this.sessionNetworkStats = {};
6345
+ this.forceClosed = false;
6305
6346
 
6306
6347
  this._boundOnHeartbeat = this._onHeartbeat.bind(this);
6307
6348
  this.heartbeat = new Heartbeat(config.heartbeatDelay, config.heartbeatTimeout, config.maxHeartbeats);
@@ -6423,6 +6464,8 @@ class WebRTCClient extends Emitter {
6423
6464
  skipRegister: this.skipRegister,
6424
6465
  };
6425
6466
 
6467
+ this.forceClosed = false;
6468
+
6426
6469
  if (this.skipRegister) {
6427
6470
  logger$9.info('sdk webrtc skip register...', logInfo);
6428
6471
  return Promise.resolve();
@@ -6447,7 +6490,15 @@ class WebRTCClient extends Emitter {
6447
6490
  const registerOptions = this._isWeb() ? {} : { extraContactHeaderParams: ['mobility=mobile'] };
6448
6491
 
6449
6492
  const onRegisterFailed = () => {
6450
- logger$9.info('sdk webrtc registering failed', { tries, registerer: !!this.registerer });
6493
+ logger$9.info('sdk webrtc registering failed', {
6494
+ tries,
6495
+ registerer: !!this.registerer,
6496
+ forceClosed: this.forceClosed,
6497
+ });
6498
+ if (this.forceClosed) {
6499
+ return;
6500
+ }
6501
+
6451
6502
  this.connectionPromise = null;
6452
6503
  if (this.registerer && this.registerer.waiting) {
6453
6504
  this.registerer.waitingToggle(false);
@@ -6725,8 +6776,9 @@ class WebRTCClient extends Emitter {
6725
6776
  }
6726
6777
  }
6727
6778
 
6728
- async close() {
6729
- logger$9.info('sdk webrtc closing client', { userAgent: !!this.userAgent });
6779
+ async close(force = false) {
6780
+ logger$9.info('sdk webrtc closing client', { userAgent: !!this.userAgent, force });
6781
+ this.forceClosed = force;
6730
6782
  this._cleanupMedia();
6731
6783
  this.connectionPromise = null;
6732
6784
 
@@ -6745,7 +6797,7 @@ class WebRTCClient extends Emitter {
6745
6797
  this.userAgent.delegate = null;
6746
6798
  this.userAgent.stateChange.removeAllListeners();
6747
6799
 
6748
- await this._disconnectTransport();
6800
+ await this._disconnectTransport(force);
6749
6801
 
6750
6802
  this._cleanupRegister();
6751
6803
 
@@ -7815,6 +7867,13 @@ class WebRTCClient extends Emitter {
7815
7867
  }
7816
7868
 
7817
7869
  _createWebRTCConfiguration(configOverrides = {}) {
7870
+ let { host } = this.config;
7871
+ let port = this.config.port || 443;
7872
+
7873
+ if (this.config.websocketSip) {
7874
+ [host, port = 443] = this.config.websocketSip.split(':');
7875
+ }
7876
+
7818
7877
  const config = {
7819
7878
  authorizationUsername: this.config.authorizationUser,
7820
7879
  authorizationPassword: this.config.password,
@@ -7850,7 +7909,7 @@ class WebRTCClient extends Emitter {
7850
7909
  },
7851
7910
  transportOptions: {
7852
7911
  traceSip: configOverrides.traceSip || false,
7853
- wsServers: `wss://${this.config.host}:${this.config.port || 443}/api/asterisk/ws`,
7912
+ wsServers: `wss://${host}:${port}/api/asterisk/ws`,
7854
7913
  },
7855
7914
  sessionDescriptionHandlerFactoryOptions: {
7856
7915
  modifiers: [replaceLocalIpModifier],
@@ -8174,7 +8233,15 @@ class WebRTCClient extends Emitter {
8174
8233
  return UserAgent.makeURI(`sip:${target}@${this.config.host}`);
8175
8234
  }
8176
8235
 
8177
- async _disconnectTransport() {
8236
+ async _disconnectTransport(force = false) {
8237
+ if (force) {
8238
+ // Bypass sip.js state machine that prevent to close WS with the state `Connecting`
8239
+ this.userAgent.transport.disconnectResolve = () => {};
8240
+ // eslint-disable-next-line
8241
+ this.userAgent.transport._ws.close(1000);
8242
+ return;
8243
+ }
8244
+
8178
8245
  // Check if `disconnectPromise` is not present to avoid `Disconnect promise must not be defined` errors.
8179
8246
  if (this.userAgent && this.userAgent.transport && !this.userAgent.transport.disconnectPromise) {
8180
8247
  try {
@@ -9812,6 +9879,7 @@ class WebRTCPhone extends Emitter {
9812
9879
  }
9813
9880
 
9814
9881
  callSession.answerTime = new Date();
9882
+ this._updateCallSession(callSession);
9815
9883
  this.eventEmitter.emit(ON_CALL_ACCEPTED, callSession, cameraEnabled);
9816
9884
 
9817
9885
  return callSession;
@@ -10028,6 +10096,7 @@ class WebRTCPhone extends Emitter {
10028
10096
 
10029
10097
  this.shouldSendReinvite = false;
10030
10098
  callSession.answerTime = new Date();
10099
+ this._updateCallSession(callSession);
10031
10100
  this.acceptedSessions[callSession.getId()] = true;
10032
10101
 
10033
10102
  this.eventEmitter.emit(ON_CALL_ANSWERED, callSession);
@@ -10127,7 +10196,7 @@ class WebRTCPhone extends Emitter {
10127
10196
  // Hold current session if different from the current one (we don't want 2 sessions active at the same time).
10128
10197
  if (this.currentSipSession && this.currentSipSession.id !== sipSession.id) {
10129
10198
  logger$7.info('WebRTC hold call after resume', { id: this.currentSipSession.id });
10130
- this.holdSipSession(this.currentSipSession, callSession);
10199
+ this.holdSipSession(this.currentSipSession, this.currentCallSession);
10131
10200
  }
10132
10201
 
10133
10202
  const promise = this.unholdSipSession(sipSession, callSession, withEvent, isConference);
@@ -10338,6 +10407,7 @@ class WebRTCPhone extends Emitter {
10338
10407
  }
10339
10408
  const callSession = this._createOutgoingCallSession(sipSession, cameraEnabled || false);
10340
10409
  callSession.creationTime = new Date();
10410
+ this._updateCallSession(callSession);
10341
10411
 
10342
10412
  this.eventEmitter.emit(ON_PLAY_PROGRESS_SOUND, this.audioOutputDeviceId, this.audioOutputVolume);
10343
10413
 
@@ -10479,7 +10549,7 @@ class WebRTCPhone extends Emitter {
10479
10549
  return this.client && this.client.isConference(callSession.sipCallId);
10480
10550
  }
10481
10551
 
10482
- async close() {
10552
+ async close(force = false) {
10483
10553
  logger$7.info('WebRTC close');
10484
10554
 
10485
10555
  try {
@@ -10491,7 +10561,7 @@ class WebRTCPhone extends Emitter {
10491
10561
  logger$7.error('WebRTC close, unregister error', e);
10492
10562
  }
10493
10563
 
10494
- this.client.close();
10564
+ this.client.close(force);
10495
10565
  this.unbind();
10496
10566
 
10497
10567
  this.incomingSessions = [];
@@ -10617,6 +10687,8 @@ class WebRTCPhone extends Emitter {
10617
10687
  }
10618
10688
 
10619
10689
  callSession.creationTime = new Date();
10690
+ this._updateCallSession(callSession);
10691
+
10620
10692
  this.eventEmitter.emit(ON_CALL_INCOMING, callSession, wantsToDoVideo);
10621
10693
  });
10622
10694
 
@@ -10660,6 +10732,8 @@ class WebRTCPhone extends Emitter {
10660
10732
  logger$7.info('WebRTC call rejected', session.id);
10661
10733
  const callSession = this._createCallSession(session);
10662
10734
  callSession.endTime = new Date();
10735
+ this._updateCallSession(callSession);
10736
+
10663
10737
  this.eventEmitter.emit(ON_CALL_REJECTED, callSession);
10664
10738
  });
10665
10739
 
@@ -10884,6 +10958,7 @@ class WebRTCPhone extends Emitter {
10884
10958
  displayName: identity ? identity.displayName || number : number,
10885
10959
  startTime: fromSession ? fromSession.startTime : new Date(),
10886
10960
  creationTime: fromSession ? fromSession.creationTime : null,
10961
+ answerTime: fromSession ? fromSession.answerTime : null,
10887
10962
  endTime: fromSession ? fromSession.endTime : null,
10888
10963
  answered: state === SessionState.Established,
10889
10964
  paused: this.client.isCallHeld(sipSession),
@@ -4016,6 +4016,34 @@ class IndirectTransfer {
4016
4016
  }
4017
4017
  }
4018
4018
 
4019
+ //
4020
+
4021
+
4022
+
4023
+
4024
+
4025
+ class MeetingStatus {
4026
+
4027
+
4028
+
4029
+
4030
+ constructor({
4031
+ full,
4032
+ } = {}) {
4033
+ this.full = full;
4034
+
4035
+ // Useful to compare instead of instanceof with minified code
4036
+ this.type = 'MeetingStatus';
4037
+ }
4038
+
4039
+ static parse(plain ) {
4040
+ return new MeetingStatus({
4041
+ full: plain.full,
4042
+ });
4043
+ }
4044
+
4045
+ }
4046
+
4019
4047
  /* */
4020
4048
 
4021
4049
 
@@ -4210,6 +4238,8 @@ var calldMethods = (client , baseUrl ) => ({
4210
4238
  client.put(`${baseUrl}/users/me/calls/${callId}/record/resume`, null, null,
4211
4239
  ApiRequester.successResponseParser),
4212
4240
 
4241
+ guestGetMeetingStatus: (meetingUuid ) =>
4242
+ client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}/status`).then(MeetingStatus.parse),
4213
4243
  });
4214
4244
 
4215
4245
  //
@@ -4016,6 +4016,34 @@ var chatdMethods = (client , baseUrl ) => ({
4016
4016
  client.get(`${baseUrl}/users/me/rooms/messages`, options),
4017
4017
  });
4018
4018
 
4019
+ //
4020
+
4021
+
4022
+
4023
+
4024
+
4025
+ class MeetingStatus {
4026
+
4027
+
4028
+
4029
+
4030
+ constructor({
4031
+ full,
4032
+ } = {}) {
4033
+ this.full = full;
4034
+
4035
+ // Useful to compare instead of instanceof with minified code
4036
+ this.type = 'MeetingStatus';
4037
+ }
4038
+
4039
+ static parse(plain ) {
4040
+ return new MeetingStatus({
4041
+ full: plain.full,
4042
+ });
4043
+ }
4044
+
4045
+ }
4046
+
4019
4047
  /* */
4020
4048
 
4021
4049
 
@@ -4210,6 +4238,8 @@ var calldMethods = (client , baseUrl ) => ({
4210
4238
  client.put(`${baseUrl}/users/me/calls/${callId}/record/resume`, null, null,
4211
4239
  ApiRequester.successResponseParser),
4212
4240
 
4241
+ guestGetMeetingStatus: (meetingUuid ) =>
4242
+ client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}/status`).then(MeetingStatus.parse),
4213
4243
  });
4214
4244
 
4215
4245
  //
@@ -3584,13 +3584,21 @@ class CallSession {
3584
3584
 
3585
3585
  // Retro-compatibility: `answered` was a boolean before. We can reproduce the behaviour with a getter/setter
3586
3586
  set answered(value ) {
3587
- this.answerTime = value ? new Date() : null;
3587
+ this.answerTime = value ? this.answerTime || new Date() : null;
3588
3588
  }
3589
3589
 
3590
3590
  get answered() {
3591
3591
  return !!this.answerTime;
3592
3592
  }
3593
3593
 
3594
+ toJSON() {
3595
+ const jsonObj = { ...this };
3596
+ // $FlowFixMe
3597
+ jsonObj.answered = this.answered;
3598
+
3599
+ return jsonObj;
3600
+ }
3601
+
3594
3602
  static parseCall(call ) {
3595
3603
  return new CallSession({
3596
3604
  callId: call.id,
@@ -4842,6 +4850,34 @@ var chatdMethods = (client , baseUrl ) => ({
4842
4850
  client.get(`${baseUrl}/users/me/rooms/messages`, options),
4843
4851
  });
4844
4852
 
4853
+ //
4854
+
4855
+
4856
+
4857
+
4858
+
4859
+ class MeetingStatus {
4860
+
4861
+
4862
+
4863
+
4864
+ constructor({
4865
+ full,
4866
+ } = {}) {
4867
+ this.full = full;
4868
+
4869
+ // Useful to compare instead of instanceof with minified code
4870
+ this.type = 'MeetingStatus';
4871
+ }
4872
+
4873
+ static parse(plain ) {
4874
+ return new MeetingStatus({
4875
+ full: plain.full,
4876
+ });
4877
+ }
4878
+
4879
+ }
4880
+
4845
4881
  /* */
4846
4882
 
4847
4883
 
@@ -5036,6 +5072,8 @@ var calldMethods = (client , baseUrl ) => ({
5036
5072
  client.put(`${baseUrl}/users/me/calls/${callId}/record/resume`, null, null,
5037
5073
  ApiRequester.successResponseParser),
5038
5074
 
5075
+ guestGetMeetingStatus: (meetingUuid ) =>
5076
+ client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}/status`).then(MeetingStatus.parse),
5039
5077
  });
5040
5078
 
5041
5079
  //
@@ -6373,6 +6411,7 @@ const MAX_REGISTER_TRIES = 10;
6373
6411
 
6374
6412
 
6375
6413
 
6414
+
6376
6415
 
6377
6416
 
6378
6417
 
@@ -6414,6 +6453,7 @@ class WebRTCClient extends Emitter {
6414
6453
 
6415
6454
 
6416
6455
 
6456
+
6417
6457
 
6418
6458
  // sugar
6419
6459
 
@@ -6476,6 +6516,7 @@ class WebRTCClient extends Emitter {
6476
6516
  this.conferences = {};
6477
6517
  this.networkMonitoringInterval = {};
6478
6518
  this.sessionNetworkStats = {};
6519
+ this.forceClosed = false;
6479
6520
 
6480
6521
  this._boundOnHeartbeat = this._onHeartbeat.bind(this);
6481
6522
  this.heartbeat = new Heartbeat(config.heartbeatDelay, config.heartbeatTimeout, config.maxHeartbeats);
@@ -6597,6 +6638,8 @@ class WebRTCClient extends Emitter {
6597
6638
  skipRegister: this.skipRegister,
6598
6639
  };
6599
6640
 
6641
+ this.forceClosed = false;
6642
+
6600
6643
  if (this.skipRegister) {
6601
6644
  logger$9.info('sdk webrtc skip register...', logInfo);
6602
6645
  return Promise.resolve();
@@ -6621,7 +6664,15 @@ class WebRTCClient extends Emitter {
6621
6664
  const registerOptions = this._isWeb() ? {} : { extraContactHeaderParams: ['mobility=mobile'] };
6622
6665
 
6623
6666
  const onRegisterFailed = () => {
6624
- logger$9.info('sdk webrtc registering failed', { tries, registerer: !!this.registerer });
6667
+ logger$9.info('sdk webrtc registering failed', {
6668
+ tries,
6669
+ registerer: !!this.registerer,
6670
+ forceClosed: this.forceClosed,
6671
+ });
6672
+ if (this.forceClosed) {
6673
+ return;
6674
+ }
6675
+
6625
6676
  this.connectionPromise = null;
6626
6677
  if (this.registerer && this.registerer.waiting) {
6627
6678
  this.registerer.waitingToggle(false);
@@ -6899,8 +6950,9 @@ class WebRTCClient extends Emitter {
6899
6950
  }
6900
6951
  }
6901
6952
 
6902
- async close() {
6903
- logger$9.info('sdk webrtc closing client', { userAgent: !!this.userAgent });
6953
+ async close(force = false) {
6954
+ logger$9.info('sdk webrtc closing client', { userAgent: !!this.userAgent, force });
6955
+ this.forceClosed = force;
6904
6956
  this._cleanupMedia();
6905
6957
  this.connectionPromise = null;
6906
6958
 
@@ -6919,7 +6971,7 @@ class WebRTCClient extends Emitter {
6919
6971
  this.userAgent.delegate = null;
6920
6972
  this.userAgent.stateChange.removeAllListeners();
6921
6973
 
6922
- await this._disconnectTransport();
6974
+ await this._disconnectTransport(force);
6923
6975
 
6924
6976
  this._cleanupRegister();
6925
6977
 
@@ -7989,6 +8041,13 @@ class WebRTCClient extends Emitter {
7989
8041
  }
7990
8042
 
7991
8043
  _createWebRTCConfiguration(configOverrides = {}) {
8044
+ let { host } = this.config;
8045
+ let port = this.config.port || 443;
8046
+
8047
+ if (this.config.websocketSip) {
8048
+ [host, port = 443] = this.config.websocketSip.split(':');
8049
+ }
8050
+
7992
8051
  const config = {
7993
8052
  authorizationUsername: this.config.authorizationUser,
7994
8053
  authorizationPassword: this.config.password,
@@ -8024,7 +8083,7 @@ class WebRTCClient extends Emitter {
8024
8083
  },
8025
8084
  transportOptions: {
8026
8085
  traceSip: configOverrides.traceSip || false,
8027
- wsServers: `wss://${this.config.host}:${this.config.port || 443}/api/asterisk/ws`,
8086
+ wsServers: `wss://${host}:${port}/api/asterisk/ws`,
8028
8087
  },
8029
8088
  sessionDescriptionHandlerFactoryOptions: {
8030
8089
  modifiers: [replaceLocalIpModifier],
@@ -8348,7 +8407,15 @@ class WebRTCClient extends Emitter {
8348
8407
  return UserAgent.makeURI(`sip:${target}@${this.config.host}`);
8349
8408
  }
8350
8409
 
8351
- async _disconnectTransport() {
8410
+ async _disconnectTransport(force = false) {
8411
+ if (force) {
8412
+ // Bypass sip.js state machine that prevent to close WS with the state `Connecting`
8413
+ this.userAgent.transport.disconnectResolve = () => {};
8414
+ // eslint-disable-next-line
8415
+ this.userAgent.transport._ws.close(1000);
8416
+ return;
8417
+ }
8418
+
8352
8419
  // Check if `disconnectPromise` is not present to avoid `Disconnect promise must not be defined` errors.
8353
8420
  if (this.userAgent && this.userAgent.transport && !this.userAgent.transport.disconnectPromise) {
8354
8421
  try {
@@ -9085,6 +9152,7 @@ class WebRTCPhone extends Emitter {
9085
9152
  }
9086
9153
 
9087
9154
  callSession.answerTime = new Date();
9155
+ this._updateCallSession(callSession);
9088
9156
  this.eventEmitter.emit(ON_CALL_ACCEPTED, callSession, cameraEnabled);
9089
9157
 
9090
9158
  return callSession;
@@ -9301,6 +9369,7 @@ class WebRTCPhone extends Emitter {
9301
9369
 
9302
9370
  this.shouldSendReinvite = false;
9303
9371
  callSession.answerTime = new Date();
9372
+ this._updateCallSession(callSession);
9304
9373
  this.acceptedSessions[callSession.getId()] = true;
9305
9374
 
9306
9375
  this.eventEmitter.emit(ON_CALL_ANSWERED, callSession);
@@ -9400,7 +9469,7 @@ class WebRTCPhone extends Emitter {
9400
9469
  // Hold current session if different from the current one (we don't want 2 sessions active at the same time).
9401
9470
  if (this.currentSipSession && this.currentSipSession.id !== sipSession.id) {
9402
9471
  logger$8.info('WebRTC hold call after resume', { id: this.currentSipSession.id });
9403
- this.holdSipSession(this.currentSipSession, callSession);
9472
+ this.holdSipSession(this.currentSipSession, this.currentCallSession);
9404
9473
  }
9405
9474
 
9406
9475
  const promise = this.unholdSipSession(sipSession, callSession, withEvent, isConference);
@@ -9611,6 +9680,7 @@ class WebRTCPhone extends Emitter {
9611
9680
  }
9612
9681
  const callSession = this._createOutgoingCallSession(sipSession, cameraEnabled || false);
9613
9682
  callSession.creationTime = new Date();
9683
+ this._updateCallSession(callSession);
9614
9684
 
9615
9685
  this.eventEmitter.emit(ON_PLAY_PROGRESS_SOUND, this.audioOutputDeviceId, this.audioOutputVolume);
9616
9686
 
@@ -9752,7 +9822,7 @@ class WebRTCPhone extends Emitter {
9752
9822
  return this.client && this.client.isConference(callSession.sipCallId);
9753
9823
  }
9754
9824
 
9755
- async close() {
9825
+ async close(force = false) {
9756
9826
  logger$8.info('WebRTC close');
9757
9827
 
9758
9828
  try {
@@ -9764,7 +9834,7 @@ class WebRTCPhone extends Emitter {
9764
9834
  logger$8.error('WebRTC close, unregister error', e);
9765
9835
  }
9766
9836
 
9767
- this.client.close();
9837
+ this.client.close(force);
9768
9838
  this.unbind();
9769
9839
 
9770
9840
  this.incomingSessions = [];
@@ -9890,6 +9960,8 @@ class WebRTCPhone extends Emitter {
9890
9960
  }
9891
9961
 
9892
9962
  callSession.creationTime = new Date();
9963
+ this._updateCallSession(callSession);
9964
+
9893
9965
  this.eventEmitter.emit(ON_CALL_INCOMING, callSession, wantsToDoVideo);
9894
9966
  });
9895
9967
 
@@ -9933,6 +10005,8 @@ class WebRTCPhone extends Emitter {
9933
10005
  logger$8.info('WebRTC call rejected', session.id);
9934
10006
  const callSession = this._createCallSession(session);
9935
10007
  callSession.endTime = new Date();
10008
+ this._updateCallSession(callSession);
10009
+
9936
10010
  this.eventEmitter.emit(ON_CALL_REJECTED, callSession);
9937
10011
  });
9938
10012
 
@@ -10157,6 +10231,7 @@ class WebRTCPhone extends Emitter {
10157
10231
  displayName: identity ? identity.displayName || number : number,
10158
10232
  startTime: fromSession ? fromSession.startTime : new Date(),
10159
10233
  creationTime: fromSession ? fromSession.creationTime : null,
10234
+ answerTime: fromSession ? fromSession.answerTime : null,
10160
10235
  endTime: fromSession ? fromSession.endTime : null,
10161
10236
  answered: state === SessionState.Established,
10162
10237
  paused: this.client.isCallHeld(sipSession),