@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
@@ -384,6 +384,7 @@ const LINE_STATE = {
384
384
 
385
385
 
386
386
 
387
+
387
388
 
388
389
 
389
390
 
@@ -420,6 +421,7 @@ const LINE_STATE = {
420
421
 
421
422
 
422
423
 
424
+
423
425
 
424
426
 
425
427
 
@@ -451,6 +453,7 @@ class Profile {
451
453
 
452
454
 
453
455
 
456
+
454
457
 
455
458
 
456
459
 
@@ -467,6 +470,7 @@ class Profile {
467
470
  lines: plain.lines.map(line => Line.parse(line)),
468
471
  username: plain.username,
469
472
  mobileNumber: plain.mobile_phone_number || '',
473
+ ringSeconds: plain.ring_seconds,
470
474
  forwards: [
471
475
  ForwardOption.parse(plain.forwards.unconditional, FORWARD_KEYS.UNCONDITIONAL),
472
476
  ForwardOption.parse(plain.forwards.noanswer, FORWARD_KEYS.NO_ANSWER),
@@ -503,6 +507,7 @@ class Profile {
503
507
  switchboards,
504
508
  agent,
505
509
  status,
510
+ ringSeconds,
506
511
  sipLines,
507
512
  callPickupTargetUsers,
508
513
  onlineCallRecordEnabled,
@@ -524,6 +529,7 @@ class Profile {
524
529
  this.status = status;
525
530
  this.callPickupTargetUsers = callPickupTargetUsers;
526
531
  this.onlineCallRecordEnabled = onlineCallRecordEnabled;
532
+ this.ringSeconds = ringSeconds;
527
533
 
528
534
  this.sipLines = sipLines || [];
529
535
  }
@@ -2216,6 +2222,7 @@ var authMethods = (client , baseUrl ) => ({
2216
2222
 
2217
2223
 
2218
2224
 
2225
+
2219
2226
  ) {
2220
2227
  const body = {
2221
2228
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2235,6 +2242,10 @@ var authMethods = (client , baseUrl ) => ({
2235
2242
  headers['Wazo-Session-Type'] = 'mobile';
2236
2243
  }
2237
2244
 
2245
+ if (params.tenantId) {
2246
+ body.tenant_id = params.tenantId;
2247
+ }
2248
+
2238
2249
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2239
2250
  },
2240
2251
 
@@ -3275,6 +3286,7 @@ var updateFrom = (instance , from ) => {
3275
3286
 
3276
3287
 
3277
3288
 
3289
+
3278
3290
 
3279
3291
 
3280
3292
  class CallSession {
@@ -3337,6 +3349,8 @@ class CallSession {
3337
3349
 
3338
3350
 
3339
3351
 
3352
+
3353
+
3340
3354
 
3341
3355
 
3342
3356
 
@@ -3368,6 +3382,7 @@ class CallSession {
3368
3382
  videoRemotelyDowngraded,
3369
3383
  sipSession,
3370
3384
  answerTime,
3385
+ conference,
3371
3386
  } ) {
3372
3387
  this.callId = callId;
3373
3388
  this.sipCallId = sipCallId;
@@ -3396,6 +3411,7 @@ class CallSession {
3396
3411
  this.videoRemotelyDowngraded = videoRemotelyDowngraded;
3397
3412
  this.sipSession = sipSession;
3398
3413
  this.answerTime = answerTime || this.answerTime;
3414
+ this.conference = conference;
3399
3415
 
3400
3416
  // Useful to compare instead of instanceof with minified code
3401
3417
  this.type = 'CallSession';
@@ -3453,6 +3469,10 @@ class CallSession {
3453
3469
  this.screensharing = false;
3454
3470
  }
3455
3471
 
3472
+ setIsConference(conference ) {
3473
+ this.conference = conference;
3474
+ }
3475
+
3456
3476
  isIncoming() {
3457
3477
  return !this.isCaller && !this.answered;
3458
3478
  }
@@ -3529,6 +3549,10 @@ class CallSession {
3529
3549
  return this.sipStatus === SessionState.Terminated;
3530
3550
  }
3531
3551
 
3552
+ isConference() {
3553
+ return this.conference;
3554
+ }
3555
+
3532
3556
  getElapsedTimeInSeconds() {
3533
3557
  if (!this.startTime) {
3534
3558
  return 0;
@@ -3620,6 +3644,7 @@ class CallSession {
3620
3644
  cameraEnabled: false,
3621
3645
  dialedExtension: call.dialedExtension,
3622
3646
  call,
3647
+ conference: false, // @FIXME?
3623
3648
  });
3624
3649
  }
3625
3650
  }
@@ -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 ) {