@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
@@ -394,6 +394,7 @@ const LINE_STATE = {
394
394
 
395
395
 
396
396
 
397
+
397
398
 
398
399
 
399
400
 
@@ -430,6 +431,7 @@ const LINE_STATE = {
430
431
 
431
432
 
432
433
 
434
+
433
435
 
434
436
 
435
437
 
@@ -461,6 +463,7 @@ class Profile {
461
463
 
462
464
 
463
465
 
466
+
464
467
 
465
468
 
466
469
 
@@ -477,6 +480,7 @@ class Profile {
477
480
  lines: plain.lines.map(line => Line.parse(line)),
478
481
  username: plain.username,
479
482
  mobileNumber: plain.mobile_phone_number || '',
483
+ ringSeconds: plain.ring_seconds,
480
484
  forwards: [
481
485
  ForwardOption.parse(plain.forwards.unconditional, FORWARD_KEYS.UNCONDITIONAL),
482
486
  ForwardOption.parse(plain.forwards.noanswer, FORWARD_KEYS.NO_ANSWER),
@@ -513,6 +517,7 @@ class Profile {
513
517
  switchboards,
514
518
  agent,
515
519
  status,
520
+ ringSeconds,
516
521
  sipLines,
517
522
  callPickupTargetUsers,
518
523
  onlineCallRecordEnabled,
@@ -534,6 +539,7 @@ class Profile {
534
539
  this.status = status;
535
540
  this.callPickupTargetUsers = callPickupTargetUsers;
536
541
  this.onlineCallRecordEnabled = onlineCallRecordEnabled;
542
+ this.ringSeconds = ringSeconds;
537
543
 
538
544
  this.sipLines = sipLines || [];
539
545
  }
@@ -2226,6 +2232,7 @@ var authMethods = (client , baseUrl ) => ({
2226
2232
 
2227
2233
 
2228
2234
 
2235
+
2229
2236
  ) {
2230
2237
  const body = {
2231
2238
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2245,6 +2252,10 @@ var authMethods = (client , baseUrl ) => ({
2245
2252
  headers['Wazo-Session-Type'] = 'mobile';
2246
2253
  }
2247
2254
 
2255
+ if (params.tenantId) {
2256
+ body.tenant_id = params.tenantId;
2257
+ }
2258
+
2248
2259
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2249
2260
  },
2250
2261
 
@@ -3285,6 +3296,7 @@ var updateFrom = (instance , from ) => {
3285
3296
 
3286
3297
 
3287
3298
 
3299
+
3288
3300
 
3289
3301
 
3290
3302
  class CallSession {
@@ -3347,6 +3359,8 @@ class CallSession {
3347
3359
 
3348
3360
 
3349
3361
 
3362
+
3363
+
3350
3364
 
3351
3365
 
3352
3366
 
@@ -3378,6 +3392,7 @@ class CallSession {
3378
3392
  videoRemotelyDowngraded,
3379
3393
  sipSession,
3380
3394
  answerTime,
3395
+ conference,
3381
3396
  } ) {
3382
3397
  this.callId = callId;
3383
3398
  this.sipCallId = sipCallId;
@@ -3406,6 +3421,7 @@ class CallSession {
3406
3421
  this.videoRemotelyDowngraded = videoRemotelyDowngraded;
3407
3422
  this.sipSession = sipSession;
3408
3423
  this.answerTime = answerTime || this.answerTime;
3424
+ this.conference = conference;
3409
3425
 
3410
3426
  // Useful to compare instead of instanceof with minified code
3411
3427
  this.type = 'CallSession';
@@ -3463,6 +3479,10 @@ class CallSession {
3463
3479
  this.screensharing = false;
3464
3480
  }
3465
3481
 
3482
+ setIsConference(conference ) {
3483
+ this.conference = conference;
3484
+ }
3485
+
3466
3486
  isIncoming() {
3467
3487
  return !this.isCaller && !this.answered;
3468
3488
  }
@@ -3539,6 +3559,10 @@ class CallSession {
3539
3559
  return this.sipStatus === sessionState.SessionState.Terminated;
3540
3560
  }
3541
3561
 
3562
+ isConference() {
3563
+ return this.conference;
3564
+ }
3565
+
3542
3566
  getElapsedTimeInSeconds() {
3543
3567
  if (!this.startTime) {
3544
3568
  return 0;
@@ -3630,6 +3654,7 @@ class CallSession {
3630
3654
  cameraEnabled: false,
3631
3655
  dialedExtension: call.dialedExtension,
3632
3656
  call,
3657
+ conference: false, // @FIXME?
3633
3658
  });
3634
3659
  }
3635
3660
  }
@@ -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 ) {