@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
@@ -1107,6 +1107,7 @@ const LINE_STATE = {
1107
1107
 
1108
1108
 
1109
1109
 
1110
+
1110
1111
 
1111
1112
 
1112
1113
 
@@ -1143,6 +1144,7 @@ const LINE_STATE = {
1143
1144
 
1144
1145
 
1145
1146
 
1147
+
1146
1148
 
1147
1149
 
1148
1150
 
@@ -1174,6 +1176,7 @@ class Profile {
1174
1176
 
1175
1177
 
1176
1178
 
1179
+
1177
1180
 
1178
1181
 
1179
1182
 
@@ -1190,6 +1193,7 @@ class Profile {
1190
1193
  lines: plain.lines.map(line => Line.parse(line)),
1191
1194
  username: plain.username,
1192
1195
  mobileNumber: plain.mobile_phone_number || '',
1196
+ ringSeconds: plain.ring_seconds,
1193
1197
  forwards: [
1194
1198
  ForwardOption.parse(plain.forwards.unconditional, FORWARD_KEYS.UNCONDITIONAL),
1195
1199
  ForwardOption.parse(plain.forwards.noanswer, FORWARD_KEYS.NO_ANSWER),
@@ -1226,6 +1230,7 @@ class Profile {
1226
1230
  switchboards,
1227
1231
  agent,
1228
1232
  status,
1233
+ ringSeconds,
1229
1234
  sipLines,
1230
1235
  callPickupTargetUsers,
1231
1236
  onlineCallRecordEnabled,
@@ -1247,6 +1252,7 @@ class Profile {
1247
1252
  this.status = status;
1248
1253
  this.callPickupTargetUsers = callPickupTargetUsers;
1249
1254
  this.onlineCallRecordEnabled = onlineCallRecordEnabled;
1255
+ this.ringSeconds = ringSeconds;
1250
1256
 
1251
1257
  this.sipLines = sipLines || [];
1252
1258
  }
@@ -2252,6 +2258,7 @@ var authMethods = (client , baseUrl ) => ({
2252
2258
 
2253
2259
 
2254
2260
 
2261
+
2255
2262
  ) {
2256
2263
  const body = {
2257
2264
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2271,6 +2278,10 @@ var authMethods = (client , baseUrl ) => ({
2271
2278
  headers['Wazo-Session-Type'] = 'mobile';
2272
2279
  }
2273
2280
 
2281
+ if (params.tenantId) {
2282
+ body.tenant_id = params.tenantId;
2283
+ }
2284
+
2274
2285
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2275
2286
  },
2276
2287
 
@@ -3311,6 +3322,7 @@ var updateFrom = (instance , from ) => {
3311
3322
 
3312
3323
 
3313
3324
 
3325
+
3314
3326
 
3315
3327
 
3316
3328
  class CallSession {
@@ -3373,6 +3385,8 @@ class CallSession {
3373
3385
 
3374
3386
 
3375
3387
 
3388
+
3389
+
3376
3390
 
3377
3391
 
3378
3392
 
@@ -3404,6 +3418,7 @@ class CallSession {
3404
3418
  videoRemotelyDowngraded,
3405
3419
  sipSession,
3406
3420
  answerTime,
3421
+ conference,
3407
3422
  } ) {
3408
3423
  this.callId = callId;
3409
3424
  this.sipCallId = sipCallId;
@@ -3432,6 +3447,7 @@ class CallSession {
3432
3447
  this.videoRemotelyDowngraded = videoRemotelyDowngraded;
3433
3448
  this.sipSession = sipSession;
3434
3449
  this.answerTime = answerTime || this.answerTime;
3450
+ this.conference = conference;
3435
3451
 
3436
3452
  // Useful to compare instead of instanceof with minified code
3437
3453
  this.type = 'CallSession';
@@ -3489,6 +3505,10 @@ class CallSession {
3489
3505
  this.screensharing = false;
3490
3506
  }
3491
3507
 
3508
+ setIsConference(conference ) {
3509
+ this.conference = conference;
3510
+ }
3511
+
3492
3512
  isIncoming() {
3493
3513
  return !this.isCaller && !this.answered;
3494
3514
  }
@@ -3565,6 +3585,10 @@ class CallSession {
3565
3585
  return this.sipStatus === sessionState.SessionState.Terminated;
3566
3586
  }
3567
3587
 
3588
+ isConference() {
3589
+ return this.conference;
3590
+ }
3591
+
3568
3592
  getElapsedTimeInSeconds() {
3569
3593
  if (!this.startTime) {
3570
3594
  return 0;
@@ -3656,6 +3680,7 @@ class CallSession {
3656
3680
  cameraEnabled: false,
3657
3681
  dialedExtension: call.dialedExtension,
3658
3682
  call,
3683
+ conference: false, // @FIXME?
3659
3684
  });
3660
3685
  }
3661
3686
  }
@@ -3719,11 +3744,13 @@ class Recording {
3719
3744
 
3720
3745
 
3721
3746
 
3747
+
3722
3748
 
3723
3749
 
3724
3750
 
3725
3751
 
3726
3752
 
3753
+
3727
3754
 
3728
3755
 
3729
3756
 
@@ -3744,10 +3771,12 @@ class Recording {
3744
3771
 
3745
3772
 
3746
3773
 
3774
+
3747
3775
 
3748
3776
 
3749
3777
 
3750
3778
 
3779
+
3751
3780
 
3752
3781
 
3753
3782
 
@@ -3809,10 +3838,12 @@ class CallLog {
3809
3838
  || plain.destination_extension
3810
3839
  || `meeting-${plain.requested_name || plain.destination_name || ''}`,
3811
3840
  name: plain.requested_name || plain.destination_name || '',
3841
+ uuid: plain.destination_user_uuid,
3812
3842
  },
3813
3843
  source: {
3814
3844
  extension: plain.source_extension,
3815
3845
  name: plain.source_name,
3846
+ uuid: plain.source_user_uuid,
3816
3847
  },
3817
3848
  id: plain.id,
3818
3849
  duration: (plain.duration || 0) * 1000, // duration is in seconds
@@ -5919,6 +5950,10 @@ class AdHocAPIConference {
5919
5950
  this.conferenceId = conferenceId || '';
5920
5951
  this.muted = muted || false;
5921
5952
  this.paused = paused || false;
5953
+
5954
+ if (this.host) {
5955
+ this.host.setIsConference(true);
5956
+ }
5922
5957
  }
5923
5958
 
5924
5959
  async start() {
@@ -6673,7 +6708,7 @@ const events$1 = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
6673
6708
  const transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
6674
6709
  class CanceledCallError extends Error {}
6675
6710
 
6676
- const MAX_REGISTER_TRIES = 10;
6711
+ const MAX_REGISTER_TRIES = 5;
6677
6712
 
6678
6713
 
6679
6714
 
@@ -9628,7 +9663,11 @@ class WebRTCPhone extends Emitter {
9628
9663
  accept(callSession , cameraEnabled ) {
9629
9664
  logger$7.info('WebRTC phone - accept call', { id: callSession ? callSession.getId() : 'n/a', cameraEnabled });
9630
9665
  if (this.currentSipSession) {
9631
- this.holdSipSession(this.currentSipSession, this.currentCallSession, true);
9666
+ this.holdSipSession(
9667
+ this.currentSipSession,
9668
+ this.currentCallSession,
9669
+ true,
9670
+ );
9632
9671
  }
9633
9672
 
9634
9673
  if (!callSession) {
@@ -9636,6 +9675,12 @@ class WebRTCPhone extends Emitter {
9636
9675
  return Promise.resolve(null);
9637
9676
  }
9638
9677
 
9678
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
9679
+ if (sipSessionId && !(sipSessionId in this.callSessions)) {
9680
+ logger$7.warn('Call session already ended or not found, can\'t accept it.', { sipSessionId });
9681
+ return Promise.resolve(null);
9682
+ }
9683
+
9639
9684
  if (callSession.getId() in this.acceptedSessions) {
9640
9685
  logger$7.warn('CallSession already accepted.', { id: callSession ? callSession.getId() : 'n/a' });
9641
9686
  return Promise.resolve(callSession.sipCallId);
@@ -9715,22 +9760,22 @@ class WebRTCPhone extends Emitter {
9715
9760
  }
9716
9761
  }
9717
9762
 
9718
- hold(callSession , withEvent = true, isConference = false) {
9763
+ hold(callSession , withEvent = true) {
9719
9764
  logger$7.info('WebRTC hold', { id: callSession.getId() });
9720
9765
 
9721
9766
  const sipSession = this.findSipSession(callSession);
9722
9767
 
9723
- return sipSession ? this.holdSipSession(sipSession, callSession, withEvent, isConference) : null;
9768
+ return sipSession ? this.holdSipSession(sipSession, callSession, withEvent) : null;
9724
9769
  }
9725
9770
 
9726
9771
  // @Deprecated
9727
- unhold(callSession , withEvent = true, isConference = false) {
9772
+ unhold(callSession , withEvent = true) {
9728
9773
  console.warn('Please note that `phone.unhold()` is being deprecated; `phone.resume()` is the preferred method');
9729
9774
 
9730
- return this.resume(callSession, isConference, withEvent);
9775
+ return this.resume(callSession, withEvent);
9731
9776
  }
9732
9777
 
9733
- resume(callSession , isConference = false, withEvent = true) {
9778
+ resume(callSession , withEvent = true) {
9734
9779
  logger$7.info('WebRTC resume called', { id: callSession ? callSession.getId() : null });
9735
9780
 
9736
9781
  const sipSession = this.findSipSession(callSession);
@@ -9743,10 +9788,14 @@ class WebRTCPhone extends Emitter {
9743
9788
  // Hold current session if different from the current one (we don't want 2 sessions active at the same time).
9744
9789
  if (this.currentSipSession && this.currentSipSession.id !== sipSession.id) {
9745
9790
  logger$7.info('WebRTC hold call after resume', { id: this.currentSipSession.id });
9746
- this.holdSipSession(this.currentSipSession, this.currentCallSession);
9791
+ this.holdSipSession(
9792
+ this.currentSipSession,
9793
+ this.currentCallSession,
9794
+ withEvent,
9795
+ );
9747
9796
  }
9748
9797
 
9749
- const promise = this.unholdSipSession(sipSession, callSession, withEvent, isConference);
9798
+ const promise = this.unholdSipSession(sipSession, callSession, withEvent);
9750
9799
  this.currentSipSession = sipSession;
9751
9800
  if (callSession) {
9752
9801
  this.currentCallSession = callSession;
@@ -9759,7 +9808,6 @@ class WebRTCPhone extends Emitter {
9759
9808
  sipSession ,
9760
9809
  callSession ,
9761
9810
  withEvent = true,
9762
- isConference = false,
9763
9811
  ) {
9764
9812
  if (!sipSession) {
9765
9813
  return new Promise((resolve, reject) => reject(new Error('No session to hold')));
@@ -9780,6 +9828,8 @@ class WebRTCPhone extends Emitter {
9780
9828
  await this.client.downgradeToAudio(sipSession);
9781
9829
  }
9782
9830
 
9831
+ const isConference = !!callSession && callSession.isConference();
9832
+
9783
9833
  const promise = this.client.hold(sipSession, isConference, hasVideo);
9784
9834
  if (withEvent) {
9785
9835
  this.eventEmitter.emit(ON_CALL_HELD, this._createCallSession(sipSession, callSession));
@@ -9792,11 +9842,13 @@ class WebRTCPhone extends Emitter {
9792
9842
  sipSession ,
9793
9843
  callSession ,
9794
9844
  withEvent = true,
9795
- isConference = false,
9796
9845
  ) {
9797
9846
  if (!sipSession) {
9798
9847
  return new Promise((resolve, reject) => reject(new Error('No session to unhold')));
9799
9848
  }
9849
+
9850
+ const isConference = !!callSession && callSession.isConference();
9851
+
9800
9852
  const sessionId = this.getSipSessionId(sipSession);
9801
9853
  logger$7.info('WebRTC unhold sip session', { sessionId, isConference });
9802
9854
 
@@ -9938,7 +9990,11 @@ class WebRTCPhone extends Emitter {
9938
9990
  await this.client.register();
9939
9991
  }
9940
9992
  if (this.currentSipSession) {
9941
- this.holdSipSession(this.currentSipSession, this.currentCallSession, true).catch(e => {
9993
+ this.holdSipSession(
9994
+ this.currentSipSession,
9995
+ this.currentCallSession,
9996
+ true,
9997
+ ).catch(e => {
9942
9998
  logger$7.warn('Unable to hold current session when making another call', e);
9943
9999
  });
9944
10000
  }
@@ -9953,6 +10009,7 @@ class WebRTCPhone extends Emitter {
9953
10009
  return Promise.resolve(null);
9954
10010
  }
9955
10011
  const callSession = this._createOutgoingCallSession(sipSession, cameraEnabled || false);
10012
+ callSession.setIsConference(conference);
9956
10013
  callSession.creationTime = new Date();
9957
10014
  this._updateCallSession(callSession);
9958
10015
 
@@ -10260,9 +10317,17 @@ class WebRTCPhone extends Emitter {
10260
10317
  });
10261
10318
 
10262
10319
  this.client.on(this.client.ACCEPTED, (sipSession ) => {
10263
- logger$7.info('WebRTC call accepted', { sipId: sipSession.id });
10320
+ const sessionId = this.getSipSessionId(sipSession);
10321
+ const hasSession = sessionId in this.callSessions;
10264
10322
 
10265
- this._onCallAccepted(sipSession, this.client.hasVideo(this.getSipSessionId(sipSession)));
10323
+ logger$7.info('WebRTC call accepted', { sipId: sessionId, hasSession });
10324
+
10325
+ if (!hasSession) {
10326
+ logger$7.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', { sessionId });
10327
+ return;
10328
+ }
10329
+
10330
+ this._onCallAccepted(sipSession, this.client.hasVideo(sessionId));
10266
10331
 
10267
10332
  if (this.audioOutputDeviceId) {
10268
10333
  this.client.changeAudioOutputDevice(this.audioOutputDeviceId);
@@ -10398,9 +10463,14 @@ class WebRTCPhone extends Emitter {
10398
10463
  return this.client.getSipSessionId(sipSession);
10399
10464
  }
10400
10465
 
10401
- _updateCallSession(callSession ) {
10466
+ getSipSessionIdFromCallSession(callSession ) {
10402
10467
  const sipSession = this.findSipSession(callSession);
10403
- const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10468
+
10469
+ return sipSession ? this.getSipSessionId(sipSession) : null;
10470
+ }
10471
+
10472
+ _updateCallSession(callSession ) {
10473
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
10404
10474
 
10405
10475
  if (sipSessionId) {
10406
10476
  this.callSessions[sipSessionId] = callSession;
@@ -10518,6 +10588,7 @@ class WebRTCPhone extends Emitter {
10518
10588
  recording: fromSession ? fromSession.isRecording() : false,
10519
10589
  recordingPaused: false, // @TODO
10520
10590
  sipSession,
10591
+ conference: !!fromSession && fromSession.isConference(),
10521
10592
  ...extra,
10522
10593
  });
10523
10594
 
@@ -10774,16 +10845,16 @@ class Phone extends Emitter {
10774
10845
  }
10775
10846
  }
10776
10847
 
10777
- hold(callSession , isConference = false) {
10778
- return this.phone && this.phone.hold(callSession, true, isConference);
10848
+ hold(callSession ) {
10849
+ return this.phone && this.phone.hold(callSession, true);
10779
10850
  }
10780
10851
 
10781
- unhold(callSession , isConference = false) {
10782
- return this.phone && this.phone.unhold(callSession, true, isConference);
10852
+ unhold(callSession ) {
10853
+ return this.phone && this.phone.unhold(callSession, true);
10783
10854
  }
10784
10855
 
10785
- resume(callSession , isConference = false) {
10786
- return this.phone && this.phone.resume(callSession, isConference);
10856
+ resume(callSession ) {
10857
+ return this.phone && this.phone.resume(callSession);
10787
10858
  }
10788
10859
 
10789
10860
  reject(callSession ) {