@wazo/sdk 0.38.7 → 0.38.10

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 (121) hide show
  1. package/dist/wazo-sdk.js +2 -2
  2. package/esm/__tests__/api-client.test.js +163 -2
  3. package/esm/__tests__/web-rtc-client.test.js +248 -27
  4. package/esm/api/auth.js +12 -0
  5. package/esm/api/calld.js +8 -0
  6. package/esm/api/confd.js +134 -2
  7. package/esm/api/ctid-ng.js +1 -0
  8. package/esm/api-client.js +163 -2
  9. package/esm/checker/Checker.js +204 -24
  10. package/esm/checker/checks/aor.js +163 -2
  11. package/esm/checker/checks/api.js +163 -2
  12. package/esm/checker/checks/index.js +204 -24
  13. package/esm/checker/checks/wazo-websocket.js +2 -0
  14. package/esm/checker/checks/webrtc-transport.js +202 -24
  15. package/esm/checker/checks/webrtc.js +202 -24
  16. package/esm/domain/AdHocAPIConference.js +170 -4
  17. package/esm/domain/Features.js +170 -4
  18. package/esm/domain/Meeting.js +18 -0
  19. package/esm/domain/MeetingAuthorization.js +70 -0
  20. package/esm/domain/Phone/CTIPhone.js +170 -4
  21. package/esm/domain/Phone/WebRTCPhone.js +2 -3
  22. package/esm/domain/__tests__/Meeting.test.js +87 -1
  23. package/esm/domain/__tests__/MeetingAuthorization.test.js +109 -0
  24. package/esm/index.js +300 -36
  25. package/esm/service/CallApi.js +170 -4
  26. package/esm/service/getApiClient.js +176 -5
  27. package/esm/simple/Auth.js +301 -37
  28. package/esm/simple/Configuration.js +300 -36
  29. package/esm/simple/Directory.js +170 -4
  30. package/esm/simple/Phone.js +300 -36
  31. package/esm/simple/Softphone.js +5 -0
  32. package/esm/simple/Websocket.js +3 -0
  33. package/esm/simple/index.js +300 -36
  34. package/esm/simple/room/LocalParticipant.js +300 -36
  35. package/esm/simple/room/Participant.js +300 -36
  36. package/esm/simple/room/RemoteParticipant.js +300 -36
  37. package/esm/simple/room/Room.js +300 -36
  38. package/esm/simple/room/SipRoom.js +300 -36
  39. package/esm/simple/room/Stream.js +300 -36
  40. package/esm/simple/room/__tests__/Participant.test.js +14812 -0
  41. package/esm/simple/room/__tests__/RemoteParticipant.test.js +300 -36
  42. package/esm/simple/utils.js +300 -36
  43. package/esm/utils/__tests__/object.test.js +57 -0
  44. package/esm/utils/__tests__/string.test.js +30 -0
  45. package/esm/utils/object.js +24 -0
  46. package/esm/utils/string.js +10 -0
  47. package/esm/web-rtc-client.js +202 -24
  48. package/esm/websocket-client.js +3 -1
  49. package/lib/__tests__/api-client.test.js +163 -2
  50. package/lib/__tests__/web-rtc-client.test.js +248 -27
  51. package/lib/api/auth.js +12 -0
  52. package/lib/api/calld.js +8 -0
  53. package/lib/api/confd.js +134 -2
  54. package/lib/api/ctid-ng.js +1 -0
  55. package/lib/api-client.js +163 -2
  56. package/lib/checker/Checker.js +204 -24
  57. package/lib/checker/checks/aor.js +163 -2
  58. package/lib/checker/checks/api.js +163 -2
  59. package/lib/checker/checks/index.js +204 -24
  60. package/lib/checker/checks/wazo-websocket.js +2 -0
  61. package/lib/checker/checks/webrtc-transport.js +202 -24
  62. package/lib/checker/checks/webrtc.js +202 -24
  63. package/lib/domain/AdHocAPIConference.js +170 -4
  64. package/lib/domain/Features.js +170 -4
  65. package/lib/domain/Meeting.js +18 -0
  66. package/lib/domain/MeetingAuthorization.js +79 -0
  67. package/lib/domain/Phone/CTIPhone.js +170 -4
  68. package/lib/domain/Phone/WebRTCPhone.js +2 -3
  69. package/lib/domain/__tests__/Meeting.test.js +87 -1
  70. package/lib/domain/__tests__/MeetingAuthorization.test.js +111 -0
  71. package/lib/index.js +300 -36
  72. package/lib/service/CallApi.js +170 -4
  73. package/lib/service/getApiClient.js +176 -4
  74. package/lib/simple/Auth.js +301 -36
  75. package/lib/simple/Configuration.js +300 -36
  76. package/lib/simple/Directory.js +170 -4
  77. package/lib/simple/Phone.js +300 -36
  78. package/lib/simple/Softphone.js +5 -0
  79. package/lib/simple/Websocket.js +3 -0
  80. package/lib/simple/index.js +300 -36
  81. package/lib/simple/room/LocalParticipant.js +300 -36
  82. package/lib/simple/room/Participant.js +300 -36
  83. package/lib/simple/room/RemoteParticipant.js +300 -36
  84. package/lib/simple/room/Room.js +300 -36
  85. package/lib/simple/room/SipRoom.js +300 -36
  86. package/lib/simple/room/Stream.js +300 -36
  87. package/lib/simple/room/__tests__/Participant.test.js +14822 -0
  88. package/lib/simple/room/__tests__/RemoteParticipant.test.js +300 -36
  89. package/lib/simple/utils.js +300 -36
  90. package/lib/utils/__tests__/object.test.js +59 -0
  91. package/lib/utils/__tests__/string.test.js +32 -0
  92. package/lib/utils/object.js +28 -0
  93. package/lib/utils/string.js +14 -0
  94. package/lib/web-rtc-client.js +202 -24
  95. package/lib/websocket-client.js +3 -0
  96. package/package.json +1 -1
  97. package/src/__tests__/web-rtc-client.test.js +46 -3
  98. package/src/api/auth.js +12 -0
  99. package/src/api/calld.js +8 -0
  100. package/src/api/confd.js +43 -2
  101. package/src/api-client.js +8 -0
  102. package/src/domain/Meeting.js +20 -0
  103. package/src/domain/MeetingAuthorization.js +67 -0
  104. package/src/domain/Phone/WebRTCPhone.js +1 -3
  105. package/src/domain/__tests__/Meeting.test.js +70 -1
  106. package/src/domain/__tests__/MeetingAuthorization.test.js +58 -0
  107. package/src/service/getApiClient.js +13 -2
  108. package/src/simple/Auth.js +35 -4
  109. package/src/simple/Softphone.js +5 -0
  110. package/src/simple/index.js +2 -1
  111. package/src/simple/room/Participant.js +40 -0
  112. package/src/simple/room/Room.js +2 -2
  113. package/src/simple/room/SipRoom.js +1 -1
  114. package/src/simple/room/__tests__/Participant.test.js +81 -0
  115. package/src/types/WebSocketMessage.js +7 -1
  116. package/src/utils/__tests__/object.test.js +35 -0
  117. package/src/utils/__tests__/string.test.js +23 -0
  118. package/src/utils/object.js +15 -0
  119. package/src/utils/string.js +8 -0
  120. package/src/web-rtc-client.js +39 -22
  121. package/src/websocket-client.js +2 -0
@@ -2795,6 +2795,7 @@ var authMethods = (client , baseUrl ) => ({
2795
2795
 
2796
2796
 
2797
2797
 
2798
+
2798
2799
  ) {
2799
2800
  const body = {
2800
2801
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2815,9 +2816,14 @@ var authMethods = (client , baseUrl ) => ({
2815
2816
  }
2816
2817
 
2817
2818
  if (params.tenantId) {
2819
+ console.warn('Use of `tenantId` is deprecated when calling logIn() method, use `domainName` instead.');
2818
2820
  body.tenant_id = params.tenantId;
2819
2821
  }
2820
2822
 
2823
+ if (params.domainName) {
2824
+ body.domain_name = params.domainName;
2825
+ }
2826
+
2821
2827
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2822
2828
  },
2823
2829
 
@@ -2830,6 +2836,7 @@ var authMethods = (client , baseUrl ) => ({
2830
2836
  expiration ,
2831
2837
  isMobile = false,
2832
2838
  tenantId ,
2839
+ domainName ,
2833
2840
  ) => {
2834
2841
  const body = {
2835
2842
  backend: backend || DEFAULT_BACKEND_USER,
@@ -2839,9 +2846,14 @@ var authMethods = (client , baseUrl ) => ({
2839
2846
  };
2840
2847
 
2841
2848
  if (tenantId) {
2849
+ console.warn('Use of `tenantId` is deprecated when calling refreshToken() method, use `domainName` instead.');
2842
2850
  body.tenant_id = tenantId;
2843
2851
  }
2844
2852
 
2853
+ if (domainName) {
2854
+ body.domain_name = domainName;
2855
+ }
2856
+
2845
2857
  const headers = {
2846
2858
  'Content-Type': 'application/json',
2847
2859
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -3211,6 +3223,70 @@ class ExternalApp {
3211
3223
 
3212
3224
  //
3213
3225
 
3226
+ class MeetingAuthorization {
3227
+
3228
+
3229
+
3230
+
3231
+
3232
+
3233
+ constructor({
3234
+ meetingUuid,
3235
+ uuid,
3236
+ userUuid,
3237
+ userName,
3238
+ } = {}) {
3239
+ this.meetingUuid = meetingUuid;
3240
+ this.uuid = uuid;
3241
+ this.userUuid = userUuid;
3242
+ this.userName = userName;
3243
+ }
3244
+
3245
+ setStatus(status ) {
3246
+ this.status = status;
3247
+ }
3248
+
3249
+ getStatus() {
3250
+ return this.status;
3251
+ }
3252
+
3253
+ static parse(plain ) {
3254
+ const {
3255
+ meeting_uuid: meetingUuid,
3256
+ uuid,
3257
+ guest_uuid: userUuid,
3258
+ guest_name: userName,
3259
+ } = plain;
3260
+
3261
+ return new MeetingAuthorization({
3262
+ meetingUuid,
3263
+ uuid,
3264
+ userUuid,
3265
+ userName,
3266
+ });
3267
+ }
3268
+
3269
+ static parseMany(items ) {
3270
+ if (!items) {
3271
+ return [];
3272
+ }
3273
+ return items.map(MeetingAuthorization.parse);
3274
+ }
3275
+ }
3276
+
3277
+ //
3278
+
3279
+
3280
+
3281
+
3282
+
3283
+
3284
+
3285
+
3286
+
3287
+
3288
+
3289
+
3214
3290
 
3215
3291
 
3216
3292
 
@@ -3221,6 +3297,7 @@ class ExternalApp {
3221
3297
 
3222
3298
 
3223
3299
 
3300
+
3224
3301
 
3225
3302
 
3226
3303
  class Meeting {
@@ -3235,6 +3312,8 @@ class Meeting {
3235
3312
 
3236
3313
 
3237
3314
 
3315
+
3316
+
3238
3317
 
3239
3318
  static parse(plain ) {
3240
3319
  return new Meeting({
@@ -3247,6 +3326,7 @@ class Meeting {
3247
3326
  extension: plain.exten,
3248
3327
  persistent: plain.persistent,
3249
3328
  creationTime: moment__default['default'](plain.creation_time).toDate(),
3329
+ requireAuthorization: plain.require_authorization,
3250
3330
  });
3251
3331
  }
3252
3332
 
@@ -3271,6 +3351,7 @@ class Meeting {
3271
3351
  extension,
3272
3352
  persistent,
3273
3353
  creationTime,
3354
+ requireAuthorization,
3274
3355
  } = {}) {
3275
3356
  this.guestSipAuthorization = guestSipAuthorization;
3276
3357
  this.uri = uri;
@@ -3281,6 +3362,7 @@ class Meeting {
3281
3362
  this.extension = extension;
3282
3363
  this.persistent = persistent;
3283
3364
  this.creationTime = creationTime;
3365
+ this.requireAuthorization = requireAuthorization;
3284
3366
 
3285
3367
  // Useful to compare instead of instanceof with minified code
3286
3368
  this.type = 'Meeting';
@@ -3291,8 +3373,32 @@ class Meeting {
3291
3373
  const [username, secret] = atob(this.guestSipAuthorization).split(':');
3292
3374
  return { username, secret };
3293
3375
  }
3376
+
3294
3377
  }
3295
3378
 
3379
+ //
3380
+
3381
+ const camelToUnderscore = (key ) => {
3382
+ if (typeof key !== 'string') {
3383
+ throw new Error('Input is not a string');
3384
+ }
3385
+ return key.charAt(0).toLowerCase() + key.substring(1).replace(/([A-Z])/g, '_$1').toLowerCase();
3386
+ };
3387
+
3388
+ //
3389
+
3390
+ const convertKeysFromCamelToUnderscore = (args ) => {
3391
+ if (!args || typeof args !== 'object' || Array.isArray(args)) {
3392
+ throw new Error('Input is not an object');
3393
+ }
3394
+
3395
+ return Object.keys(args).reduce((acc, key) => {
3396
+ acc[camelToUnderscore(key)] = typeof args[key] === 'object' && !Array.isArray(args[key])
3397
+ ? convertKeysFromCamelToUnderscore(args[key]) : args[key];
3398
+ return acc;
3399
+ }, {});
3400
+ };
3401
+
3296
3402
  /* */
3297
3403
 
3298
3404
  var confdMethods = (client , baseUrl ) => ({
@@ -3361,8 +3467,18 @@ var confdMethods = (client , baseUrl ) => ({
3361
3467
  getMyMeetings: () =>
3362
3468
  client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
3363
3469
 
3364
- createMyMeeting: (name , persistent ) =>
3365
- client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
3470
+ createMyMeeting: (args ) =>
3471
+ client
3472
+ .post(`${baseUrl}/users/me/meetings`, convertKeysFromCamelToUnderscore(args))
3473
+ .then(Meeting.parse),
3474
+
3475
+ updateMyMeeting: (meetingUuid , data ) =>
3476
+ client.put(
3477
+ `${baseUrl}/users/me/meetings/${meetingUuid}`,
3478
+ convertKeysFromCamelToUnderscore(data),
3479
+ null,
3480
+ ApiRequester.successResponseParser,
3481
+ ),
3366
3482
 
3367
3483
  deleteMyMeeting: (meetingUuid ) =>
3368
3484
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -3370,8 +3486,36 @@ var confdMethods = (client , baseUrl ) => ({
3370
3486
  getMeeting: (meetingUuid ) =>
3371
3487
  client.get(`${baseUrl}/meetings/${meetingUuid}`, null).then(Meeting.parse),
3372
3488
 
3489
+ meetingAuthorizations: (meetingUuid ) =>
3490
+ client.get(`${baseUrl}/users/me/meetings/${meetingUuid}/authorizations`, null).then(MeetingAuthorization.parseMany),
3491
+
3492
+ meetingAuthorizationReject: (meetingUuid , authorizationUuid ) =>
3493
+ client.put(
3494
+ `${baseUrl}/users/me/meetings/${meetingUuid}/authorizations/${authorizationUuid}/reject`,
3495
+ {},
3496
+ null,
3497
+ ApiRequester.successResponseParser,
3498
+ ),
3499
+
3500
+ meetingAuthorizationAccept: (meetingUuid , authorizationUuid ) =>
3501
+ client.put(
3502
+ `${baseUrl}/users/me/meetings/${meetingUuid}/authorizations/${authorizationUuid}/accept`,
3503
+ {},
3504
+ null,
3505
+ ApiRequester.successResponseParser,
3506
+ ),
3507
+
3373
3508
  guestGetMeeting: (meetingUuid ) =>
3374
3509
  client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}`, null).then(Meeting.parse),
3510
+
3511
+ guestAuthorizationRequest: (userUuid , meetingUuid , username ) =>
3512
+ client
3513
+ .post(`${baseUrl}/guests/${userUuid}/meetings/${meetingUuid}/authorizations`, { guest_name: username })
3514
+ .then(MeetingAuthorization.parse),
3515
+
3516
+ guestAuthorizationCheck: (userUuid , meetingUuid , authorizationUuid ) =>
3517
+ client.get(`${baseUrl}/guests/${userUuid}/meetings/${meetingUuid}/authorizations/${authorizationUuid}`, null),
3518
+
3375
3519
  });
3376
3520
 
3377
3521
  //
@@ -4136,6 +4280,7 @@ global.wazoClientId = global.wazoClientId || {};
4136
4280
  global.wazoClientToken = global.wazoClientToken || {};
4137
4281
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4138
4282
  global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4283
+ global.wazoRefreshDomainName = global.wazoRefreshDomainName || {};
4139
4284
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4140
4285
  global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4141
4286
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
@@ -4810,6 +4955,14 @@ var calldMethods = (client , baseUrl ) => ({
4810
4955
  getMeetingParticipantsAsUser: async (meetingUuid ) =>
4811
4956
  client.get(`${baseUrl}/users/me/meetings/${meetingUuid}/participants`),
4812
4957
 
4958
+ banMeetingParticipant: (meetingUuid , participantUuid ) =>
4959
+ client.delete(
4960
+ `${baseUrl}/users/me/meetings/${meetingUuid}/participants/${participantUuid}`,
4961
+ null,
4962
+ null,
4963
+ ApiRequester.successResponseParser,
4964
+ ),
4965
+
4813
4966
  listTrunks: () => client.get(`${baseUrl}/trunks`),
4814
4967
 
4815
4968
  mute: (callId ) =>
@@ -5187,6 +5340,7 @@ class ApiClient {
5187
5340
 
5188
5341
 
5189
5342
 
5343
+
5190
5344
 
5191
5345
 
5192
5346
 
@@ -5228,6 +5382,7 @@ class ApiClient {
5228
5382
  refreshToken: this.refreshToken,
5229
5383
  refreshBackend: this.refreshBackend,
5230
5384
  refreshTenantId: this.refreshTenantId,
5385
+ refreshDomainName: this.refreshDomainName,
5231
5386
  refreshExpiration: this.refreshExpiration,
5232
5387
  isMobile: this.isMobile,
5233
5388
  });
@@ -5243,6 +5398,7 @@ class ApiClient {
5243
5398
  this.refreshExpiration,
5244
5399
  this.isMobile,
5245
5400
  this.refreshTenantId,
5401
+ this.refreshDomainName,
5246
5402
  );
5247
5403
 
5248
5404
  logger$1.info('token refreshed', { token: session.token });
@@ -5296,9 +5452,14 @@ class ApiClient {
5296
5452
  }
5297
5453
 
5298
5454
  setRefreshTenantId(tenantId ) {
5455
+ console.warn('Use of `setRefreshTenantId` is deprecated, use `setRefreshDomainName` instead');
5299
5456
  this.refreshTenantId = tenantId;
5300
5457
  }
5301
5458
 
5459
+ setRefreshDomainName(domainName ) {
5460
+ this.refreshDomainName = domainName;
5461
+ }
5462
+
5302
5463
  setIsMobile(isMobile ) {
5303
5464
  this.isMobile = isMobile;
5304
5465
  }
@@ -6450,7 +6611,7 @@ class WebRTCClient extends Emitter {
6450
6611
  });
6451
6612
  }
6452
6613
 
6453
- changeAudioInputDevice(id , session , force ) {
6614
+ async changeAudioInputDevice(id , session , force ) {
6454
6615
  const currentId = this.getAudioDeviceId();
6455
6616
  logger.info('setting audio input device', { id, currentId, session: !!session });
6456
6617
 
@@ -6458,33 +6619,50 @@ class WebRTCClient extends Emitter {
6458
6619
  return null;
6459
6620
  }
6460
6621
 
6622
+ // in order to handle an audio track change for default devices
6623
+ // we need the actual id of the device (not 'default')
6624
+ let deviceId = id;
6625
+ if (id === 'default' && navigator.mediaDevices) {
6626
+ const devices = await navigator.mediaDevices.enumerateDevices();
6627
+ const defaultDevice = devices.find(device => device.deviceId === 'default');
6628
+ if (defaultDevice) {
6629
+ const deviceLabel = defaultDevice.label.replace('Default - ', '');
6630
+ const targetDevice = devices.find(device => device.label === deviceLabel);
6631
+ if (targetDevice) {
6632
+ deviceId = targetDevice.deviceId;
6633
+ if (!force && deviceId === currentId) {
6634
+ return null;
6635
+ }
6636
+ }
6637
+ }
6638
+ }
6639
+
6461
6640
  // let's update the local audio value
6462
6641
  if (this.audio) {
6463
6642
  this.audio = {
6464
6643
  deviceId: {
6465
- exact: id,
6644
+ exact: deviceId,
6466
6645
  },
6467
6646
  };
6468
6647
  }
6469
6648
 
6470
- if (session) {
6649
+ if (session && navigator.mediaDevices) {
6471
6650
  const sdh = session.sessionDescriptionHandler;
6472
6651
  const pc = sdh.peerConnection;
6473
6652
 
6474
- // $FlowFixMe
6475
- return navigator.mediaDevices.getUserMedia({ audio: { deviceId: { exact: id } } }).then(async stream => {
6476
- const audioTrack = stream.getAudioTracks()[0];
6477
- const sender = pc && pc.getSenders().find(s => audioTrack && s && s.track && s.track.kind === audioTrack.kind);
6653
+ const constraints = { audio: { deviceId: { exact: deviceId } } };
6654
+ const stream = await navigator.mediaDevices.getUserMedia(constraints);
6655
+ const audioTrack = stream.getAudioTracks()[0];
6656
+ const sender = pc && pc.getSenders().find(s => audioTrack && s && s.track && s.track.kind === audioTrack.kind);
6478
6657
 
6479
- if (sender) {
6480
- if (sender.track) {
6481
- audioTrack.enabled = sender.track.enabled;
6482
- }
6483
- sender.replaceTrack(audioTrack);
6658
+ if (sender) {
6659
+ if (sender.track) {
6660
+ audioTrack.enabled = sender.track.enabled;
6484
6661
  }
6662
+ sender.replaceTrack(audioTrack);
6663
+ }
6485
6664
 
6486
- return stream;
6487
- });
6665
+ return stream;
6488
6666
  }
6489
6667
  }
6490
6668
 
@@ -6504,14 +6682,14 @@ class WebRTCClient extends Emitter {
6504
6682
  return null;
6505
6683
  }
6506
6684
 
6507
- // let's update the local video value
6508
- if (this.video) {
6509
- this.video = {
6510
- deviceId: {
6511
- exact: id,
6512
- },
6513
- };
6514
- }
6685
+ // let's make sure we don't lose other video constraints settings -- width, height, frameRate...
6686
+ const videoObject = typeof this.video === 'object' ? this.video : {};
6687
+ this.video = {
6688
+ ...videoObject,
6689
+ deviceId: {
6690
+ exact: id,
6691
+ },
6692
+ };
6515
6693
  }
6516
6694
 
6517
6695
  changeSessionVideoInputDevice(id , session ) {