@wazo/sdk 0.37.31 → 0.37.35

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 (90) hide show
  1. package/dist/wazo-sdk.js +2 -2
  2. package/esm/__tests__/api-client.test.js +41 -0
  3. package/esm/__tests__/web-rtc-client.test.js +68 -6
  4. package/esm/api/auth.js +5 -0
  5. package/esm/api/call-logd.js +6 -0
  6. package/esm/api/calld.js +30 -0
  7. package/esm/api-client.js +41 -0
  8. package/esm/checker/Checker.js +68 -6
  9. package/esm/checker/checks/aor.js +41 -0
  10. package/esm/checker/checks/api.js +41 -0
  11. package/esm/checker/checks/index.js +68 -6
  12. package/esm/checker/checks/webrtc-transport.js +68 -6
  13. package/esm/checker/checks/webrtc.js +68 -6
  14. package/esm/domain/AdHocAPIConference.js +41 -0
  15. package/esm/domain/CallLog.js +6 -0
  16. package/esm/domain/CallSession.js +8 -0
  17. package/esm/domain/Features.js +41 -0
  18. package/esm/domain/MeetingStatus.js +29 -0
  19. package/esm/domain/Phone/CTIPhone.js +49 -0
  20. package/esm/domain/Phone/WebRTCPhone.js +33 -6
  21. package/esm/domain/__tests__/CallLog.test.js +6 -0
  22. package/esm/domain/__tests__/CallSession.test.js +40 -4
  23. package/esm/domain/__tests__/IndirectTransfer.test.js +8 -0
  24. package/esm/domain/__tests__/Room.test.js +8 -0
  25. package/esm/index.js +101 -12
  26. package/esm/service/CallApi.js +41 -0
  27. package/esm/service/getApiClient.js +41 -0
  28. package/esm/simple/Auth.js +101 -12
  29. package/esm/simple/Configuration.js +101 -12
  30. package/esm/simple/Directory.js +41 -0
  31. package/esm/simple/Phone.js +101 -12
  32. package/esm/simple/index.js +101 -12
  33. package/esm/simple/room/LocalParticipant.js +101 -12
  34. package/esm/simple/room/Participant.js +101 -12
  35. package/esm/simple/room/RemoteParticipant.js +101 -12
  36. package/esm/simple/room/Room.js +101 -12
  37. package/esm/simple/room/SipRoom.js +101 -12
  38. package/esm/simple/room/Stream.js +101 -12
  39. package/esm/simple/room/__tests__/RemoteParticipant.test.js +101 -12
  40. package/esm/simple/utils.js +101 -12
  41. package/esm/web-rtc-client.js +68 -6
  42. package/lib/__tests__/api-client.test.js +41 -0
  43. package/lib/__tests__/web-rtc-client.test.js +68 -6
  44. package/lib/api/auth.js +5 -0
  45. package/lib/api/call-logd.js +6 -0
  46. package/lib/api/calld.js +30 -0
  47. package/lib/api-client.js +41 -0
  48. package/lib/checker/Checker.js +68 -6
  49. package/lib/checker/checks/aor.js +41 -0
  50. package/lib/checker/checks/api.js +41 -0
  51. package/lib/checker/checks/index.js +68 -6
  52. package/lib/checker/checks/webrtc-transport.js +68 -6
  53. package/lib/checker/checks/webrtc.js +68 -6
  54. package/lib/domain/AdHocAPIConference.js +41 -0
  55. package/lib/domain/CallLog.js +6 -0
  56. package/lib/domain/CallSession.js +8 -0
  57. package/lib/domain/Features.js +41 -0
  58. package/lib/domain/MeetingStatus.js +31 -0
  59. package/lib/domain/Phone/CTIPhone.js +49 -0
  60. package/lib/domain/Phone/WebRTCPhone.js +33 -6
  61. package/lib/domain/__tests__/CallLog.test.js +6 -0
  62. package/lib/domain/__tests__/CallSession.test.js +40 -4
  63. package/lib/domain/__tests__/IndirectTransfer.test.js +8 -0
  64. package/lib/domain/__tests__/Room.test.js +8 -0
  65. package/lib/index.js +101 -12
  66. package/lib/service/CallApi.js +41 -0
  67. package/lib/service/getApiClient.js +41 -0
  68. package/lib/simple/Auth.js +101 -12
  69. package/lib/simple/Configuration.js +101 -12
  70. package/lib/simple/Directory.js +41 -0
  71. package/lib/simple/Phone.js +101 -12
  72. package/lib/simple/index.js +101 -12
  73. package/lib/simple/room/LocalParticipant.js +101 -12
  74. package/lib/simple/room/Participant.js +101 -12
  75. package/lib/simple/room/RemoteParticipant.js +101 -12
  76. package/lib/simple/room/Room.js +101 -12
  77. package/lib/simple/room/SipRoom.js +101 -12
  78. package/lib/simple/room/Stream.js +101 -12
  79. package/lib/simple/room/__tests__/RemoteParticipant.test.js +101 -12
  80. package/lib/simple/utils.js +101 -12
  81. package/lib/web-rtc-client.js +68 -6
  82. package/package.json +1 -1
  83. package/src/api/auth.js +5 -0
  84. package/src/api/calld.js +3 -0
  85. package/src/domain/CallLog.js +6 -0
  86. package/src/domain/CallSession.js +8 -0
  87. package/src/domain/MeetingStatus.js +27 -0
  88. package/src/domain/Phone/WebRTCPhone.js +25 -6
  89. package/src/domain/__tests__/CallSession.test.js +32 -4
  90. package/src/web-rtc-client.js +27 -6
@@ -2242,6 +2242,7 @@ var authMethods = (client , baseUrl ) => ({
2242
2242
 
2243
2243
 
2244
2244
 
2245
+
2245
2246
  ) {
2246
2247
  const body = {
2247
2248
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2261,6 +2262,10 @@ var authMethods = (client , baseUrl ) => ({
2261
2262
  headers['Wazo-Session-Type'] = 'mobile';
2262
2263
  }
2263
2264
 
2265
+ if (params.tenantId) {
2266
+ body.tenant_id = params.tenantId;
2267
+ }
2268
+
2264
2269
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2265
2270
  },
2266
2271
 
@@ -3617,6 +3622,14 @@ class CallSession {
3617
3622
  return !!this.answerTime;
3618
3623
  }
3619
3624
 
3625
+ toJSON() {
3626
+ const jsonObj = { ...this };
3627
+ // $FlowFixMe
3628
+ jsonObj.answered = this.answered;
3629
+
3630
+ return jsonObj;
3631
+ }
3632
+
3620
3633
  static parseCall(call ) {
3621
3634
  return new CallSession({
3622
3635
  callId: call.id,
@@ -3701,11 +3714,13 @@ class Recording {
3701
3714
 
3702
3715
 
3703
3716
 
3717
+
3704
3718
 
3705
3719
 
3706
3720
 
3707
3721
 
3708
3722
 
3723
+
3709
3724
 
3710
3725
 
3711
3726
 
@@ -3726,10 +3741,12 @@ class Recording {
3726
3741
 
3727
3742
 
3728
3743
 
3744
+
3729
3745
 
3730
3746
 
3731
3747
 
3732
3748
 
3749
+
3733
3750
 
3734
3751
 
3735
3752
 
@@ -3791,10 +3808,12 @@ class CallLog {
3791
3808
  || plain.destination_extension
3792
3809
  || `meeting-${plain.requested_name || plain.destination_name || ''}`,
3793
3810
  name: plain.requested_name || plain.destination_name || '',
3811
+ uuid: plain.destination_user_uuid,
3794
3812
  },
3795
3813
  source: {
3796
3814
  extension: plain.source_extension,
3797
3815
  name: plain.source_name,
3816
+ uuid: plain.source_user_uuid,
3798
3817
  },
3799
3818
  id: plain.id,
3800
3819
  duration: (plain.duration || 0) * 1000, // duration is in seconds
@@ -4842,6 +4861,34 @@ var chatdMethods = (client , baseUrl ) => ({
4842
4861
  client.get(`${baseUrl}/users/me/rooms/messages`, options),
4843
4862
  });
4844
4863
 
4864
+ //
4865
+
4866
+
4867
+
4868
+
4869
+
4870
+ class MeetingStatus {
4871
+
4872
+
4873
+
4874
+
4875
+ constructor({
4876
+ full,
4877
+ } = {}) {
4878
+ this.full = full;
4879
+
4880
+ // Useful to compare instead of instanceof with minified code
4881
+ this.type = 'MeetingStatus';
4882
+ }
4883
+
4884
+ static parse(plain ) {
4885
+ return new MeetingStatus({
4886
+ full: plain.full,
4887
+ });
4888
+ }
4889
+
4890
+ }
4891
+
4845
4892
  /* */
4846
4893
 
4847
4894
 
@@ -5036,6 +5083,8 @@ var calldMethods = (client , baseUrl ) => ({
5036
5083
  client.put(`${baseUrl}/users/me/calls/${callId}/record/resume`, null, null,
5037
5084
  ApiRequester.successResponseParser),
5038
5085
 
5086
+ guestGetMeetingStatus: (meetingUuid ) =>
5087
+ client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}/status`).then(MeetingStatus.parse),
5039
5088
  });
5040
5089
 
5041
5090
  //
@@ -6625,7 +6674,7 @@ const events$1 = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
6625
6674
  const transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
6626
6675
  class CanceledCallError extends Error {}
6627
6676
 
6628
- const MAX_REGISTER_TRIES = 10;
6677
+ const MAX_REGISTER_TRIES = 5;
6629
6678
 
6630
6679
 
6631
6680
 
@@ -6679,6 +6728,7 @@ class WebRTCClient extends Emitter {
6679
6728
 
6680
6729
 
6681
6730
 
6731
+
6682
6732
 
6683
6733
  // sugar
6684
6734
 
@@ -6741,6 +6791,7 @@ class WebRTCClient extends Emitter {
6741
6791
  this.conferences = {};
6742
6792
  this.networkMonitoringInterval = {};
6743
6793
  this.sessionNetworkStats = {};
6794
+ this.forceClosed = false;
6744
6795
 
6745
6796
  this._boundOnHeartbeat = this._onHeartbeat.bind(this);
6746
6797
  this.heartbeat = new Heartbeat(config.heartbeatDelay, config.heartbeatTimeout, config.maxHeartbeats);
@@ -6862,6 +6913,8 @@ class WebRTCClient extends Emitter {
6862
6913
  skipRegister: this.skipRegister,
6863
6914
  };
6864
6915
 
6916
+ this.forceClosed = false;
6917
+
6865
6918
  if (this.skipRegister) {
6866
6919
  logger$8.info('sdk webrtc skip register...', logInfo);
6867
6920
  return Promise.resolve();
@@ -6886,7 +6939,15 @@ class WebRTCClient extends Emitter {
6886
6939
  const registerOptions = this._isWeb() ? {} : { extraContactHeaderParams: ['mobility=mobile'] };
6887
6940
 
6888
6941
  const onRegisterFailed = () => {
6889
- logger$8.info('sdk webrtc registering failed', { tries, registerer: !!this.registerer });
6942
+ logger$8.info('sdk webrtc registering failed', {
6943
+ tries,
6944
+ registerer: !!this.registerer,
6945
+ forceClosed: this.forceClosed,
6946
+ });
6947
+ if (this.forceClosed) {
6948
+ return;
6949
+ }
6950
+
6890
6951
  this.connectionPromise = null;
6891
6952
  if (this.registerer && this.registerer.waiting) {
6892
6953
  this.registerer.waitingToggle(false);
@@ -7164,8 +7225,9 @@ class WebRTCClient extends Emitter {
7164
7225
  }
7165
7226
  }
7166
7227
 
7167
- async close() {
7168
- logger$8.info('sdk webrtc closing client', { userAgent: !!this.userAgent });
7228
+ async close(force = false) {
7229
+ logger$8.info('sdk webrtc closing client', { userAgent: !!this.userAgent, force });
7230
+ this.forceClosed = force;
7169
7231
  this._cleanupMedia();
7170
7232
  this.connectionPromise = null;
7171
7233
 
@@ -7184,7 +7246,7 @@ class WebRTCClient extends Emitter {
7184
7246
  this.userAgent.delegate = null;
7185
7247
  this.userAgent.stateChange.removeAllListeners();
7186
7248
 
7187
- await this._disconnectTransport();
7249
+ await this._disconnectTransport(force);
7188
7250
 
7189
7251
  this._cleanupRegister();
7190
7252
 
@@ -8620,7 +8682,15 @@ class WebRTCClient extends Emitter {
8620
8682
  return UserAgent.makeURI(`sip:${target}@${this.config.host}`);
8621
8683
  }
8622
8684
 
8623
- async _disconnectTransport() {
8685
+ async _disconnectTransport(force = false) {
8686
+ if (force) {
8687
+ // Bypass sip.js state machine that prevent to close WS with the state `Connecting`
8688
+ this.userAgent.transport.disconnectResolve = () => {};
8689
+ // eslint-disable-next-line
8690
+ this.userAgent.transport._ws.close(1000);
8691
+ return;
8692
+ }
8693
+
8624
8694
  // Check if `disconnectPromise` is not present to avoid `Disconnect promise must not be defined` errors.
8625
8695
  if (this.userAgent && this.userAgent.transport && !this.userAgent.transport.disconnectPromise) {
8626
8696
  try {
@@ -9567,6 +9637,12 @@ class WebRTCPhone extends Emitter {
9567
9637
  return Promise.resolve(null);
9568
9638
  }
9569
9639
 
9640
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
9641
+ if (sipSessionId && !(sipSessionId in this.callSessions)) {
9642
+ logger$7.warn('Call session already ended or not found, can\'t accept it.', { sipSessionId });
9643
+ return Promise.resolve(null);
9644
+ }
9645
+
9570
9646
  if (callSession.getId() in this.acceptedSessions) {
9571
9647
  logger$7.warn('CallSession already accepted.', { id: callSession ? callSession.getId() : 'n/a' });
9572
9648
  return Promise.resolve(callSession.sipCallId);
@@ -10027,7 +10103,7 @@ class WebRTCPhone extends Emitter {
10027
10103
  return this.client && this.client.isConference(callSession.sipCallId);
10028
10104
  }
10029
10105
 
10030
- async close() {
10106
+ async close(force = false) {
10031
10107
  logger$7.info('WebRTC close');
10032
10108
 
10033
10109
  try {
@@ -10039,7 +10115,7 @@ class WebRTCPhone extends Emitter {
10039
10115
  logger$7.error('WebRTC close, unregister error', e);
10040
10116
  }
10041
10117
 
10042
- this.client.close();
10118
+ this.client.close(force);
10043
10119
  this.unbind();
10044
10120
 
10045
10121
  this.incomingSessions = [];
@@ -10191,9 +10267,17 @@ class WebRTCPhone extends Emitter {
10191
10267
  });
10192
10268
 
10193
10269
  this.client.on(this.client.ACCEPTED, (sipSession ) => {
10194
- logger$7.info('WebRTC call accepted', { sipId: sipSession.id });
10270
+ const sessionId = this.getSipSessionId(sipSession);
10271
+ const hasSession = sessionId in this.callSessions;
10272
+
10273
+ logger$7.info('WebRTC call accepted', { sipId: sessionId, hasSession });
10274
+
10275
+ if (!hasSession) {
10276
+ logger$7.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', { sessionId });
10277
+ return;
10278
+ }
10195
10279
 
10196
- this._onCallAccepted(sipSession, this.client.hasVideo(this.getSipSessionId(sipSession)));
10280
+ this._onCallAccepted(sipSession, this.client.hasVideo(sessionId));
10197
10281
 
10198
10282
  if (this.audioOutputDeviceId) {
10199
10283
  this.client.changeAudioOutputDevice(this.audioOutputDeviceId);
@@ -10329,9 +10413,14 @@ class WebRTCPhone extends Emitter {
10329
10413
  return this.client.getSipSessionId(sipSession);
10330
10414
  }
10331
10415
 
10332
- _updateCallSession(callSession ) {
10416
+ getSipSessionIdFromCallSession(callSession ) {
10333
10417
  const sipSession = this.findSipSession(callSession);
10334
- const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10418
+
10419
+ return sipSession ? this.getSipSessionId(sipSession) : null;
10420
+ }
10421
+
10422
+ _updateCallSession(callSession ) {
10423
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
10335
10424
 
10336
10425
  if (sipSessionId) {
10337
10426
  this.callSessions[sipSessionId] = callSession;
@@ -2242,6 +2242,7 @@ var authMethods = (client , baseUrl ) => ({
2242
2242
 
2243
2243
 
2244
2244
 
2245
+
2245
2246
  ) {
2246
2247
  const body = {
2247
2248
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2261,6 +2262,10 @@ var authMethods = (client , baseUrl ) => ({
2261
2262
  headers['Wazo-Session-Type'] = 'mobile';
2262
2263
  }
2263
2264
 
2265
+ if (params.tenantId) {
2266
+ body.tenant_id = params.tenantId;
2267
+ }
2268
+
2264
2269
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2265
2270
  },
2266
2271
 
@@ -3617,6 +3622,14 @@ class CallSession {
3617
3622
  return !!this.answerTime;
3618
3623
  }
3619
3624
 
3625
+ toJSON() {
3626
+ const jsonObj = { ...this };
3627
+ // $FlowFixMe
3628
+ jsonObj.answered = this.answered;
3629
+
3630
+ return jsonObj;
3631
+ }
3632
+
3620
3633
  static parseCall(call ) {
3621
3634
  return new CallSession({
3622
3635
  callId: call.id,
@@ -3701,11 +3714,13 @@ class Recording {
3701
3714
 
3702
3715
 
3703
3716
 
3717
+
3704
3718
 
3705
3719
 
3706
3720
 
3707
3721
 
3708
3722
 
3723
+
3709
3724
 
3710
3725
 
3711
3726
 
@@ -3726,10 +3741,12 @@ class Recording {
3726
3741
 
3727
3742
 
3728
3743
 
3744
+
3729
3745
 
3730
3746
 
3731
3747
 
3732
3748
 
3749
+
3733
3750
 
3734
3751
 
3735
3752
 
@@ -3791,10 +3808,12 @@ class CallLog {
3791
3808
  || plain.destination_extension
3792
3809
  || `meeting-${plain.requested_name || plain.destination_name || ''}`,
3793
3810
  name: plain.requested_name || plain.destination_name || '',
3811
+ uuid: plain.destination_user_uuid,
3794
3812
  },
3795
3813
  source: {
3796
3814
  extension: plain.source_extension,
3797
3815
  name: plain.source_name,
3816
+ uuid: plain.source_user_uuid,
3798
3817
  },
3799
3818
  id: plain.id,
3800
3819
  duration: (plain.duration || 0) * 1000, // duration is in seconds
@@ -4842,6 +4861,34 @@ var chatdMethods = (client , baseUrl ) => ({
4842
4861
  client.get(`${baseUrl}/users/me/rooms/messages`, options),
4843
4862
  });
4844
4863
 
4864
+ //
4865
+
4866
+
4867
+
4868
+
4869
+
4870
+ class MeetingStatus {
4871
+
4872
+
4873
+
4874
+
4875
+ constructor({
4876
+ full,
4877
+ } = {}) {
4878
+ this.full = full;
4879
+
4880
+ // Useful to compare instead of instanceof with minified code
4881
+ this.type = 'MeetingStatus';
4882
+ }
4883
+
4884
+ static parse(plain ) {
4885
+ return new MeetingStatus({
4886
+ full: plain.full,
4887
+ });
4888
+ }
4889
+
4890
+ }
4891
+
4845
4892
  /* */
4846
4893
 
4847
4894
 
@@ -5036,6 +5083,8 @@ var calldMethods = (client , baseUrl ) => ({
5036
5083
  client.put(`${baseUrl}/users/me/calls/${callId}/record/resume`, null, null,
5037
5084
  ApiRequester.successResponseParser),
5038
5085
 
5086
+ guestGetMeetingStatus: (meetingUuid ) =>
5087
+ client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}/status`).then(MeetingStatus.parse),
5039
5088
  });
5040
5089
 
5041
5090
  //
@@ -6625,7 +6674,7 @@ const events$1 = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
6625
6674
  const transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
6626
6675
  class CanceledCallError extends Error {}
6627
6676
 
6628
- const MAX_REGISTER_TRIES = 10;
6677
+ const MAX_REGISTER_TRIES = 5;
6629
6678
 
6630
6679
 
6631
6680
 
@@ -6679,6 +6728,7 @@ class WebRTCClient extends Emitter {
6679
6728
 
6680
6729
 
6681
6730
 
6731
+
6682
6732
 
6683
6733
  // sugar
6684
6734
 
@@ -6741,6 +6791,7 @@ class WebRTCClient extends Emitter {
6741
6791
  this.conferences = {};
6742
6792
  this.networkMonitoringInterval = {};
6743
6793
  this.sessionNetworkStats = {};
6794
+ this.forceClosed = false;
6744
6795
 
6745
6796
  this._boundOnHeartbeat = this._onHeartbeat.bind(this);
6746
6797
  this.heartbeat = new Heartbeat(config.heartbeatDelay, config.heartbeatTimeout, config.maxHeartbeats);
@@ -6862,6 +6913,8 @@ class WebRTCClient extends Emitter {
6862
6913
  skipRegister: this.skipRegister,
6863
6914
  };
6864
6915
 
6916
+ this.forceClosed = false;
6917
+
6865
6918
  if (this.skipRegister) {
6866
6919
  logger$8.info('sdk webrtc skip register...', logInfo);
6867
6920
  return Promise.resolve();
@@ -6886,7 +6939,15 @@ class WebRTCClient extends Emitter {
6886
6939
  const registerOptions = this._isWeb() ? {} : { extraContactHeaderParams: ['mobility=mobile'] };
6887
6940
 
6888
6941
  const onRegisterFailed = () => {
6889
- logger$8.info('sdk webrtc registering failed', { tries, registerer: !!this.registerer });
6942
+ logger$8.info('sdk webrtc registering failed', {
6943
+ tries,
6944
+ registerer: !!this.registerer,
6945
+ forceClosed: this.forceClosed,
6946
+ });
6947
+ if (this.forceClosed) {
6948
+ return;
6949
+ }
6950
+
6890
6951
  this.connectionPromise = null;
6891
6952
  if (this.registerer && this.registerer.waiting) {
6892
6953
  this.registerer.waitingToggle(false);
@@ -7164,8 +7225,9 @@ class WebRTCClient extends Emitter {
7164
7225
  }
7165
7226
  }
7166
7227
 
7167
- async close() {
7168
- logger$8.info('sdk webrtc closing client', { userAgent: !!this.userAgent });
7228
+ async close(force = false) {
7229
+ logger$8.info('sdk webrtc closing client', { userAgent: !!this.userAgent, force });
7230
+ this.forceClosed = force;
7169
7231
  this._cleanupMedia();
7170
7232
  this.connectionPromise = null;
7171
7233
 
@@ -7184,7 +7246,7 @@ class WebRTCClient extends Emitter {
7184
7246
  this.userAgent.delegate = null;
7185
7247
  this.userAgent.stateChange.removeAllListeners();
7186
7248
 
7187
- await this._disconnectTransport();
7249
+ await this._disconnectTransport(force);
7188
7250
 
7189
7251
  this._cleanupRegister();
7190
7252
 
@@ -8620,7 +8682,15 @@ class WebRTCClient extends Emitter {
8620
8682
  return UserAgent.makeURI(`sip:${target}@${this.config.host}`);
8621
8683
  }
8622
8684
 
8623
- async _disconnectTransport() {
8685
+ async _disconnectTransport(force = false) {
8686
+ if (force) {
8687
+ // Bypass sip.js state machine that prevent to close WS with the state `Connecting`
8688
+ this.userAgent.transport.disconnectResolve = () => {};
8689
+ // eslint-disable-next-line
8690
+ this.userAgent.transport._ws.close(1000);
8691
+ return;
8692
+ }
8693
+
8624
8694
  // Check if `disconnectPromise` is not present to avoid `Disconnect promise must not be defined` errors.
8625
8695
  if (this.userAgent && this.userAgent.transport && !this.userAgent.transport.disconnectPromise) {
8626
8696
  try {
@@ -9567,6 +9637,12 @@ class WebRTCPhone extends Emitter {
9567
9637
  return Promise.resolve(null);
9568
9638
  }
9569
9639
 
9640
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
9641
+ if (sipSessionId && !(sipSessionId in this.callSessions)) {
9642
+ logger$7.warn('Call session already ended or not found, can\'t accept it.', { sipSessionId });
9643
+ return Promise.resolve(null);
9644
+ }
9645
+
9570
9646
  if (callSession.getId() in this.acceptedSessions) {
9571
9647
  logger$7.warn('CallSession already accepted.', { id: callSession ? callSession.getId() : 'n/a' });
9572
9648
  return Promise.resolve(callSession.sipCallId);
@@ -10027,7 +10103,7 @@ class WebRTCPhone extends Emitter {
10027
10103
  return this.client && this.client.isConference(callSession.sipCallId);
10028
10104
  }
10029
10105
 
10030
- async close() {
10106
+ async close(force = false) {
10031
10107
  logger$7.info('WebRTC close');
10032
10108
 
10033
10109
  try {
@@ -10039,7 +10115,7 @@ class WebRTCPhone extends Emitter {
10039
10115
  logger$7.error('WebRTC close, unregister error', e);
10040
10116
  }
10041
10117
 
10042
- this.client.close();
10118
+ this.client.close(force);
10043
10119
  this.unbind();
10044
10120
 
10045
10121
  this.incomingSessions = [];
@@ -10191,9 +10267,17 @@ class WebRTCPhone extends Emitter {
10191
10267
  });
10192
10268
 
10193
10269
  this.client.on(this.client.ACCEPTED, (sipSession ) => {
10194
- logger$7.info('WebRTC call accepted', { sipId: sipSession.id });
10270
+ const sessionId = this.getSipSessionId(sipSession);
10271
+ const hasSession = sessionId in this.callSessions;
10272
+
10273
+ logger$7.info('WebRTC call accepted', { sipId: sessionId, hasSession });
10274
+
10275
+ if (!hasSession) {
10276
+ logger$7.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', { sessionId });
10277
+ return;
10278
+ }
10195
10279
 
10196
- this._onCallAccepted(sipSession, this.client.hasVideo(this.getSipSessionId(sipSession)));
10280
+ this._onCallAccepted(sipSession, this.client.hasVideo(sessionId));
10197
10281
 
10198
10282
  if (this.audioOutputDeviceId) {
10199
10283
  this.client.changeAudioOutputDevice(this.audioOutputDeviceId);
@@ -10329,9 +10413,14 @@ class WebRTCPhone extends Emitter {
10329
10413
  return this.client.getSipSessionId(sipSession);
10330
10414
  }
10331
10415
 
10332
- _updateCallSession(callSession ) {
10416
+ getSipSessionIdFromCallSession(callSession ) {
10333
10417
  const sipSession = this.findSipSession(callSession);
10334
- const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10418
+
10419
+ return sipSession ? this.getSipSessionId(sipSession) : null;
10420
+ }
10421
+
10422
+ _updateCallSession(callSession ) {
10423
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
10335
10424
 
10336
10425
  if (sipSessionId) {
10337
10426
  this.callSessions[sipSessionId] = callSession;