@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
@@ -2226,6 +2226,7 @@ var authMethods = (client , baseUrl ) => ({
2226
2226
 
2227
2227
 
2228
2228
 
2229
+
2229
2230
  ) {
2230
2231
  const body = {
2231
2232
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2245,6 +2246,10 @@ var authMethods = (client , baseUrl ) => ({
2245
2246
  headers['Wazo-Session-Type'] = 'mobile';
2246
2247
  }
2247
2248
 
2249
+ if (params.tenantId) {
2250
+ body.tenant_id = params.tenantId;
2251
+ }
2252
+
2248
2253
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2249
2254
  },
2250
2255
 
@@ -3601,6 +3606,14 @@ class CallSession {
3601
3606
  return !!this.answerTime;
3602
3607
  }
3603
3608
 
3609
+ toJSON() {
3610
+ const jsonObj = { ...this };
3611
+ // $FlowFixMe
3612
+ jsonObj.answered = this.answered;
3613
+
3614
+ return jsonObj;
3615
+ }
3616
+
3604
3617
  static parseCall(call ) {
3605
3618
  return new CallSession({
3606
3619
  callId: call.id,
@@ -3711,11 +3724,13 @@ class Recording {
3711
3724
 
3712
3725
 
3713
3726
 
3727
+
3714
3728
 
3715
3729
 
3716
3730
 
3717
3731
 
3718
3732
 
3733
+
3719
3734
 
3720
3735
 
3721
3736
 
@@ -3736,10 +3751,12 @@ class Recording {
3736
3751
 
3737
3752
 
3738
3753
 
3754
+
3739
3755
 
3740
3756
 
3741
3757
 
3742
3758
 
3759
+
3743
3760
 
3744
3761
 
3745
3762
 
@@ -3801,10 +3818,12 @@ class CallLog {
3801
3818
  || plain.destination_extension
3802
3819
  || `meeting-${plain.requested_name || plain.destination_name || ''}`,
3803
3820
  name: plain.requested_name || plain.destination_name || '',
3821
+ uuid: plain.destination_user_uuid,
3804
3822
  },
3805
3823
  source: {
3806
3824
  extension: plain.source_extension,
3807
3825
  name: plain.source_name,
3826
+ uuid: plain.source_user_uuid,
3808
3827
  },
3809
3828
  id: plain.id,
3810
3829
  duration: (plain.duration || 0) * 1000, // duration is in seconds
@@ -4852,6 +4871,34 @@ var chatdMethods = (client , baseUrl ) => ({
4852
4871
  client.get(`${baseUrl}/users/me/rooms/messages`, options),
4853
4872
  });
4854
4873
 
4874
+ //
4875
+
4876
+
4877
+
4878
+
4879
+
4880
+ class MeetingStatus {
4881
+
4882
+
4883
+
4884
+
4885
+ constructor({
4886
+ full,
4887
+ } = {}) {
4888
+ this.full = full;
4889
+
4890
+ // Useful to compare instead of instanceof with minified code
4891
+ this.type = 'MeetingStatus';
4892
+ }
4893
+
4894
+ static parse(plain ) {
4895
+ return new MeetingStatus({
4896
+ full: plain.full,
4897
+ });
4898
+ }
4899
+
4900
+ }
4901
+
4855
4902
  /* */
4856
4903
 
4857
4904
 
@@ -5046,6 +5093,8 @@ var calldMethods = (client , baseUrl ) => ({
5046
5093
  client.put(`${baseUrl}/users/me/calls/${callId}/record/resume`, null, null,
5047
5094
  ApiRequester.successResponseParser),
5048
5095
 
5096
+ guestGetMeetingStatus: (meetingUuid ) =>
5097
+ client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}/status`).then(MeetingStatus.parse),
5049
5098
  });
5050
5099
 
5051
5100
  //
@@ -6635,7 +6684,7 @@ const events$1 = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
6635
6684
  const transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
6636
6685
  class CanceledCallError extends Error {}
6637
6686
 
6638
- const MAX_REGISTER_TRIES = 10;
6687
+ const MAX_REGISTER_TRIES = 5;
6639
6688
 
6640
6689
 
6641
6690
 
@@ -6689,6 +6738,7 @@ class WebRTCClient extends Emitter {
6689
6738
 
6690
6739
 
6691
6740
 
6741
+
6692
6742
 
6693
6743
  // sugar
6694
6744
 
@@ -6751,6 +6801,7 @@ class WebRTCClient extends Emitter {
6751
6801
  this.conferences = {};
6752
6802
  this.networkMonitoringInterval = {};
6753
6803
  this.sessionNetworkStats = {};
6804
+ this.forceClosed = false;
6754
6805
 
6755
6806
  this._boundOnHeartbeat = this._onHeartbeat.bind(this);
6756
6807
  this.heartbeat = new Heartbeat(config.heartbeatDelay, config.heartbeatTimeout, config.maxHeartbeats);
@@ -6872,6 +6923,8 @@ class WebRTCClient extends Emitter {
6872
6923
  skipRegister: this.skipRegister,
6873
6924
  };
6874
6925
 
6926
+ this.forceClosed = false;
6927
+
6875
6928
  if (this.skipRegister) {
6876
6929
  logger$8.info('sdk webrtc skip register...', logInfo);
6877
6930
  return Promise.resolve();
@@ -6896,7 +6949,15 @@ class WebRTCClient extends Emitter {
6896
6949
  const registerOptions = this._isWeb() ? {} : { extraContactHeaderParams: ['mobility=mobile'] };
6897
6950
 
6898
6951
  const onRegisterFailed = () => {
6899
- logger$8.info('sdk webrtc registering failed', { tries, registerer: !!this.registerer });
6952
+ logger$8.info('sdk webrtc registering failed', {
6953
+ tries,
6954
+ registerer: !!this.registerer,
6955
+ forceClosed: this.forceClosed,
6956
+ });
6957
+ if (this.forceClosed) {
6958
+ return;
6959
+ }
6960
+
6900
6961
  this.connectionPromise = null;
6901
6962
  if (this.registerer && this.registerer.waiting) {
6902
6963
  this.registerer.waitingToggle(false);
@@ -7174,8 +7235,9 @@ class WebRTCClient extends Emitter {
7174
7235
  }
7175
7236
  }
7176
7237
 
7177
- async close() {
7178
- logger$8.info('sdk webrtc closing client', { userAgent: !!this.userAgent });
7238
+ async close(force = false) {
7239
+ logger$8.info('sdk webrtc closing client', { userAgent: !!this.userAgent, force });
7240
+ this.forceClosed = force;
7179
7241
  this._cleanupMedia();
7180
7242
  this.connectionPromise = null;
7181
7243
 
@@ -7194,7 +7256,7 @@ class WebRTCClient extends Emitter {
7194
7256
  this.userAgent.delegate = null;
7195
7257
  this.userAgent.stateChange.removeAllListeners();
7196
7258
 
7197
- await this._disconnectTransport();
7259
+ await this._disconnectTransport(force);
7198
7260
 
7199
7261
  this._cleanupRegister();
7200
7262
 
@@ -8630,7 +8692,15 @@ class WebRTCClient extends Emitter {
8630
8692
  return userAgent.UserAgent.makeURI(`sip:${target}@${this.config.host}`);
8631
8693
  }
8632
8694
 
8633
- async _disconnectTransport() {
8695
+ async _disconnectTransport(force = false) {
8696
+ if (force) {
8697
+ // Bypass sip.js state machine that prevent to close WS with the state `Connecting`
8698
+ this.userAgent.transport.disconnectResolve = () => {};
8699
+ // eslint-disable-next-line
8700
+ this.userAgent.transport._ws.close(1000);
8701
+ return;
8702
+ }
8703
+
8634
8704
  // Check if `disconnectPromise` is not present to avoid `Disconnect promise must not be defined` errors.
8635
8705
  if (this.userAgent && this.userAgent.transport && !this.userAgent.transport.disconnectPromise) {
8636
8706
  try {
@@ -9577,6 +9647,12 @@ class WebRTCPhone extends Emitter {
9577
9647
  return Promise.resolve(null);
9578
9648
  }
9579
9649
 
9650
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
9651
+ if (sipSessionId && !(sipSessionId in this.callSessions)) {
9652
+ logger$7.warn('Call session already ended or not found, can\'t accept it.', { sipSessionId });
9653
+ return Promise.resolve(null);
9654
+ }
9655
+
9580
9656
  if (callSession.getId() in this.acceptedSessions) {
9581
9657
  logger$7.warn('CallSession already accepted.', { id: callSession ? callSession.getId() : 'n/a' });
9582
9658
  return Promise.resolve(callSession.sipCallId);
@@ -10037,7 +10113,7 @@ class WebRTCPhone extends Emitter {
10037
10113
  return this.client && this.client.isConference(callSession.sipCallId);
10038
10114
  }
10039
10115
 
10040
- async close() {
10116
+ async close(force = false) {
10041
10117
  logger$7.info('WebRTC close');
10042
10118
 
10043
10119
  try {
@@ -10049,7 +10125,7 @@ class WebRTCPhone extends Emitter {
10049
10125
  logger$7.error('WebRTC close, unregister error', e);
10050
10126
  }
10051
10127
 
10052
- this.client.close();
10128
+ this.client.close(force);
10053
10129
  this.unbind();
10054
10130
 
10055
10131
  this.incomingSessions = [];
@@ -10201,9 +10277,17 @@ class WebRTCPhone extends Emitter {
10201
10277
  });
10202
10278
 
10203
10279
  this.client.on(this.client.ACCEPTED, (sipSession ) => {
10204
- logger$7.info('WebRTC call accepted', { sipId: sipSession.id });
10280
+ const sessionId = this.getSipSessionId(sipSession);
10281
+ const hasSession = sessionId in this.callSessions;
10282
+
10283
+ logger$7.info('WebRTC call accepted', { sipId: sessionId, hasSession });
10284
+
10285
+ if (!hasSession) {
10286
+ logger$7.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', { sessionId });
10287
+ return;
10288
+ }
10205
10289
 
10206
- this._onCallAccepted(sipSession, this.client.hasVideo(this.getSipSessionId(sipSession)));
10290
+ this._onCallAccepted(sipSession, this.client.hasVideo(sessionId));
10207
10291
 
10208
10292
  if (this.audioOutputDeviceId) {
10209
10293
  this.client.changeAudioOutputDevice(this.audioOutputDeviceId);
@@ -10339,9 +10423,14 @@ class WebRTCPhone extends Emitter {
10339
10423
  return this.client.getSipSessionId(sipSession);
10340
10424
  }
10341
10425
 
10342
- _updateCallSession(callSession ) {
10426
+ getSipSessionIdFromCallSession(callSession ) {
10343
10427
  const sipSession = this.findSipSession(callSession);
10344
- const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10428
+
10429
+ return sipSession ? this.getSipSessionId(sipSession) : null;
10430
+ }
10431
+
10432
+ _updateCallSession(callSession ) {
10433
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
10345
10434
 
10346
10435
  if (sipSessionId) {
10347
10436
  this.callSessions[sipSessionId] = callSession;
@@ -2226,6 +2226,7 @@ var authMethods = (client , baseUrl ) => ({
2226
2226
 
2227
2227
 
2228
2228
 
2229
+
2229
2230
  ) {
2230
2231
  const body = {
2231
2232
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2245,6 +2246,10 @@ var authMethods = (client , baseUrl ) => ({
2245
2246
  headers['Wazo-Session-Type'] = 'mobile';
2246
2247
  }
2247
2248
 
2249
+ if (params.tenantId) {
2250
+ body.tenant_id = params.tenantId;
2251
+ }
2252
+
2248
2253
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2249
2254
  },
2250
2255
 
@@ -3601,6 +3606,14 @@ class CallSession {
3601
3606
  return !!this.answerTime;
3602
3607
  }
3603
3608
 
3609
+ toJSON() {
3610
+ const jsonObj = { ...this };
3611
+ // $FlowFixMe
3612
+ jsonObj.answered = this.answered;
3613
+
3614
+ return jsonObj;
3615
+ }
3616
+
3604
3617
  static parseCall(call ) {
3605
3618
  return new CallSession({
3606
3619
  callId: call.id,
@@ -3711,11 +3724,13 @@ class Recording {
3711
3724
 
3712
3725
 
3713
3726
 
3727
+
3714
3728
 
3715
3729
 
3716
3730
 
3717
3731
 
3718
3732
 
3733
+
3719
3734
 
3720
3735
 
3721
3736
 
@@ -3736,10 +3751,12 @@ class Recording {
3736
3751
 
3737
3752
 
3738
3753
 
3754
+
3739
3755
 
3740
3756
 
3741
3757
 
3742
3758
 
3759
+
3743
3760
 
3744
3761
 
3745
3762
 
@@ -3801,10 +3818,12 @@ class CallLog {
3801
3818
  || plain.destination_extension
3802
3819
  || `meeting-${plain.requested_name || plain.destination_name || ''}`,
3803
3820
  name: plain.requested_name || plain.destination_name || '',
3821
+ uuid: plain.destination_user_uuid,
3804
3822
  },
3805
3823
  source: {
3806
3824
  extension: plain.source_extension,
3807
3825
  name: plain.source_name,
3826
+ uuid: plain.source_user_uuid,
3808
3827
  },
3809
3828
  id: plain.id,
3810
3829
  duration: (plain.duration || 0) * 1000, // duration is in seconds
@@ -4852,6 +4871,34 @@ var chatdMethods = (client , baseUrl ) => ({
4852
4871
  client.get(`${baseUrl}/users/me/rooms/messages`, options),
4853
4872
  });
4854
4873
 
4874
+ //
4875
+
4876
+
4877
+
4878
+
4879
+
4880
+ class MeetingStatus {
4881
+
4882
+
4883
+
4884
+
4885
+ constructor({
4886
+ full,
4887
+ } = {}) {
4888
+ this.full = full;
4889
+
4890
+ // Useful to compare instead of instanceof with minified code
4891
+ this.type = 'MeetingStatus';
4892
+ }
4893
+
4894
+ static parse(plain ) {
4895
+ return new MeetingStatus({
4896
+ full: plain.full,
4897
+ });
4898
+ }
4899
+
4900
+ }
4901
+
4855
4902
  /* */
4856
4903
 
4857
4904
 
@@ -5046,6 +5093,8 @@ var calldMethods = (client , baseUrl ) => ({
5046
5093
  client.put(`${baseUrl}/users/me/calls/${callId}/record/resume`, null, null,
5047
5094
  ApiRequester.successResponseParser),
5048
5095
 
5096
+ guestGetMeetingStatus: (meetingUuid ) =>
5097
+ client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}/status`).then(MeetingStatus.parse),
5049
5098
  });
5050
5099
 
5051
5100
  //
@@ -6635,7 +6684,7 @@ const events$1 = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
6635
6684
  const transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
6636
6685
  class CanceledCallError extends Error {}
6637
6686
 
6638
- const MAX_REGISTER_TRIES = 10;
6687
+ const MAX_REGISTER_TRIES = 5;
6639
6688
 
6640
6689
 
6641
6690
 
@@ -6689,6 +6738,7 @@ class WebRTCClient extends Emitter {
6689
6738
 
6690
6739
 
6691
6740
 
6741
+
6692
6742
 
6693
6743
  // sugar
6694
6744
 
@@ -6751,6 +6801,7 @@ class WebRTCClient extends Emitter {
6751
6801
  this.conferences = {};
6752
6802
  this.networkMonitoringInterval = {};
6753
6803
  this.sessionNetworkStats = {};
6804
+ this.forceClosed = false;
6754
6805
 
6755
6806
  this._boundOnHeartbeat = this._onHeartbeat.bind(this);
6756
6807
  this.heartbeat = new Heartbeat(config.heartbeatDelay, config.heartbeatTimeout, config.maxHeartbeats);
@@ -6872,6 +6923,8 @@ class WebRTCClient extends Emitter {
6872
6923
  skipRegister: this.skipRegister,
6873
6924
  };
6874
6925
 
6926
+ this.forceClosed = false;
6927
+
6875
6928
  if (this.skipRegister) {
6876
6929
  logger$8.info('sdk webrtc skip register...', logInfo);
6877
6930
  return Promise.resolve();
@@ -6896,7 +6949,15 @@ class WebRTCClient extends Emitter {
6896
6949
  const registerOptions = this._isWeb() ? {} : { extraContactHeaderParams: ['mobility=mobile'] };
6897
6950
 
6898
6951
  const onRegisterFailed = () => {
6899
- logger$8.info('sdk webrtc registering failed', { tries, registerer: !!this.registerer });
6952
+ logger$8.info('sdk webrtc registering failed', {
6953
+ tries,
6954
+ registerer: !!this.registerer,
6955
+ forceClosed: this.forceClosed,
6956
+ });
6957
+ if (this.forceClosed) {
6958
+ return;
6959
+ }
6960
+
6900
6961
  this.connectionPromise = null;
6901
6962
  if (this.registerer && this.registerer.waiting) {
6902
6963
  this.registerer.waitingToggle(false);
@@ -7174,8 +7235,9 @@ class WebRTCClient extends Emitter {
7174
7235
  }
7175
7236
  }
7176
7237
 
7177
- async close() {
7178
- logger$8.info('sdk webrtc closing client', { userAgent: !!this.userAgent });
7238
+ async close(force = false) {
7239
+ logger$8.info('sdk webrtc closing client', { userAgent: !!this.userAgent, force });
7240
+ this.forceClosed = force;
7179
7241
  this._cleanupMedia();
7180
7242
  this.connectionPromise = null;
7181
7243
 
@@ -7194,7 +7256,7 @@ class WebRTCClient extends Emitter {
7194
7256
  this.userAgent.delegate = null;
7195
7257
  this.userAgent.stateChange.removeAllListeners();
7196
7258
 
7197
- await this._disconnectTransport();
7259
+ await this._disconnectTransport(force);
7198
7260
 
7199
7261
  this._cleanupRegister();
7200
7262
 
@@ -8630,7 +8692,15 @@ class WebRTCClient extends Emitter {
8630
8692
  return userAgent.UserAgent.makeURI(`sip:${target}@${this.config.host}`);
8631
8693
  }
8632
8694
 
8633
- async _disconnectTransport() {
8695
+ async _disconnectTransport(force = false) {
8696
+ if (force) {
8697
+ // Bypass sip.js state machine that prevent to close WS with the state `Connecting`
8698
+ this.userAgent.transport.disconnectResolve = () => {};
8699
+ // eslint-disable-next-line
8700
+ this.userAgent.transport._ws.close(1000);
8701
+ return;
8702
+ }
8703
+
8634
8704
  // Check if `disconnectPromise` is not present to avoid `Disconnect promise must not be defined` errors.
8635
8705
  if (this.userAgent && this.userAgent.transport && !this.userAgent.transport.disconnectPromise) {
8636
8706
  try {
@@ -9577,6 +9647,12 @@ class WebRTCPhone extends Emitter {
9577
9647
  return Promise.resolve(null);
9578
9648
  }
9579
9649
 
9650
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
9651
+ if (sipSessionId && !(sipSessionId in this.callSessions)) {
9652
+ logger$7.warn('Call session already ended or not found, can\'t accept it.', { sipSessionId });
9653
+ return Promise.resolve(null);
9654
+ }
9655
+
9580
9656
  if (callSession.getId() in this.acceptedSessions) {
9581
9657
  logger$7.warn('CallSession already accepted.', { id: callSession ? callSession.getId() : 'n/a' });
9582
9658
  return Promise.resolve(callSession.sipCallId);
@@ -10037,7 +10113,7 @@ class WebRTCPhone extends Emitter {
10037
10113
  return this.client && this.client.isConference(callSession.sipCallId);
10038
10114
  }
10039
10115
 
10040
- async close() {
10116
+ async close(force = false) {
10041
10117
  logger$7.info('WebRTC close');
10042
10118
 
10043
10119
  try {
@@ -10049,7 +10125,7 @@ class WebRTCPhone extends Emitter {
10049
10125
  logger$7.error('WebRTC close, unregister error', e);
10050
10126
  }
10051
10127
 
10052
- this.client.close();
10128
+ this.client.close(force);
10053
10129
  this.unbind();
10054
10130
 
10055
10131
  this.incomingSessions = [];
@@ -10201,9 +10277,17 @@ class WebRTCPhone extends Emitter {
10201
10277
  });
10202
10278
 
10203
10279
  this.client.on(this.client.ACCEPTED, (sipSession ) => {
10204
- logger$7.info('WebRTC call accepted', { sipId: sipSession.id });
10280
+ const sessionId = this.getSipSessionId(sipSession);
10281
+ const hasSession = sessionId in this.callSessions;
10282
+
10283
+ logger$7.info('WebRTC call accepted', { sipId: sessionId, hasSession });
10284
+
10285
+ if (!hasSession) {
10286
+ logger$7.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', { sessionId });
10287
+ return;
10288
+ }
10205
10289
 
10206
- this._onCallAccepted(sipSession, this.client.hasVideo(this.getSipSessionId(sipSession)));
10290
+ this._onCallAccepted(sipSession, this.client.hasVideo(sessionId));
10207
10291
 
10208
10292
  if (this.audioOutputDeviceId) {
10209
10293
  this.client.changeAudioOutputDevice(this.audioOutputDeviceId);
@@ -10339,9 +10423,14 @@ class WebRTCPhone extends Emitter {
10339
10423
  return this.client.getSipSessionId(sipSession);
10340
10424
  }
10341
10425
 
10342
- _updateCallSession(callSession ) {
10426
+ getSipSessionIdFromCallSession(callSession ) {
10343
10427
  const sipSession = this.findSipSession(callSession);
10344
- const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10428
+
10429
+ return sipSession ? this.getSipSessionId(sipSession) : null;
10430
+ }
10431
+
10432
+ _updateCallSession(callSession ) {
10433
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
10345
10434
 
10346
10435
  if (sipSessionId) {
10347
10436
  this.callSessions[sipSessionId] = callSession;