@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
@@ -1751,11 +1751,13 @@ class Recording {
1751
1751
 
1752
1752
 
1753
1753
 
1754
+
1754
1755
 
1755
1756
 
1756
1757
 
1757
1758
 
1758
1759
 
1760
+
1759
1761
 
1760
1762
 
1761
1763
 
@@ -1776,10 +1778,12 @@ class Recording {
1776
1778
 
1777
1779
 
1778
1780
 
1781
+
1779
1782
 
1780
1783
 
1781
1784
 
1782
1785
 
1786
+
1783
1787
 
1784
1788
 
1785
1789
 
@@ -1841,10 +1845,12 @@ class CallLog {
1841
1845
  || plain.destination_extension
1842
1846
  || `meeting-${plain.requested_name || plain.destination_name || ''}`,
1843
1847
  name: plain.requested_name || plain.destination_name || '',
1848
+ uuid: plain.destination_user_uuid,
1844
1849
  },
1845
1850
  source: {
1846
1851
  extension: plain.source_extension,
1847
1852
  name: plain.source_name,
1853
+ uuid: plain.source_user_uuid,
1848
1854
  },
1849
1855
  id: plain.id,
1850
1856
  duration: (plain.duration || 0) * 1000, // duration is in seconds
@@ -2737,6 +2743,7 @@ var authMethods = (client , baseUrl ) => ({
2737
2743
 
2738
2744
 
2739
2745
 
2746
+
2740
2747
  ) {
2741
2748
  const body = {
2742
2749
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2756,6 +2763,10 @@ var authMethods = (client , baseUrl ) => ({
2756
2763
  headers['Wazo-Session-Type'] = 'mobile';
2757
2764
  }
2758
2765
 
2766
+ if (params.tenantId) {
2767
+ body.tenant_id = params.tenantId;
2768
+ }
2769
+
2759
2770
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2760
2771
  },
2761
2772
 
@@ -4022,6 +4033,34 @@ class IndirectTransfer {
4022
4033
  }
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
  //
@@ -2205,6 +2205,7 @@ var authMethods = (client , baseUrl ) => ({
2205
2205
 
2206
2206
 
2207
2207
 
2208
+
2208
2209
  ) {
2209
2210
  const body = {
2210
2211
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2224,6 +2225,10 @@ var authMethods = (client , baseUrl ) => ({
2224
2225
  headers['Wazo-Session-Type'] = 'mobile';
2225
2226
  }
2226
2227
 
2228
+ if (params.tenantId) {
2229
+ body.tenant_id = params.tenantId;
2230
+ }
2231
+
2227
2232
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2228
2233
  },
2229
2234
 
@@ -3292,11 +3297,13 @@ class Recording {
3292
3297
 
3293
3298
 
3294
3299
 
3300
+
3295
3301
 
3296
3302
 
3297
3303
 
3298
3304
 
3299
3305
 
3306
+
3300
3307
 
3301
3308
 
3302
3309
 
@@ -3317,10 +3324,12 @@ class Recording {
3317
3324
 
3318
3325
 
3319
3326
 
3327
+
3320
3328
 
3321
3329
 
3322
3330
 
3323
3331
 
3332
+
3324
3333
 
3325
3334
 
3326
3335
 
@@ -3382,10 +3391,12 @@ class CallLog {
3382
3391
  || plain.destination_extension
3383
3392
  || `meeting-${plain.requested_name || plain.destination_name || ''}`,
3384
3393
  name: plain.requested_name || plain.destination_name || '',
3394
+ uuid: plain.destination_user_uuid,
3385
3395
  },
3386
3396
  source: {
3387
3397
  extension: plain.source_extension,
3388
3398
  name: plain.source_name,
3399
+ uuid: plain.source_user_uuid,
3389
3400
  },
3390
3401
  id: plain.id,
3391
3402
  duration: (plain.duration || 0) * 1000, // duration is in seconds
@@ -4024,6 +4035,34 @@ var chatdMethods = (client , baseUrl ) => ({
4024
4035
  client.get(`${baseUrl}/users/me/rooms/messages`, options),
4025
4036
  });
4026
4037
 
4038
+ //
4039
+
4040
+
4041
+
4042
+
4043
+
4044
+ class MeetingStatus {
4045
+
4046
+
4047
+
4048
+
4049
+ constructor({
4050
+ full,
4051
+ } = {}) {
4052
+ this.full = full;
4053
+
4054
+ // Useful to compare instead of instanceof with minified code
4055
+ this.type = 'MeetingStatus';
4056
+ }
4057
+
4058
+ static parse(plain ) {
4059
+ return new MeetingStatus({
4060
+ full: plain.full,
4061
+ });
4062
+ }
4063
+
4064
+ }
4065
+
4027
4066
  /* */
4028
4067
 
4029
4068
 
@@ -4218,6 +4257,8 @@ var calldMethods = (client , baseUrl ) => ({
4218
4257
  client.put(`${baseUrl}/users/me/calls/${callId}/record/resume`, null, null,
4219
4258
  ApiRequester.successResponseParser),
4220
4259
 
4260
+ guestGetMeetingStatus: (meetingUuid ) =>
4261
+ client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}/status`).then(MeetingStatus.parse),
4221
4262
  });
4222
4263
 
4223
4264
  //
@@ -2228,6 +2228,7 @@ var authMethods = (client , baseUrl ) => ({
2228
2228
 
2229
2229
 
2230
2230
 
2231
+
2231
2232
  ) {
2232
2233
  const body = {
2233
2234
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2247,6 +2248,10 @@ var authMethods = (client , baseUrl ) => ({
2247
2248
  headers['Wazo-Session-Type'] = 'mobile';
2248
2249
  }
2249
2250
 
2251
+ if (params.tenantId) {
2252
+ body.tenant_id = params.tenantId;
2253
+ }
2254
+
2250
2255
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2251
2256
  },
2252
2257
 
@@ -3603,6 +3608,14 @@ class CallSession {
3603
3608
  return !!this.answerTime;
3604
3609
  }
3605
3610
 
3611
+ toJSON() {
3612
+ const jsonObj = { ...this };
3613
+ // $FlowFixMe
3614
+ jsonObj.answered = this.answered;
3615
+
3616
+ return jsonObj;
3617
+ }
3618
+
3606
3619
  static parseCall(call ) {
3607
3620
  return new CallSession({
3608
3621
  callId: call.id,
@@ -3713,11 +3726,13 @@ class Recording {
3713
3726
 
3714
3727
 
3715
3728
 
3729
+
3716
3730
 
3717
3731
 
3718
3732
 
3719
3733
 
3720
3734
 
3735
+
3721
3736
 
3722
3737
 
3723
3738
 
@@ -3738,10 +3753,12 @@ class Recording {
3738
3753
 
3739
3754
 
3740
3755
 
3756
+
3741
3757
 
3742
3758
 
3743
3759
 
3744
3760
 
3761
+
3745
3762
 
3746
3763
 
3747
3764
 
@@ -3803,10 +3820,12 @@ class CallLog {
3803
3820
  || plain.destination_extension
3804
3821
  || `meeting-${plain.requested_name || plain.destination_name || ''}`,
3805
3822
  name: plain.requested_name || plain.destination_name || '',
3823
+ uuid: plain.destination_user_uuid,
3806
3824
  },
3807
3825
  source: {
3808
3826
  extension: plain.source_extension,
3809
3827
  name: plain.source_name,
3828
+ uuid: plain.source_user_uuid,
3810
3829
  },
3811
3830
  id: plain.id,
3812
3831
  duration: (plain.duration || 0) * 1000, // duration is in seconds
@@ -4854,6 +4873,34 @@ var chatdMethods = (client , baseUrl ) => ({
4854
4873
  client.get(`${baseUrl}/users/me/rooms/messages`, options),
4855
4874
  });
4856
4875
 
4876
+ //
4877
+
4878
+
4879
+
4880
+
4881
+
4882
+ class MeetingStatus {
4883
+
4884
+
4885
+
4886
+
4887
+ constructor({
4888
+ full,
4889
+ } = {}) {
4890
+ this.full = full;
4891
+
4892
+ // Useful to compare instead of instanceof with minified code
4893
+ this.type = 'MeetingStatus';
4894
+ }
4895
+
4896
+ static parse(plain ) {
4897
+ return new MeetingStatus({
4898
+ full: plain.full,
4899
+ });
4900
+ }
4901
+
4902
+ }
4903
+
4857
4904
  /* */
4858
4905
 
4859
4906
 
@@ -5048,6 +5095,8 @@ var calldMethods = (client , baseUrl ) => ({
5048
5095
  client.put(`${baseUrl}/users/me/calls/${callId}/record/resume`, null, null,
5049
5096
  ApiRequester.successResponseParser),
5050
5097
 
5098
+ guestGetMeetingStatus: (meetingUuid ) =>
5099
+ client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}/status`).then(MeetingStatus.parse),
5051
5100
  });
5052
5101
 
5053
5102
  //
@@ -6373,7 +6422,7 @@ const events$1 = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
6373
6422
  const transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
6374
6423
  class CanceledCallError extends Error {}
6375
6424
 
6376
- const MAX_REGISTER_TRIES = 10;
6425
+ const MAX_REGISTER_TRIES = 5;
6377
6426
 
6378
6427
 
6379
6428
 
@@ -6427,6 +6476,7 @@ class WebRTCClient extends Emitter {
6427
6476
 
6428
6477
 
6429
6478
 
6479
+
6430
6480
 
6431
6481
  // sugar
6432
6482
 
@@ -6489,6 +6539,7 @@ class WebRTCClient extends Emitter {
6489
6539
  this.conferences = {};
6490
6540
  this.networkMonitoringInterval = {};
6491
6541
  this.sessionNetworkStats = {};
6542
+ this.forceClosed = false;
6492
6543
 
6493
6544
  this._boundOnHeartbeat = this._onHeartbeat.bind(this);
6494
6545
  this.heartbeat = new Heartbeat(config.heartbeatDelay, config.heartbeatTimeout, config.maxHeartbeats);
@@ -6610,6 +6661,8 @@ class WebRTCClient extends Emitter {
6610
6661
  skipRegister: this.skipRegister,
6611
6662
  };
6612
6663
 
6664
+ this.forceClosed = false;
6665
+
6613
6666
  if (this.skipRegister) {
6614
6667
  logger$9.info('sdk webrtc skip register...', logInfo);
6615
6668
  return Promise.resolve();
@@ -6634,7 +6687,15 @@ class WebRTCClient extends Emitter {
6634
6687
  const registerOptions = this._isWeb() ? {} : { extraContactHeaderParams: ['mobility=mobile'] };
6635
6688
 
6636
6689
  const onRegisterFailed = () => {
6637
- logger$9.info('sdk webrtc registering failed', { tries, registerer: !!this.registerer });
6690
+ logger$9.info('sdk webrtc registering failed', {
6691
+ tries,
6692
+ registerer: !!this.registerer,
6693
+ forceClosed: this.forceClosed,
6694
+ });
6695
+ if (this.forceClosed) {
6696
+ return;
6697
+ }
6698
+
6638
6699
  this.connectionPromise = null;
6639
6700
  if (this.registerer && this.registerer.waiting) {
6640
6701
  this.registerer.waitingToggle(false);
@@ -6912,8 +6973,9 @@ class WebRTCClient extends Emitter {
6912
6973
  }
6913
6974
  }
6914
6975
 
6915
- async close() {
6916
- logger$9.info('sdk webrtc closing client', { userAgent: !!this.userAgent });
6976
+ async close(force = false) {
6977
+ logger$9.info('sdk webrtc closing client', { userAgent: !!this.userAgent, force });
6978
+ this.forceClosed = force;
6917
6979
  this._cleanupMedia();
6918
6980
  this.connectionPromise = null;
6919
6981
 
@@ -6932,7 +6994,7 @@ class WebRTCClient extends Emitter {
6932
6994
  this.userAgent.delegate = null;
6933
6995
  this.userAgent.stateChange.removeAllListeners();
6934
6996
 
6935
- await this._disconnectTransport();
6997
+ await this._disconnectTransport(force);
6936
6998
 
6937
6999
  this._cleanupRegister();
6938
7000
 
@@ -8368,7 +8430,15 @@ class WebRTCClient extends Emitter {
8368
8430
  return userAgent.UserAgent.makeURI(`sip:${target}@${this.config.host}`);
8369
8431
  }
8370
8432
 
8371
- async _disconnectTransport() {
8433
+ async _disconnectTransport(force = false) {
8434
+ if (force) {
8435
+ // Bypass sip.js state machine that prevent to close WS with the state `Connecting`
8436
+ this.userAgent.transport.disconnectResolve = () => {};
8437
+ // eslint-disable-next-line
8438
+ this.userAgent.transport._ws.close(1000);
8439
+ return;
8440
+ }
8441
+
8372
8442
  // Check if `disconnectPromise` is not present to avoid `Disconnect promise must not be defined` errors.
8373
8443
  if (this.userAgent && this.userAgent.transport && !this.userAgent.transport.disconnectPromise) {
8374
8444
  try {
@@ -9315,6 +9385,12 @@ class WebRTCPhone extends Emitter {
9315
9385
  return Promise.resolve(null);
9316
9386
  }
9317
9387
 
9388
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
9389
+ if (sipSessionId && !(sipSessionId in this.callSessions)) {
9390
+ logger$8.warn('Call session already ended or not found, can\'t accept it.', { sipSessionId });
9391
+ return Promise.resolve(null);
9392
+ }
9393
+
9318
9394
  if (callSession.getId() in this.acceptedSessions) {
9319
9395
  logger$8.warn('CallSession already accepted.', { id: callSession ? callSession.getId() : 'n/a' });
9320
9396
  return Promise.resolve(callSession.sipCallId);
@@ -9775,7 +9851,7 @@ class WebRTCPhone extends Emitter {
9775
9851
  return this.client && this.client.isConference(callSession.sipCallId);
9776
9852
  }
9777
9853
 
9778
- async close() {
9854
+ async close(force = false) {
9779
9855
  logger$8.info('WebRTC close');
9780
9856
 
9781
9857
  try {
@@ -9787,7 +9863,7 @@ class WebRTCPhone extends Emitter {
9787
9863
  logger$8.error('WebRTC close, unregister error', e);
9788
9864
  }
9789
9865
 
9790
- this.client.close();
9866
+ this.client.close(force);
9791
9867
  this.unbind();
9792
9868
 
9793
9869
  this.incomingSessions = [];
@@ -9939,9 +10015,17 @@ class WebRTCPhone extends Emitter {
9939
10015
  });
9940
10016
 
9941
10017
  this.client.on(this.client.ACCEPTED, (sipSession ) => {
9942
- logger$8.info('WebRTC call accepted', { sipId: sipSession.id });
10018
+ const sessionId = this.getSipSessionId(sipSession);
10019
+ const hasSession = sessionId in this.callSessions;
10020
+
10021
+ logger$8.info('WebRTC call accepted', { sipId: sessionId, hasSession });
10022
+
10023
+ if (!hasSession) {
10024
+ logger$8.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', { sessionId });
10025
+ return;
10026
+ }
9943
10027
 
9944
- this._onCallAccepted(sipSession, this.client.hasVideo(this.getSipSessionId(sipSession)));
10028
+ this._onCallAccepted(sipSession, this.client.hasVideo(sessionId));
9945
10029
 
9946
10030
  if (this.audioOutputDeviceId) {
9947
10031
  this.client.changeAudioOutputDevice(this.audioOutputDeviceId);
@@ -10077,9 +10161,14 @@ class WebRTCPhone extends Emitter {
10077
10161
  return this.client.getSipSessionId(sipSession);
10078
10162
  }
10079
10163
 
10080
- _updateCallSession(callSession ) {
10164
+ getSipSessionIdFromCallSession(callSession ) {
10081
10165
  const sipSession = this.findSipSession(callSession);
10082
- const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10166
+
10167
+ return sipSession ? this.getSipSessionId(sipSession) : null;
10168
+ }
10169
+
10170
+ _updateCallSession(callSession ) {
10171
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
10083
10172
 
10084
10173
  if (sipSessionId) {
10085
10174
  this.callSessions[sipSessionId] = callSession;