@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
@@ -396,6 +396,7 @@ const LINE_STATE = {
396
396
 
397
397
 
398
398
 
399
+
399
400
 
400
401
 
401
402
 
@@ -432,6 +433,7 @@ const LINE_STATE = {
432
433
 
433
434
 
434
435
 
436
+
435
437
 
436
438
 
437
439
 
@@ -463,6 +465,7 @@ class Profile {
463
465
 
464
466
 
465
467
 
468
+
466
469
 
467
470
 
468
471
 
@@ -479,6 +482,7 @@ class Profile {
479
482
  lines: plain.lines.map(line => Line.parse(line)),
480
483
  username: plain.username,
481
484
  mobileNumber: plain.mobile_phone_number || '',
485
+ ringSeconds: plain.ring_seconds,
482
486
  forwards: [
483
487
  ForwardOption.parse(plain.forwards.unconditional, FORWARD_KEYS.UNCONDITIONAL),
484
488
  ForwardOption.parse(plain.forwards.noanswer, FORWARD_KEYS.NO_ANSWER),
@@ -515,6 +519,7 @@ class Profile {
515
519
  switchboards,
516
520
  agent,
517
521
  status,
522
+ ringSeconds,
518
523
  sipLines,
519
524
  callPickupTargetUsers,
520
525
  onlineCallRecordEnabled,
@@ -536,6 +541,7 @@ class Profile {
536
541
  this.status = status;
537
542
  this.callPickupTargetUsers = callPickupTargetUsers;
538
543
  this.onlineCallRecordEnabled = onlineCallRecordEnabled;
544
+ this.ringSeconds = ringSeconds;
539
545
 
540
546
  this.sipLines = sipLines || [];
541
547
  }
@@ -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
@@ -5657,6 +5688,10 @@ class AdHocAPIConference {
5657
5688
  this.conferenceId = conferenceId || '';
5658
5689
  this.muted = muted || false;
5659
5690
  this.paused = paused || false;
5691
+
5692
+ if (this.host) {
5693
+ this.host.setIsConference(true);
5694
+ }
5660
5695
  }
5661
5696
 
5662
5697
  async start() {
@@ -6411,7 +6446,7 @@ const events$1 = [REGISTERED, UNREGISTERED, REGISTRATION_FAILED, INVITE];
6411
6446
  const transportEvents = [CONNECTED, DISCONNECTED, TRANSPORT_ERROR, MESSAGE];
6412
6447
  class CanceledCallError extends Error {}
6413
6448
 
6414
- const MAX_REGISTER_TRIES = 10;
6449
+ const MAX_REGISTER_TRIES = 5;
6415
6450
 
6416
6451
 
6417
6452
 
@@ -9366,7 +9401,11 @@ class WebRTCPhone extends Emitter {
9366
9401
  accept(callSession , cameraEnabled ) {
9367
9402
  logger$8.info('WebRTC phone - accept call', { id: callSession ? callSession.getId() : 'n/a', cameraEnabled });
9368
9403
  if (this.currentSipSession) {
9369
- this.holdSipSession(this.currentSipSession, this.currentCallSession, true);
9404
+ this.holdSipSession(
9405
+ this.currentSipSession,
9406
+ this.currentCallSession,
9407
+ true,
9408
+ );
9370
9409
  }
9371
9410
 
9372
9411
  if (!callSession) {
@@ -9374,6 +9413,12 @@ class WebRTCPhone extends Emitter {
9374
9413
  return Promise.resolve(null);
9375
9414
  }
9376
9415
 
9416
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
9417
+ if (sipSessionId && !(sipSessionId in this.callSessions)) {
9418
+ logger$8.warn('Call session already ended or not found, can\'t accept it.', { sipSessionId });
9419
+ return Promise.resolve(null);
9420
+ }
9421
+
9377
9422
  if (callSession.getId() in this.acceptedSessions) {
9378
9423
  logger$8.warn('CallSession already accepted.', { id: callSession ? callSession.getId() : 'n/a' });
9379
9424
  return Promise.resolve(callSession.sipCallId);
@@ -9453,22 +9498,22 @@ class WebRTCPhone extends Emitter {
9453
9498
  }
9454
9499
  }
9455
9500
 
9456
- hold(callSession , withEvent = true, isConference = false) {
9501
+ hold(callSession , withEvent = true) {
9457
9502
  logger$8.info('WebRTC hold', { id: callSession.getId() });
9458
9503
 
9459
9504
  const sipSession = this.findSipSession(callSession);
9460
9505
 
9461
- return sipSession ? this.holdSipSession(sipSession, callSession, withEvent, isConference) : null;
9506
+ return sipSession ? this.holdSipSession(sipSession, callSession, withEvent) : null;
9462
9507
  }
9463
9508
 
9464
9509
  // @Deprecated
9465
- unhold(callSession , withEvent = true, isConference = false) {
9510
+ unhold(callSession , withEvent = true) {
9466
9511
  console.warn('Please note that `phone.unhold()` is being deprecated; `phone.resume()` is the preferred method');
9467
9512
 
9468
- return this.resume(callSession, isConference, withEvent);
9513
+ return this.resume(callSession, withEvent);
9469
9514
  }
9470
9515
 
9471
- resume(callSession , isConference = false, withEvent = true) {
9516
+ resume(callSession , withEvent = true) {
9472
9517
  logger$8.info('WebRTC resume called', { id: callSession ? callSession.getId() : null });
9473
9518
 
9474
9519
  const sipSession = this.findSipSession(callSession);
@@ -9481,10 +9526,14 @@ class WebRTCPhone extends Emitter {
9481
9526
  // Hold current session if different from the current one (we don't want 2 sessions active at the same time).
9482
9527
  if (this.currentSipSession && this.currentSipSession.id !== sipSession.id) {
9483
9528
  logger$8.info('WebRTC hold call after resume', { id: this.currentSipSession.id });
9484
- this.holdSipSession(this.currentSipSession, this.currentCallSession);
9529
+ this.holdSipSession(
9530
+ this.currentSipSession,
9531
+ this.currentCallSession,
9532
+ withEvent,
9533
+ );
9485
9534
  }
9486
9535
 
9487
- const promise = this.unholdSipSession(sipSession, callSession, withEvent, isConference);
9536
+ const promise = this.unholdSipSession(sipSession, callSession, withEvent);
9488
9537
  this.currentSipSession = sipSession;
9489
9538
  if (callSession) {
9490
9539
  this.currentCallSession = callSession;
@@ -9497,7 +9546,6 @@ class WebRTCPhone extends Emitter {
9497
9546
  sipSession ,
9498
9547
  callSession ,
9499
9548
  withEvent = true,
9500
- isConference = false,
9501
9549
  ) {
9502
9550
  if (!sipSession) {
9503
9551
  return new Promise((resolve, reject) => reject(new Error('No session to hold')));
@@ -9518,6 +9566,8 @@ class WebRTCPhone extends Emitter {
9518
9566
  await this.client.downgradeToAudio(sipSession);
9519
9567
  }
9520
9568
 
9569
+ const isConference = !!callSession && callSession.isConference();
9570
+
9521
9571
  const promise = this.client.hold(sipSession, isConference, hasVideo);
9522
9572
  if (withEvent) {
9523
9573
  this.eventEmitter.emit(ON_CALL_HELD, this._createCallSession(sipSession, callSession));
@@ -9530,11 +9580,13 @@ class WebRTCPhone extends Emitter {
9530
9580
  sipSession ,
9531
9581
  callSession ,
9532
9582
  withEvent = true,
9533
- isConference = false,
9534
9583
  ) {
9535
9584
  if (!sipSession) {
9536
9585
  return new Promise((resolve, reject) => reject(new Error('No session to unhold')));
9537
9586
  }
9587
+
9588
+ const isConference = !!callSession && callSession.isConference();
9589
+
9538
9590
  const sessionId = this.getSipSessionId(sipSession);
9539
9591
  logger$8.info('WebRTC unhold sip session', { sessionId, isConference });
9540
9592
 
@@ -9676,7 +9728,11 @@ class WebRTCPhone extends Emitter {
9676
9728
  await this.client.register();
9677
9729
  }
9678
9730
  if (this.currentSipSession) {
9679
- this.holdSipSession(this.currentSipSession, this.currentCallSession, true).catch(e => {
9731
+ this.holdSipSession(
9732
+ this.currentSipSession,
9733
+ this.currentCallSession,
9734
+ true,
9735
+ ).catch(e => {
9680
9736
  logger$8.warn('Unable to hold current session when making another call', e);
9681
9737
  });
9682
9738
  }
@@ -9691,6 +9747,7 @@ class WebRTCPhone extends Emitter {
9691
9747
  return Promise.resolve(null);
9692
9748
  }
9693
9749
  const callSession = this._createOutgoingCallSession(sipSession, cameraEnabled || false);
9750
+ callSession.setIsConference(conference);
9694
9751
  callSession.creationTime = new Date();
9695
9752
  this._updateCallSession(callSession);
9696
9753
 
@@ -9998,9 +10055,17 @@ class WebRTCPhone extends Emitter {
9998
10055
  });
9999
10056
 
10000
10057
  this.client.on(this.client.ACCEPTED, (sipSession ) => {
10001
- logger$8.info('WebRTC call accepted', { sipId: sipSession.id });
10058
+ const sessionId = this.getSipSessionId(sipSession);
10059
+ const hasSession = sessionId in this.callSessions;
10002
10060
 
10003
- this._onCallAccepted(sipSession, this.client.hasVideo(this.getSipSessionId(sipSession)));
10061
+ logger$8.info('WebRTC call accepted', { sipId: sessionId, hasSession });
10062
+
10063
+ if (!hasSession) {
10064
+ logger$8.warn('Call accepted ignored, session is no longer present in the WebRtcPhone', { sessionId });
10065
+ return;
10066
+ }
10067
+
10068
+ this._onCallAccepted(sipSession, this.client.hasVideo(sessionId));
10004
10069
 
10005
10070
  if (this.audioOutputDeviceId) {
10006
10071
  this.client.changeAudioOutputDevice(this.audioOutputDeviceId);
@@ -10136,9 +10201,14 @@ class WebRTCPhone extends Emitter {
10136
10201
  return this.client.getSipSessionId(sipSession);
10137
10202
  }
10138
10203
 
10139
- _updateCallSession(callSession ) {
10204
+ getSipSessionIdFromCallSession(callSession ) {
10140
10205
  const sipSession = this.findSipSession(callSession);
10141
- const sipSessionId = sipSession ? this.getSipSessionId(sipSession) : null;
10206
+
10207
+ return sipSession ? this.getSipSessionId(sipSession) : null;
10208
+ }
10209
+
10210
+ _updateCallSession(callSession ) {
10211
+ const sipSessionId = this.getSipSessionIdFromCallSession(callSession);
10142
10212
 
10143
10213
  if (sipSessionId) {
10144
10214
  this.callSessions[sipSessionId] = callSession;
@@ -10256,6 +10326,7 @@ class WebRTCPhone extends Emitter {
10256
10326
  recording: fromSession ? fromSession.isRecording() : false,
10257
10327
  recordingPaused: false, // @TODO
10258
10328
  sipSession,
10329
+ conference: !!fromSession && fromSession.isConference(),
10259
10330
  ...extra,
10260
10331
  });
10261
10332
 
@@ -10512,16 +10583,16 @@ class Phone extends Emitter {
10512
10583
  }
10513
10584
  }
10514
10585
 
10515
- hold(callSession , isConference = false) {
10516
- return this.phone && this.phone.hold(callSession, true, isConference);
10586
+ hold(callSession ) {
10587
+ return this.phone && this.phone.hold(callSession, true);
10517
10588
  }
10518
10589
 
10519
- unhold(callSession , isConference = false) {
10520
- return this.phone && this.phone.unhold(callSession, true, isConference);
10590
+ unhold(callSession ) {
10591
+ return this.phone && this.phone.unhold(callSession, true);
10521
10592
  }
10522
10593
 
10523
- resume(callSession , isConference = false) {
10524
- return this.phone && this.phone.resume(callSession, isConference);
10594
+ resume(callSession ) {
10595
+ return this.phone && this.phone.resume(callSession);
10525
10596
  }
10526
10597
 
10527
10598
  reject(callSession ) {