@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
@@ -1083,6 +1083,7 @@ const LINE_STATE = {
1083
1083
 
1084
1084
 
1085
1085
 
1086
+
1086
1087
 
1087
1088
 
1088
1089
 
@@ -1119,6 +1120,7 @@ const LINE_STATE = {
1119
1120
 
1120
1121
 
1121
1122
 
1123
+
1122
1124
 
1123
1125
 
1124
1126
 
@@ -1150,6 +1152,7 @@ class Profile {
1150
1152
 
1151
1153
 
1152
1154
 
1155
+
1153
1156
 
1154
1157
 
1155
1158
 
@@ -1166,6 +1169,7 @@ class Profile {
1166
1169
  lines: plain.lines.map(line => Line.parse(line)),
1167
1170
  username: plain.username,
1168
1171
  mobileNumber: plain.mobile_phone_number || '',
1172
+ ringSeconds: plain.ring_seconds,
1169
1173
  forwards: [
1170
1174
  ForwardOption.parse(plain.forwards.unconditional, FORWARD_KEYS.UNCONDITIONAL),
1171
1175
  ForwardOption.parse(plain.forwards.noanswer, FORWARD_KEYS.NO_ANSWER),
@@ -1202,6 +1206,7 @@ class Profile {
1202
1206
  switchboards,
1203
1207
  agent,
1204
1208
  status,
1209
+ ringSeconds,
1205
1210
  sipLines,
1206
1211
  callPickupTargetUsers,
1207
1212
  onlineCallRecordEnabled,
@@ -1223,6 +1228,7 @@ class Profile {
1223
1228
  this.status = status;
1224
1229
  this.callPickupTargetUsers = callPickupTargetUsers;
1225
1230
  this.onlineCallRecordEnabled = onlineCallRecordEnabled;
1231
+ this.ringSeconds = ringSeconds;
1226
1232
 
1227
1233
  this.sipLines = sipLines || [];
1228
1234
  }
@@ -2228,6 +2234,7 @@ var authMethods = (client , baseUrl ) => ({
2228
2234
 
2229
2235
 
2230
2236
 
2237
+
2231
2238
  ) {
2232
2239
  const body = {
2233
2240
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2247,6 +2254,10 @@ var authMethods = (client , baseUrl ) => ({
2247
2254
  headers['Wazo-Session-Type'] = 'mobile';
2248
2255
  }
2249
2256
 
2257
+ if (params.tenantId) {
2258
+ body.tenant_id = params.tenantId;
2259
+ }
2260
+
2250
2261
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2251
2262
  },
2252
2263
 
@@ -3287,6 +3298,7 @@ var updateFrom = (instance , from ) => {
3287
3298
 
3288
3299
 
3289
3300
 
3301
+
3290
3302
 
3291
3303
 
3292
3304
  class CallSession {
@@ -3349,6 +3361,8 @@ class CallSession {
3349
3361
 
3350
3362
 
3351
3363
 
3364
+
3365
+
3352
3366
 
3353
3367
 
3354
3368
 
@@ -3380,6 +3394,7 @@ class CallSession {
3380
3394
  videoRemotelyDowngraded,
3381
3395
  sipSession,
3382
3396
  answerTime,
3397
+ conference,
3383
3398
  } ) {
3384
3399
  this.callId = callId;
3385
3400
  this.sipCallId = sipCallId;
@@ -3408,6 +3423,7 @@ class CallSession {
3408
3423
  this.videoRemotelyDowngraded = videoRemotelyDowngraded;
3409
3424
  this.sipSession = sipSession;
3410
3425
  this.answerTime = answerTime || this.answerTime;
3426
+ this.conference = conference;
3411
3427
 
3412
3428
  // Useful to compare instead of instanceof with minified code
3413
3429
  this.type = 'CallSession';
@@ -3465,6 +3481,10 @@ class CallSession {
3465
3481
  this.screensharing = false;
3466
3482
  }
3467
3483
 
3484
+ setIsConference(conference ) {
3485
+ this.conference = conference;
3486
+ }
3487
+
3468
3488
  isIncoming() {
3469
3489
  return !this.isCaller && !this.answered;
3470
3490
  }
@@ -3541,6 +3561,10 @@ class CallSession {
3541
3561
  return this.sipStatus === sessionState.SessionState.Terminated;
3542
3562
  }
3543
3563
 
3564
+ isConference() {
3565
+ return this.conference;
3566
+ }
3567
+
3544
3568
  getElapsedTimeInSeconds() {
3545
3569
  if (!this.startTime) {
3546
3570
  return 0;
@@ -3632,6 +3656,7 @@ class CallSession {
3632
3656
  cameraEnabled: false,
3633
3657
  dialedExtension: call.dialedExtension,
3634
3658
  call,
3659
+ conference: false, // @FIXME?
3635
3660
  });
3636
3661
  }
3637
3662
  }
@@ -3721,11 +3746,13 @@ class Recording {
3721
3746
 
3722
3747
 
3723
3748
 
3749
+
3724
3750
 
3725
3751
 
3726
3752
 
3727
3753
 
3728
3754
 
3755
+
3729
3756
 
3730
3757
 
3731
3758
 
@@ -3746,10 +3773,12 @@ class Recording {
3746
3773
 
3747
3774
 
3748
3775
 
3776
+
3749
3777
 
3750
3778
 
3751
3779
 
3752
3780
 
3781
+
3753
3782
 
3754
3783
 
3755
3784
 
@@ -3811,10 +3840,12 @@ class CallLog {
3811
3840
  || plain.destination_extension
3812
3841
  || `meeting-${plain.requested_name || plain.destination_name || ''}`,
3813
3842
  name: plain.requested_name || plain.destination_name || '',
3843
+ uuid: plain.destination_user_uuid,
3814
3844
  },
3815
3845
  source: {
3816
3846
  extension: plain.source_extension,
3817
3847
  name: plain.source_name,
3848
+ uuid: plain.source_user_uuid,
3818
3849
  },
3819
3850
  id: plain.id,
3820
3851
  duration: (plain.duration || 0) * 1000, // duration is in seconds
@@ -5921,6 +5952,10 @@ class AdHocAPIConference {
5921
5952
  this.conferenceId = conferenceId || '';
5922
5953
  this.muted = muted || false;
5923
5954
  this.paused = paused || false;
5955
+
5956
+ if (this.host) {
5957
+ this.host.setIsConference(true);
5958
+ }
5924
5959
  }
5925
5960
 
5926
5961
  async start() {
@@ -6675,7 +6710,7 @@ const events$1 = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
6675
6710
  const transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
6676
6711
  class CanceledCallError extends Error {}
6677
6712
 
6678
- const MAX_REGISTER_TRIES = 10;
6713
+ const MAX_REGISTER_TRIES = 5;
6679
6714
 
6680
6715
 
6681
6716
 
@@ -9630,7 +9665,11 @@ class WebRTCPhone extends Emitter {
9630
9665
  accept(callSession , cameraEnabled ) {
9631
9666
  logger$7.info('WebRTC phone - accept call', { id: callSession ? callSession.getId() : 'n/a', cameraEnabled });
9632
9667
  if (this.currentSipSession) {
9633
- this.holdSipSession(this.currentSipSession, this.currentCallSession, true);
9668
+ this.holdSipSession(
9669
+ this.currentSipSession,
9670
+ this.currentCallSession,
9671
+ true,
9672
+ );
9634
9673
  }
9635
9674
 
9636
9675
  if (!callSession) {
@@ -9638,6 +9677,12 @@ class WebRTCPhone extends Emitter {
9638
9677
  return Promise.resolve(null);
9639
9678
  }
9640
9679
 
9680
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
9681
+ if (sipSessionId && !(sipSessionId in this.callSessions)) {
9682
+ logger$7.warn('Call session already ended or not found, can\'t accept it.', { sipSessionId });
9683
+ return Promise.resolve(null);
9684
+ }
9685
+
9641
9686
  if (callSession.getId() in this.acceptedSessions) {
9642
9687
  logger$7.warn('CallSession already accepted.', { id: callSession ? callSession.getId() : 'n/a' });
9643
9688
  return Promise.resolve(callSession.sipCallId);
@@ -9717,22 +9762,22 @@ class WebRTCPhone extends Emitter {
9717
9762
  }
9718
9763
  }
9719
9764
 
9720
- hold(callSession , withEvent = true, isConference = false) {
9765
+ hold(callSession , withEvent = true) {
9721
9766
  logger$7.info('WebRTC hold', { id: callSession.getId() });
9722
9767
 
9723
9768
  const sipSession = this.findSipSession(callSession);
9724
9769
 
9725
- return sipSession ? this.holdSipSession(sipSession, callSession, withEvent, isConference) : null;
9770
+ return sipSession ? this.holdSipSession(sipSession, callSession, withEvent) : null;
9726
9771
  }
9727
9772
 
9728
9773
  // @Deprecated
9729
- unhold(callSession , withEvent = true, isConference = false) {
9774
+ unhold(callSession , withEvent = true) {
9730
9775
  console.warn('Please note that `phone.unhold()` is being deprecated; `phone.resume()` is the preferred method');
9731
9776
 
9732
- return this.resume(callSession, isConference, withEvent);
9777
+ return this.resume(callSession, withEvent);
9733
9778
  }
9734
9779
 
9735
- resume(callSession , isConference = false, withEvent = true) {
9780
+ resume(callSession , withEvent = true) {
9736
9781
  logger$7.info('WebRTC resume called', { id: callSession ? callSession.getId() : null });
9737
9782
 
9738
9783
  const sipSession = this.findSipSession(callSession);
@@ -9745,10 +9790,14 @@ class WebRTCPhone extends Emitter {
9745
9790
  // Hold current session if different from the current one (we don't want 2 sessions active at the same time).
9746
9791
  if (this.currentSipSession && this.currentSipSession.id !== sipSession.id) {
9747
9792
  logger$7.info('WebRTC hold call after resume', { id: this.currentSipSession.id });
9748
- this.holdSipSession(this.currentSipSession, this.currentCallSession);
9793
+ this.holdSipSession(
9794
+ this.currentSipSession,
9795
+ this.currentCallSession,
9796
+ withEvent,
9797
+ );
9749
9798
  }
9750
9799
 
9751
- const promise = this.unholdSipSession(sipSession, callSession, withEvent, isConference);
9800
+ const promise = this.unholdSipSession(sipSession, callSession, withEvent);
9752
9801
  this.currentSipSession = sipSession;
9753
9802
  if (callSession) {
9754
9803
  this.currentCallSession = callSession;
@@ -9761,7 +9810,6 @@ class WebRTCPhone extends Emitter {
9761
9810
  sipSession ,
9762
9811
  callSession ,
9763
9812
  withEvent = true,
9764
- isConference = false,
9765
9813
  ) {
9766
9814
  if (!sipSession) {
9767
9815
  return new Promise((resolve, reject) => reject(new Error('No session to hold')));
@@ -9782,6 +9830,8 @@ class WebRTCPhone extends Emitter {
9782
9830
  await this.client.downgradeToAudio(sipSession);
9783
9831
  }
9784
9832
 
9833
+ const isConference = !!callSession && callSession.isConference();
9834
+
9785
9835
  const promise = this.client.hold(sipSession, isConference, hasVideo);
9786
9836
  if (withEvent) {
9787
9837
  this.eventEmitter.emit(ON_CALL_HELD, this._createCallSession(sipSession, callSession));
@@ -9794,11 +9844,13 @@ class WebRTCPhone extends Emitter {
9794
9844
  sipSession ,
9795
9845
  callSession ,
9796
9846
  withEvent = true,
9797
- isConference = false,
9798
9847
  ) {
9799
9848
  if (!sipSession) {
9800
9849
  return new Promise((resolve, reject) => reject(new Error('No session to unhold')));
9801
9850
  }
9851
+
9852
+ const isConference = !!callSession && callSession.isConference();
9853
+
9802
9854
  const sessionId = this.getSipSessionId(sipSession);
9803
9855
  logger$7.info('WebRTC unhold sip session', { sessionId, isConference });
9804
9856
 
@@ -9940,7 +9992,11 @@ class WebRTCPhone extends Emitter {
9940
9992
  await this.client.register();
9941
9993
  }
9942
9994
  if (this.currentSipSession) {
9943
- this.holdSipSession(this.currentSipSession, this.currentCallSession, true).catch(e => {
9995
+ this.holdSipSession(
9996
+ this.currentSipSession,
9997
+ this.currentCallSession,
9998
+ true,
9999
+ ).catch(e => {
9944
10000
  logger$7.warn('Unable to hold current session when making another call', e);
9945
10001
  });
9946
10002
  }
@@ -9955,6 +10011,7 @@ class WebRTCPhone extends Emitter {
9955
10011
  return Promise.resolve(null);
9956
10012
  }
9957
10013
  const callSession = this._createOutgoingCallSession(sipSession, cameraEnabled || false);
10014
+ callSession.setIsConference(conference);
9958
10015
  callSession.creationTime = new Date();
9959
10016
  this._updateCallSession(callSession);
9960
10017
 
@@ -10262,9 +10319,17 @@ class WebRTCPhone extends Emitter {
10262
10319
  });
10263
10320
 
10264
10321
  this.client.on(this.client.ACCEPTED, (sipSession ) => {
10265
- logger$7.info('WebRTC call accepted', { sipId: sipSession.id });
10322
+ const sessionId = this.getSipSessionId(sipSession);
10323
+ const hasSession = sessionId in this.callSessions;
10266
10324
 
10267
- this._onCallAccepted(sipSession, this.client.hasVideo(this.getSipSessionId(sipSession)));
10325
+ logger$7.info('WebRTC call accepted', { sipId: sessionId, hasSession });
10326
+
10327
+ if (!hasSession) {
10328
+ logger$7.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', { sessionId });
10329
+ return;
10330
+ }
10331
+
10332
+ this._onCallAccepted(sipSession, this.client.hasVideo(sessionId));
10268
10333
 
10269
10334
  if (this.audioOutputDeviceId) {
10270
10335
  this.client.changeAudioOutputDevice(this.audioOutputDeviceId);
@@ -10400,9 +10465,14 @@ class WebRTCPhone extends Emitter {
10400
10465
  return this.client.getSipSessionId(sipSession);
10401
10466
  }
10402
10467
 
10403
- _updateCallSession(callSession ) {
10468
+ getSipSessionIdFromCallSession(callSession ) {
10404
10469
  const sipSession = this.findSipSession(callSession);
10405
- const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10470
+
10471
+ return sipSession ? this.getSipSessionId(sipSession) : null;
10472
+ }
10473
+
10474
+ _updateCallSession(callSession ) {
10475
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
10406
10476
 
10407
10477
  if (sipSessionId) {
10408
10478
  this.callSessions[sipSessionId] = callSession;
@@ -10520,6 +10590,7 @@ class WebRTCPhone extends Emitter {
10520
10590
  recording: fromSession ? fromSession.isRecording() : false,
10521
10591
  recordingPaused: false, // @TODO
10522
10592
  sipSession,
10593
+ conference: !!fromSession && fromSession.isConference(),
10523
10594
  ...extra,
10524
10595
  });
10525
10596
 
@@ -10776,16 +10847,16 @@ class Phone extends Emitter {
10776
10847
  }
10777
10848
  }
10778
10849
 
10779
- hold(callSession , isConference = false) {
10780
- return this.phone && this.phone.hold(callSession, true, isConference);
10850
+ hold(callSession ) {
10851
+ return this.phone && this.phone.hold(callSession, true);
10781
10852
  }
10782
10853
 
10783
- unhold(callSession , isConference = false) {
10784
- return this.phone && this.phone.unhold(callSession, true, isConference);
10854
+ unhold(callSession ) {
10855
+ return this.phone && this.phone.unhold(callSession, true);
10785
10856
  }
10786
10857
 
10787
- resume(callSession , isConference = false) {
10788
- return this.phone && this.phone.resume(callSession, isConference);
10858
+ resume(callSession ) {
10859
+ return this.phone && this.phone.resume(callSession);
10789
10860
  }
10790
10861
 
10791
10862
  reject(callSession ) {