@wazo/sdk 0.37.33 → 0.37.36

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 (98) hide show
  1. package/README.md +1 -0
  2. package/dist/wazo-sdk.js +2 -2
  3. package/esm/__tests__/api-client.test.js +17 -0
  4. package/esm/__tests__/web-rtc-client.test.js +18 -1
  5. package/esm/api/auth.js +5 -0
  6. package/esm/api/call-logd.js +6 -0
  7. package/esm/api/chatd.js +6 -0
  8. package/esm/api/confd.js +6 -0
  9. package/esm/api-client.js +17 -0
  10. package/esm/checker/Checker.js +18 -1
  11. package/esm/checker/checks/aor.js +17 -0
  12. package/esm/checker/checks/api.js +17 -0
  13. package/esm/checker/checks/index.js +18 -1
  14. package/esm/checker/checks/webrtc-transport.js +18 -1
  15. package/esm/checker/checks/webrtc.js +18 -1
  16. package/esm/domain/AdHocAPIConference.js +21 -0
  17. package/esm/domain/CallLog.js +6 -0
  18. package/esm/domain/CallSession.js +14 -0
  19. package/esm/domain/Features.js +17 -0
  20. package/esm/domain/Phone/CTIPhone.js +31 -0
  21. package/esm/domain/Phone/WebRTCPhone.js +65 -15
  22. package/esm/domain/Profile.js +6 -0
  23. package/esm/domain/__tests__/CallLog.test.js +10 -0
  24. package/esm/domain/__tests__/CallSession.test.js +14 -0
  25. package/esm/domain/__tests__/IndirectTransfer.test.js +14 -0
  26. package/esm/domain/__tests__/Profile.test.js +6 -0
  27. package/esm/domain/__tests__/Room.test.js +14 -0
  28. package/esm/domain/__tests__/Session.test.js +6 -0
  29. package/esm/index.js +93 -22
  30. package/esm/service/CallApi.js +17 -0
  31. package/esm/service/getApiClient.js +17 -0
  32. package/esm/simple/Auth.js +93 -22
  33. package/esm/simple/Configuration.js +93 -22
  34. package/esm/simple/Directory.js +17 -0
  35. package/esm/simple/Phone.js +93 -22
  36. package/esm/simple/index.js +93 -22
  37. package/esm/simple/room/LocalParticipant.js +93 -22
  38. package/esm/simple/room/Participant.js +93 -22
  39. package/esm/simple/room/RemoteParticipant.js +93 -22
  40. package/esm/simple/room/Room.js +93 -22
  41. package/esm/simple/room/SipRoom.js +93 -22
  42. package/esm/simple/room/Stream.js +93 -22
  43. package/esm/simple/room/__tests__/RemoteParticipant.test.js +93 -22
  44. package/esm/simple/utils.js +93 -22
  45. package/esm/web-rtc-client.js +18 -1
  46. package/lib/__tests__/api-client.test.js +17 -0
  47. package/lib/__tests__/web-rtc-client.test.js +18 -1
  48. package/lib/api/auth.js +5 -0
  49. package/lib/api/call-logd.js +6 -0
  50. package/lib/api/chatd.js +6 -0
  51. package/lib/api/confd.js +6 -0
  52. package/lib/api-client.js +17 -0
  53. package/lib/checker/Checker.js +18 -1
  54. package/lib/checker/checks/aor.js +17 -0
  55. package/lib/checker/checks/api.js +17 -0
  56. package/lib/checker/checks/index.js +18 -1
  57. package/lib/checker/checks/webrtc-transport.js +18 -1
  58. package/lib/checker/checks/webrtc.js +18 -1
  59. package/lib/domain/AdHocAPIConference.js +21 -0
  60. package/lib/domain/CallLog.js +6 -0
  61. package/lib/domain/CallSession.js +14 -0
  62. package/lib/domain/Features.js +17 -0
  63. package/lib/domain/Phone/CTIPhone.js +31 -0
  64. package/lib/domain/Phone/WebRTCPhone.js +65 -15
  65. package/lib/domain/Profile.js +6 -0
  66. package/lib/domain/__tests__/CallLog.test.js +10 -0
  67. package/lib/domain/__tests__/CallSession.test.js +14 -0
  68. package/lib/domain/__tests__/IndirectTransfer.test.js +14 -0
  69. package/lib/domain/__tests__/Profile.test.js +6 -0
  70. package/lib/domain/__tests__/Room.test.js +14 -0
  71. package/lib/domain/__tests__/Session.test.js +6 -0
  72. package/lib/index.js +93 -22
  73. package/lib/service/CallApi.js +17 -0
  74. package/lib/service/getApiClient.js +17 -0
  75. package/lib/simple/Auth.js +93 -22
  76. package/lib/simple/Configuration.js +93 -22
  77. package/lib/simple/Directory.js +17 -0
  78. package/lib/simple/Phone.js +93 -22
  79. package/lib/simple/index.js +93 -22
  80. package/lib/simple/room/LocalParticipant.js +93 -22
  81. package/lib/simple/room/Participant.js +93 -22
  82. package/lib/simple/room/RemoteParticipant.js +93 -22
  83. package/lib/simple/room/Room.js +93 -22
  84. package/lib/simple/room/SipRoom.js +93 -22
  85. package/lib/simple/room/Stream.js +93 -22
  86. package/lib/simple/room/__tests__/RemoteParticipant.test.js +93 -22
  87. package/lib/simple/utils.js +93 -22
  88. package/lib/web-rtc-client.js +18 -1
  89. package/package.json +1 -1
  90. package/src/api/auth.js +5 -0
  91. package/src/domain/AdHocAPIConference.js +4 -0
  92. package/src/domain/CallLog.js +6 -0
  93. package/src/domain/CallSession.js +14 -0
  94. package/src/domain/Phone/WebRTCPhone.js +51 -15
  95. package/src/domain/Profile.js +6 -0
  96. package/src/domain/__tests__/CallLog.test.js +4 -0
  97. package/src/simple/Phone.js +6 -6
  98. package/src/web-rtc-client.js +1 -1
@@ -1097,6 +1097,7 @@ const LINE_STATE = {
1097
1097
 
1098
1098
 
1099
1099
 
1100
+
1100
1101
 
1101
1102
 
1102
1103
 
@@ -1133,6 +1134,7 @@ const LINE_STATE = {
1133
1134
 
1134
1135
 
1135
1136
 
1137
+
1136
1138
 
1137
1139
 
1138
1140
 
@@ -1164,6 +1166,7 @@ class Profile {
1164
1166
 
1165
1167
 
1166
1168
 
1169
+
1167
1170
 
1168
1171
 
1169
1172
 
@@ -1180,6 +1183,7 @@ class Profile {
1180
1183
  lines: plain.lines.map(line => Line.parse(line)),
1181
1184
  username: plain.username,
1182
1185
  mobileNumber: plain.mobile_phone_number || '',
1186
+ ringSeconds: plain.ring_seconds,
1183
1187
  forwards: [
1184
1188
  ForwardOption.parse(plain.forwards.unconditional, FORWARD_KEYS.UNCONDITIONAL),
1185
1189
  ForwardOption.parse(plain.forwards.noanswer, FORWARD_KEYS.NO_ANSWER),
@@ -1216,6 +1220,7 @@ class Profile {
1216
1220
  switchboards,
1217
1221
  agent,
1218
1222
  status,
1223
+ ringSeconds,
1219
1224
  sipLines,
1220
1225
  callPickupTargetUsers,
1221
1226
  onlineCallRecordEnabled,
@@ -1237,6 +1242,7 @@ class Profile {
1237
1242
  this.status = status;
1238
1243
  this.callPickupTargetUsers = callPickupTargetUsers;
1239
1244
  this.onlineCallRecordEnabled = onlineCallRecordEnabled;
1245
+ this.ringSeconds = ringSeconds;
1240
1246
 
1241
1247
  this.sipLines = sipLines || [];
1242
1248
  }
@@ -2242,6 +2248,7 @@ var authMethods = (client , baseUrl ) => ({
2242
2248
 
2243
2249
 
2244
2250
 
2251
+
2245
2252
  ) {
2246
2253
  const body = {
2247
2254
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2261,6 +2268,10 @@ var authMethods = (client , baseUrl ) => ({
2261
2268
  headers['Wazo-Session-Type'] = 'mobile';
2262
2269
  }
2263
2270
 
2271
+ if (params.tenantId) {
2272
+ body.tenant_id = params.tenantId;
2273
+ }
2274
+
2264
2275
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2265
2276
  },
2266
2277
 
@@ -3301,6 +3312,7 @@ var updateFrom = (instance , from ) => {
3301
3312
 
3302
3313
 
3303
3314
 
3315
+
3304
3316
 
3305
3317
 
3306
3318
  class CallSession {
@@ -3363,6 +3375,8 @@ class CallSession {
3363
3375
 
3364
3376
 
3365
3377
 
3378
+
3379
+
3366
3380
 
3367
3381
 
3368
3382
 
@@ -3394,6 +3408,7 @@ class CallSession {
3394
3408
  videoRemotelyDowngraded,
3395
3409
  sipSession,
3396
3410
  answerTime,
3411
+ conference,
3397
3412
  } ) {
3398
3413
  this.callId = callId;
3399
3414
  this.sipCallId = sipCallId;
@@ -3422,6 +3437,7 @@ class CallSession {
3422
3437
  this.videoRemotelyDowngraded = videoRemotelyDowngraded;
3423
3438
  this.sipSession = sipSession;
3424
3439
  this.answerTime = answerTime || this.answerTime;
3440
+ this.conference = conference;
3425
3441
 
3426
3442
  // Useful to compare instead of instanceof with minified code
3427
3443
  this.type = 'CallSession';
@@ -3479,6 +3495,10 @@ class CallSession {
3479
3495
  this.screensharing = false;
3480
3496
  }
3481
3497
 
3498
+ setIsConference(conference ) {
3499
+ this.conference = conference;
3500
+ }
3501
+
3482
3502
  isIncoming() {
3483
3503
  return !this.isCaller && !this.answered;
3484
3504
  }
@@ -3555,6 +3575,10 @@ class CallSession {
3555
3575
  return this.sipStatus === SessionState.Terminated;
3556
3576
  }
3557
3577
 
3578
+ isConference() {
3579
+ return this.conference;
3580
+ }
3581
+
3558
3582
  getElapsedTimeInSeconds() {
3559
3583
  if (!this.startTime) {
3560
3584
  return 0;
@@ -3646,6 +3670,7 @@ class CallSession {
3646
3670
  cameraEnabled: false,
3647
3671
  dialedExtension: call.dialedExtension,
3648
3672
  call,
3673
+ conference: false, // @FIXME?
3649
3674
  });
3650
3675
  }
3651
3676
  }
@@ -3709,11 +3734,13 @@ class Recording {
3709
3734
 
3710
3735
 
3711
3736
 
3737
+
3712
3738
 
3713
3739
 
3714
3740
 
3715
3741
 
3716
3742
 
3743
+
3717
3744
 
3718
3745
 
3719
3746
 
@@ -3734,10 +3761,12 @@ class Recording {
3734
3761
 
3735
3762
 
3736
3763
 
3764
+
3737
3765
 
3738
3766
 
3739
3767
 
3740
3768
 
3769
+
3741
3770
 
3742
3771
 
3743
3772
 
@@ -3799,10 +3828,12 @@ class CallLog {
3799
3828
  || plain.destination_extension
3800
3829
  || `meeting-${plain.requested_name || plain.destination_name || ''}`,
3801
3830
  name: plain.requested_name || plain.destination_name || '',
3831
+ uuid: plain.destination_user_uuid,
3802
3832
  },
3803
3833
  source: {
3804
3834
  extension: plain.source_extension,
3805
3835
  name: plain.source_name,
3836
+ uuid: plain.source_user_uuid,
3806
3837
  },
3807
3838
  id: plain.id,
3808
3839
  duration: (plain.duration || 0) * 1000, // duration is in seconds
@@ -5909,6 +5940,10 @@ class AdHocAPIConference {
5909
5940
  this.conferenceId = conferenceId || '';
5910
5941
  this.muted = muted || false;
5911
5942
  this.paused = paused || false;
5943
+
5944
+ if (this.host) {
5945
+ this.host.setIsConference(true);
5946
+ }
5912
5947
  }
5913
5948
 
5914
5949
  async start() {
@@ -6663,7 +6698,7 @@ const events$1 = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
6663
6698
  const transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
6664
6699
  class CanceledCallError extends Error {}
6665
6700
 
6666
- const MAX_REGISTER_TRIES = 10;
6701
+ const MAX_REGISTER_TRIES = 5;
6667
6702
 
6668
6703
 
6669
6704
 
@@ -9618,7 +9653,11 @@ class WebRTCPhone extends Emitter {
9618
9653
  accept(callSession , cameraEnabled ) {
9619
9654
  logger$7.info('WebRTC phone - accept call', { id: callSession ? callSession.getId() : 'n/a', cameraEnabled });
9620
9655
  if (this.currentSipSession) {
9621
- this.holdSipSession(this.currentSipSession, this.currentCallSession, true);
9656
+ this.holdSipSession(
9657
+ this.currentSipSession,
9658
+ this.currentCallSession,
9659
+ true,
9660
+ );
9622
9661
  }
9623
9662
 
9624
9663
  if (!callSession) {
@@ -9626,6 +9665,12 @@ class WebRTCPhone extends Emitter {
9626
9665
  return Promise.resolve(null);
9627
9666
  }
9628
9667
 
9668
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
9669
+ if (sipSessionId && !(sipSessionId in this.callSessions)) {
9670
+ logger$7.warn('Call session already ended or not found, can\'t accept it.', { sipSessionId });
9671
+ return Promise.resolve(null);
9672
+ }
9673
+
9629
9674
  if (callSession.getId() in this.acceptedSessions) {
9630
9675
  logger$7.warn('CallSession already accepted.', { id: callSession ? callSession.getId() : 'n/a' });
9631
9676
  return Promise.resolve(callSession.sipCallId);
@@ -9705,22 +9750,22 @@ class WebRTCPhone extends Emitter {
9705
9750
  }
9706
9751
  }
9707
9752
 
9708
- hold(callSession , withEvent = true, isConference = false) {
9753
+ hold(callSession , withEvent = true) {
9709
9754
  logger$7.info('WebRTC hold', { id: callSession.getId() });
9710
9755
 
9711
9756
  const sipSession = this.findSipSession(callSession);
9712
9757
 
9713
- return sipSession ? this.holdSipSession(sipSession, callSession, withEvent, isConference) : null;
9758
+ return sipSession ? this.holdSipSession(sipSession, callSession, withEvent) : null;
9714
9759
  }
9715
9760
 
9716
9761
  // @Deprecated
9717
- unhold(callSession , withEvent = true, isConference = false) {
9762
+ unhold(callSession , withEvent = true) {
9718
9763
  console.warn('Please note that `phone.unhold()` is being deprecated; `phone.resume()` is the preferred method');
9719
9764
 
9720
- return this.resume(callSession, isConference, withEvent);
9765
+ return this.resume(callSession, withEvent);
9721
9766
  }
9722
9767
 
9723
- resume(callSession , isConference = false, withEvent = true) {
9768
+ resume(callSession , withEvent = true) {
9724
9769
  logger$7.info('WebRTC resume called', { id: callSession ? callSession.getId() : null });
9725
9770
 
9726
9771
  const sipSession = this.findSipSession(callSession);
@@ -9733,10 +9778,14 @@ class WebRTCPhone extends Emitter {
9733
9778
  // Hold current session if different from the current one (we don't want 2 sessions active at the same time).
9734
9779
  if (this.currentSipSession && this.currentSipSession.id !== sipSession.id) {
9735
9780
  logger$7.info('WebRTC hold call after resume', { id: this.currentSipSession.id });
9736
- this.holdSipSession(this.currentSipSession, this.currentCallSession);
9781
+ this.holdSipSession(
9782
+ this.currentSipSession,
9783
+ this.currentCallSession,
9784
+ withEvent,
9785
+ );
9737
9786
  }
9738
9787
 
9739
- const promise = this.unholdSipSession(sipSession, callSession, withEvent, isConference);
9788
+ const promise = this.unholdSipSession(sipSession, callSession, withEvent);
9740
9789
  this.currentSipSession = sipSession;
9741
9790
  if (callSession) {
9742
9791
  this.currentCallSession = callSession;
@@ -9749,7 +9798,6 @@ class WebRTCPhone extends Emitter {
9749
9798
  sipSession ,
9750
9799
  callSession ,
9751
9800
  withEvent = true,
9752
- isConference = false,
9753
9801
  ) {
9754
9802
  if (!sipSession) {
9755
9803
  return new Promise((resolve, reject) => reject(new Error('No session to hold')));
@@ -9770,6 +9818,8 @@ class WebRTCPhone extends Emitter {
9770
9818
  await this.client.downgradeToAudio(sipSession);
9771
9819
  }
9772
9820
 
9821
+ const isConference = !!callSession && callSession.isConference();
9822
+
9773
9823
  const promise = this.client.hold(sipSession, isConference, hasVideo);
9774
9824
  if (withEvent) {
9775
9825
  this.eventEmitter.emit(ON_CALL_HELD, this._createCallSession(sipSession, callSession));
@@ -9782,11 +9832,13 @@ class WebRTCPhone extends Emitter {
9782
9832
  sipSession ,
9783
9833
  callSession ,
9784
9834
  withEvent = true,
9785
- isConference = false,
9786
9835
  ) {
9787
9836
  if (!sipSession) {
9788
9837
  return new Promise((resolve, reject) => reject(new Error('No session to unhold')));
9789
9838
  }
9839
+
9840
+ const isConference = !!callSession && callSession.isConference();
9841
+
9790
9842
  const sessionId = this.getSipSessionId(sipSession);
9791
9843
  logger$7.info('WebRTC unhold sip session', { sessionId, isConference });
9792
9844
 
@@ -9928,7 +9980,11 @@ class WebRTCPhone extends Emitter {
9928
9980
  await this.client.register();
9929
9981
  }
9930
9982
  if (this.currentSipSession) {
9931
- this.holdSipSession(this.currentSipSession, this.currentCallSession, true).catch(e => {
9983
+ this.holdSipSession(
9984
+ this.currentSipSession,
9985
+ this.currentCallSession,
9986
+ true,
9987
+ ).catch(e => {
9932
9988
  logger$7.warn('Unable to hold current session when making another call', e);
9933
9989
  });
9934
9990
  }
@@ -9943,6 +9999,7 @@ class WebRTCPhone extends Emitter {
9943
9999
  return Promise.resolve(null);
9944
10000
  }
9945
10001
  const callSession = this._createOutgoingCallSession(sipSession, cameraEnabled || false);
10002
+ callSession.setIsConference(conference);
9946
10003
  callSession.creationTime = new Date();
9947
10004
  this._updateCallSession(callSession);
9948
10005
 
@@ -10250,9 +10307,17 @@ class WebRTCPhone extends Emitter {
10250
10307
  });
10251
10308
 
10252
10309
  this.client.on(this.client.ACCEPTED, (sipSession ) => {
10253
- logger$7.info('WebRTC call accepted', { sipId: sipSession.id });
10310
+ const sessionId = this.getSipSessionId(sipSession);
10311
+ const hasSession = sessionId in this.callSessions;
10254
10312
 
10255
- this._onCallAccepted(sipSession, this.client.hasVideo(this.getSipSessionId(sipSession)));
10313
+ logger$7.info('WebRTC call accepted', { sipId: sessionId, hasSession });
10314
+
10315
+ if (!hasSession) {
10316
+ logger$7.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', { sessionId });
10317
+ return;
10318
+ }
10319
+
10320
+ this._onCallAccepted(sipSession, this.client.hasVideo(sessionId));
10256
10321
 
10257
10322
  if (this.audioOutputDeviceId) {
10258
10323
  this.client.changeAudioOutputDevice(this.audioOutputDeviceId);
@@ -10388,9 +10453,14 @@ class WebRTCPhone extends Emitter {
10388
10453
  return this.client.getSipSessionId(sipSession);
10389
10454
  }
10390
10455
 
10391
- _updateCallSession(callSession ) {
10456
+ getSipSessionIdFromCallSession(callSession ) {
10392
10457
  const sipSession = this.findSipSession(callSession);
10393
- const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10458
+
10459
+ return sipSession ? this.getSipSessionId(sipSession) : null;
10460
+ }
10461
+
10462
+ _updateCallSession(callSession ) {
10463
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
10394
10464
 
10395
10465
  if (sipSessionId) {
10396
10466
  this.callSessions[sipSessionId] = callSession;
@@ -10508,6 +10578,7 @@ class WebRTCPhone extends Emitter {
10508
10578
  recording: fromSession ? fromSession.isRecording() : false,
10509
10579
  recordingPaused: false, // @TODO
10510
10580
  sipSession,
10581
+ conference: !!fromSession && fromSession.isConference(),
10511
10582
  ...extra,
10512
10583
  });
10513
10584
 
@@ -10764,16 +10835,16 @@ class Phone extends Emitter {
10764
10835
  }
10765
10836
  }
10766
10837
 
10767
- hold(callSession , isConference = false) {
10768
- return this.phone && this.phone.hold(callSession, true, isConference);
10838
+ hold(callSession ) {
10839
+ return this.phone && this.phone.hold(callSession, true);
10769
10840
  }
10770
10841
 
10771
- unhold(callSession , isConference = false) {
10772
- return this.phone && this.phone.unhold(callSession, true, isConference);
10842
+ unhold(callSession ) {
10843
+ return this.phone && this.phone.unhold(callSession, true);
10773
10844
  }
10774
10845
 
10775
- resume(callSession , isConference = false) {
10776
- return this.phone && this.phone.resume(callSession, isConference);
10846
+ resume(callSession ) {
10847
+ return this.phone && this.phone.resume(callSession);
10777
10848
  }
10778
10849
 
10779
10850
  reject(callSession ) {