@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
  //
@@ -6371,7 +6420,7 @@ const events$1 = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
6371
6420
  const transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
6372
6421
  class CanceledCallError extends Error {}
6373
6422
 
6374
- const MAX_REGISTER_TRIES = 10;
6423
+ const MAX_REGISTER_TRIES = 5;
6375
6424
 
6376
6425
 
6377
6426
 
@@ -6425,6 +6474,7 @@ class WebRTCClient extends Emitter {
6425
6474
 
6426
6475
 
6427
6476
 
6477
+
6428
6478
 
6429
6479
  // sugar
6430
6480
 
@@ -6487,6 +6537,7 @@ class WebRTCClient extends Emitter {
6487
6537
  this.conferences = {};
6488
6538
  this.networkMonitoringInterval = {};
6489
6539
  this.sessionNetworkStats = {};
6540
+ this.forceClosed = false;
6490
6541
 
6491
6542
  this._boundOnHeartbeat = this._onHeartbeat.bind(this);
6492
6543
  this.heartbeat = new Heartbeat(config.heartbeatDelay, config.heartbeatTimeout, config.maxHeartbeats);
@@ -6608,6 +6659,8 @@ class WebRTCClient extends Emitter {
6608
6659
  skipRegister: this.skipRegister,
6609
6660
  };
6610
6661
 
6662
+ this.forceClosed = false;
6663
+
6611
6664
  if (this.skipRegister) {
6612
6665
  logger$9.info('sdk webrtc skip register...', logInfo);
6613
6666
  return Promise.resolve();
@@ -6632,7 +6685,15 @@ class WebRTCClient extends Emitter {
6632
6685
  const registerOptions = this._isWeb() ? {} : { extraContactHeaderParams: ['mobility=mobile'] };
6633
6686
 
6634
6687
  const onRegisterFailed = () => {
6635
- logger$9.info('sdk webrtc registering failed', { tries, registerer: !!this.registerer });
6688
+ logger$9.info('sdk webrtc registering failed', {
6689
+ tries,
6690
+ registerer: !!this.registerer,
6691
+ forceClosed: this.forceClosed,
6692
+ });
6693
+ if (this.forceClosed) {
6694
+ return;
6695
+ }
6696
+
6636
6697
  this.connectionPromise = null;
6637
6698
  if (this.registerer && this.registerer.waiting) {
6638
6699
  this.registerer.waitingToggle(false);
@@ -6910,8 +6971,9 @@ class WebRTCClient extends Emitter {
6910
6971
  }
6911
6972
  }
6912
6973
 
6913
- async close() {
6914
- logger$9.info('sdk webrtc closing client', { userAgent: !!this.userAgent });
6974
+ async close(force = false) {
6975
+ logger$9.info('sdk webrtc closing client', { userAgent: !!this.userAgent, force });
6976
+ this.forceClosed = force;
6915
6977
  this._cleanupMedia();
6916
6978
  this.connectionPromise = null;
6917
6979
 
@@ -6930,7 +6992,7 @@ class WebRTCClient extends Emitter {
6930
6992
  this.userAgent.delegate = null;
6931
6993
  this.userAgent.stateChange.removeAllListeners();
6932
6994
 
6933
- await this._disconnectTransport();
6995
+ await this._disconnectTransport(force);
6934
6996
 
6935
6997
  this._cleanupRegister();
6936
6998
 
@@ -8366,7 +8428,15 @@ class WebRTCClient extends Emitter {
8366
8428
  return userAgent.UserAgent.makeURI(`sip:${target}@${this.config.host}`);
8367
8429
  }
8368
8430
 
8369
- async _disconnectTransport() {
8431
+ async _disconnectTransport(force = false) {
8432
+ if (force) {
8433
+ // Bypass sip.js state machine that prevent to close WS with the state `Connecting`
8434
+ this.userAgent.transport.disconnectResolve = () => {};
8435
+ // eslint-disable-next-line
8436
+ this.userAgent.transport._ws.close(1000);
8437
+ return;
8438
+ }
8439
+
8370
8440
  // Check if `disconnectPromise` is not present to avoid `Disconnect promise must not be defined` errors.
8371
8441
  if (this.userAgent && this.userAgent.transport && !this.userAgent.transport.disconnectPromise) {
8372
8442
  try {
@@ -9313,6 +9383,12 @@ class WebRTCPhone extends Emitter {
9313
9383
  return Promise.resolve(null);
9314
9384
  }
9315
9385
 
9386
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
9387
+ if (sipSessionId && !(sipSessionId in this.callSessions)) {
9388
+ logger$8.warn('Call session already ended or not found, can\'t accept it.', { sipSessionId });
9389
+ return Promise.resolve(null);
9390
+ }
9391
+
9316
9392
  if (callSession.getId() in this.acceptedSessions) {
9317
9393
  logger$8.warn('CallSession already accepted.', { id: callSession ? callSession.getId() : 'n/a' });
9318
9394
  return Promise.resolve(callSession.sipCallId);
@@ -9773,7 +9849,7 @@ class WebRTCPhone extends Emitter {
9773
9849
  return this.client && this.client.isConference(callSession.sipCallId);
9774
9850
  }
9775
9851
 
9776
- async close() {
9852
+ async close(force = false) {
9777
9853
  logger$8.info('WebRTC close');
9778
9854
 
9779
9855
  try {
@@ -9785,7 +9861,7 @@ class WebRTCPhone extends Emitter {
9785
9861
  logger$8.error('WebRTC close, unregister error', e);
9786
9862
  }
9787
9863
 
9788
- this.client.close();
9864
+ this.client.close(force);
9789
9865
  this.unbind();
9790
9866
 
9791
9867
  this.incomingSessions = [];
@@ -9937,9 +10013,17 @@ class WebRTCPhone extends Emitter {
9937
10013
  });
9938
10014
 
9939
10015
  this.client.on(this.client.ACCEPTED, (sipSession ) => {
9940
- logger$8.info('WebRTC call accepted', { sipId: sipSession.id });
10016
+ const sessionId = this.getSipSessionId(sipSession);
10017
+ const hasSession = sessionId in this.callSessions;
10018
+
10019
+ logger$8.info('WebRTC call accepted', { sipId: sessionId, hasSession });
10020
+
10021
+ if (!hasSession) {
10022
+ logger$8.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', { sessionId });
10023
+ return;
10024
+ }
9941
10025
 
9942
- this._onCallAccepted(sipSession, this.client.hasVideo(this.getSipSessionId(sipSession)));
10026
+ this._onCallAccepted(sipSession, this.client.hasVideo(sessionId));
9943
10027
 
9944
10028
  if (this.audioOutputDeviceId) {
9945
10029
  this.client.changeAudioOutputDevice(this.audioOutputDeviceId);
@@ -10075,9 +10159,14 @@ class WebRTCPhone extends Emitter {
10075
10159
  return this.client.getSipSessionId(sipSession);
10076
10160
  }
10077
10161
 
10078
- _updateCallSession(callSession ) {
10162
+ getSipSessionIdFromCallSession(callSession ) {
10079
10163
  const sipSession = this.findSipSession(callSession);
10080
- const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10164
+
10165
+ return sipSession ? this.getSipSessionId(sipSession) : null;
10166
+ }
10167
+
10168
+ _updateCallSession(callSession ) {
10169
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
10081
10170
 
10082
10171
  if (sipSessionId) {
10083
10172
  this.callSessions[sipSessionId] = callSession;
@@ -2203,6 +2203,7 @@ var authMethods = (client , baseUrl ) => ({
2203
2203
 
2204
2204
 
2205
2205
 
2206
+
2206
2207
  ) {
2207
2208
  const body = {
2208
2209
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2222,6 +2223,10 @@ var authMethods = (client , baseUrl ) => ({
2222
2223
  headers['Wazo-Session-Type'] = 'mobile';
2223
2224
  }
2224
2225
 
2226
+ if (params.tenantId) {
2227
+ body.tenant_id = params.tenantId;
2228
+ }
2229
+
2225
2230
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2226
2231
  },
2227
2232
 
@@ -3290,11 +3295,13 @@ class Recording {
3290
3295
 
3291
3296
 
3292
3297
 
3298
+
3293
3299
 
3294
3300
 
3295
3301
 
3296
3302
 
3297
3303
 
3304
+
3298
3305
 
3299
3306
 
3300
3307
 
@@ -3315,10 +3322,12 @@ class Recording {
3315
3322
 
3316
3323
 
3317
3324
 
3325
+
3318
3326
 
3319
3327
 
3320
3328
 
3321
3329
 
3330
+
3322
3331
 
3323
3332
 
3324
3333
 
@@ -3380,10 +3389,12 @@ class CallLog {
3380
3389
  || plain.destination_extension
3381
3390
  || `meeting-${plain.requested_name || plain.destination_name || ''}`,
3382
3391
  name: plain.requested_name || plain.destination_name || '',
3392
+ uuid: plain.destination_user_uuid,
3383
3393
  },
3384
3394
  source: {
3385
3395
  extension: plain.source_extension,
3386
3396
  name: plain.source_name,
3397
+ uuid: plain.source_user_uuid,
3387
3398
  },
3388
3399
  id: plain.id,
3389
3400
  duration: (plain.duration || 0) * 1000, // duration is in seconds
@@ -4022,6 +4033,34 @@ var chatdMethods = (client , baseUrl ) => ({
4022
4033
  client.get(`${baseUrl}/users/me/rooms/messages`, options),
4023
4034
  });
4024
4035
 
4036
+ //
4037
+
4038
+
4039
+
4040
+
4041
+
4042
+ class MeetingStatus {
4043
+
4044
+
4045
+
4046
+
4047
+ constructor({
4048
+ full,
4049
+ } = {}) {
4050
+ this.full = full;
4051
+
4052
+ // Useful to compare instead of instanceof with minified code
4053
+ this.type = 'MeetingStatus';
4054
+ }
4055
+
4056
+ static parse(plain ) {
4057
+ return new MeetingStatus({
4058
+ full: plain.full,
4059
+ });
4060
+ }
4061
+
4062
+ }
4063
+
4025
4064
  /* */
4026
4065
 
4027
4066
 
@@ -4216,6 +4255,8 @@ var calldMethods = (client , baseUrl ) => ({
4216
4255
  client.put(`${baseUrl}/users/me/calls/${callId}/record/resume`, null, null,
4217
4256
  ApiRequester.successResponseParser),
4218
4257
 
4258
+ guestGetMeetingStatus: (meetingUuid ) =>
4259
+ client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}/status`).then(MeetingStatus.parse),
4219
4260
  });
4220
4261
 
4221
4262
  //
@@ -601,6 +601,14 @@ class CallSession {
601
601
  return !!this.answerTime;
602
602
  }
603
603
 
604
+ toJSON() {
605
+ const jsonObj = { ...this };
606
+ // $FlowFixMe
607
+ jsonObj.answered = this.answered;
608
+
609
+ return jsonObj;
610
+ }
611
+
604
612
  static parseCall(call ) {
605
613
  return new CallSession({
606
614
  callId: call.id,
@@ -2807,6 +2815,7 @@ var authMethods = (client , baseUrl ) => ({
2807
2815
 
2808
2816
 
2809
2817
 
2818
+
2810
2819
  ) {
2811
2820
  const body = {
2812
2821
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2826,6 +2835,10 @@ var authMethods = (client , baseUrl ) => ({
2826
2835
  headers['Wazo-Session-Type'] = 'mobile';
2827
2836
  }
2828
2837
 
2838
+ if (params.tenantId) {
2839
+ body.tenant_id = params.tenantId;
2840
+ }
2841
+
2829
2842
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2830
2843
  },
2831
2844
 
@@ -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
  //
@@ -6371,7 +6420,7 @@ const events$1 = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
6371
6420
  const transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
6372
6421
  class CanceledCallError extends Error {}
6373
6422
 
6374
- const MAX_REGISTER_TRIES = 10;
6423
+ const MAX_REGISTER_TRIES = 5;
6375
6424
 
6376
6425
 
6377
6426
 
@@ -6425,6 +6474,7 @@ class WebRTCClient extends Emitter {
6425
6474
 
6426
6475
 
6427
6476
 
6477
+
6428
6478
 
6429
6479
  // sugar
6430
6480
 
@@ -6487,6 +6537,7 @@ class WebRTCClient extends Emitter {
6487
6537
  this.conferences = {};
6488
6538
  this.networkMonitoringInterval = {};
6489
6539
  this.sessionNetworkStats = {};
6540
+ this.forceClosed = false;
6490
6541
 
6491
6542
  this._boundOnHeartbeat = this._onHeartbeat.bind(this);
6492
6543
  this.heartbeat = new Heartbeat(config.heartbeatDelay, config.heartbeatTimeout, config.maxHeartbeats);
@@ -6608,6 +6659,8 @@ class WebRTCClient extends Emitter {
6608
6659
  skipRegister: this.skipRegister,
6609
6660
  };
6610
6661
 
6662
+ this.forceClosed = false;
6663
+
6611
6664
  if (this.skipRegister) {
6612
6665
  logger$9.info('sdk webrtc skip register...', logInfo);
6613
6666
  return Promise.resolve();
@@ -6632,7 +6685,15 @@ class WebRTCClient extends Emitter {
6632
6685
  const registerOptions = this._isWeb() ? {} : { extraContactHeaderParams: ['mobility=mobile'] };
6633
6686
 
6634
6687
  const onRegisterFailed = () => {
6635
- logger$9.info('sdk webrtc registering failed', { tries, registerer: !!this.registerer });
6688
+ logger$9.info('sdk webrtc registering failed', {
6689
+ tries,
6690
+ registerer: !!this.registerer,
6691
+ forceClosed: this.forceClosed,
6692
+ });
6693
+ if (this.forceClosed) {
6694
+ return;
6695
+ }
6696
+
6636
6697
  this.connectionPromise = null;
6637
6698
  if (this.registerer && this.registerer.waiting) {
6638
6699
  this.registerer.waitingToggle(false);
@@ -6910,8 +6971,9 @@ class WebRTCClient extends Emitter {
6910
6971
  }
6911
6972
  }
6912
6973
 
6913
- async close() {
6914
- logger$9.info('sdk webrtc closing client', { userAgent: !!this.userAgent });
6974
+ async close(force = false) {
6975
+ logger$9.info('sdk webrtc closing client', { userAgent: !!this.userAgent, force });
6976
+ this.forceClosed = force;
6915
6977
  this._cleanupMedia();
6916
6978
  this.connectionPromise = null;
6917
6979
 
@@ -6930,7 +6992,7 @@ class WebRTCClient extends Emitter {
6930
6992
  this.userAgent.delegate = null;
6931
6993
  this.userAgent.stateChange.removeAllListeners();
6932
6994
 
6933
- await this._disconnectTransport();
6995
+ await this._disconnectTransport(force);
6934
6996
 
6935
6997
  this._cleanupRegister();
6936
6998
 
@@ -8366,7 +8428,15 @@ class WebRTCClient extends Emitter {
8366
8428
  return userAgent.UserAgent.makeURI(`sip:${target}@${this.config.host}`);
8367
8429
  }
8368
8430
 
8369
- async _disconnectTransport() {
8431
+ async _disconnectTransport(force = false) {
8432
+ if (force) {
8433
+ // Bypass sip.js state machine that prevent to close WS with the state `Connecting`
8434
+ this.userAgent.transport.disconnectResolve = () => {};
8435
+ // eslint-disable-next-line
8436
+ this.userAgent.transport._ws.close(1000);
8437
+ return;
8438
+ }
8439
+
8370
8440
  // Check if `disconnectPromise` is not present to avoid `Disconnect promise must not be defined` errors.
8371
8441
  if (this.userAgent && this.userAgent.transport && !this.userAgent.transport.disconnectPromise) {
8372
8442
  try {
@@ -9313,6 +9383,12 @@ class WebRTCPhone extends Emitter {
9313
9383
  return Promise.resolve(null);
9314
9384
  }
9315
9385
 
9386
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
9387
+ if (sipSessionId && !(sipSessionId in this.callSessions)) {
9388
+ logger$8.warn('Call session already ended or not found, can\'t accept it.', { sipSessionId });
9389
+ return Promise.resolve(null);
9390
+ }
9391
+
9316
9392
  if (callSession.getId() in this.acceptedSessions) {
9317
9393
  logger$8.warn('CallSession already accepted.', { id: callSession ? callSession.getId() : 'n/a' });
9318
9394
  return Promise.resolve(callSession.sipCallId);
@@ -9773,7 +9849,7 @@ class WebRTCPhone extends Emitter {
9773
9849
  return this.client && this.client.isConference(callSession.sipCallId);
9774
9850
  }
9775
9851
 
9776
- async close() {
9852
+ async close(force = false) {
9777
9853
  logger$8.info('WebRTC close');
9778
9854
 
9779
9855
  try {
@@ -9785,7 +9861,7 @@ class WebRTCPhone extends Emitter {
9785
9861
  logger$8.error('WebRTC close, unregister error', e);
9786
9862
  }
9787
9863
 
9788
- this.client.close();
9864
+ this.client.close(force);
9789
9865
  this.unbind();
9790
9866
 
9791
9867
  this.incomingSessions = [];
@@ -9937,9 +10013,17 @@ class WebRTCPhone extends Emitter {
9937
10013
  });
9938
10014
 
9939
10015
  this.client.on(this.client.ACCEPTED, (sipSession ) => {
9940
- logger$8.info('WebRTC call accepted', { sipId: sipSession.id });
10016
+ const sessionId = this.getSipSessionId(sipSession);
10017
+ const hasSession = sessionId in this.callSessions;
10018
+
10019
+ logger$8.info('WebRTC call accepted', { sipId: sessionId, hasSession });
10020
+
10021
+ if (!hasSession) {
10022
+ logger$8.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', { sessionId });
10023
+ return;
10024
+ }
9941
10025
 
9942
- this._onCallAccepted(sipSession, this.client.hasVideo(this.getSipSessionId(sipSession)));
10026
+ this._onCallAccepted(sipSession, this.client.hasVideo(sessionId));
9943
10027
 
9944
10028
  if (this.audioOutputDeviceId) {
9945
10029
  this.client.changeAudioOutputDevice(this.audioOutputDeviceId);
@@ -10075,9 +10159,14 @@ class WebRTCPhone extends Emitter {
10075
10159
  return this.client.getSipSessionId(sipSession);
10076
10160
  }
10077
10161
 
10078
- _updateCallSession(callSession ) {
10162
+ getSipSessionIdFromCallSession(callSession ) {
10079
10163
  const sipSession = this.findSipSession(callSession);
10080
- const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10164
+
10165
+ return sipSession ? this.getSipSessionId(sipSession) : null;
10166
+ }
10167
+
10168
+ _updateCallSession(callSession ) {
10169
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
10081
10170
 
10082
10171
  if (sipSessionId) {
10083
10172
  this.callSessions[sipSessionId] = callSession;