@wazo/sdk 0.38.9 → 0.38.12

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 (78) hide show
  1. package/dist/wazo-sdk.js +2 -2
  2. package/esm/__tests__/api-client.test.js +21 -0
  3. package/esm/__tests__/web-rtc-client.test.js +32 -7
  4. package/esm/api/auth.js +12 -0
  5. package/esm/api/ctid-ng.js +1 -0
  6. package/esm/api-client.js +21 -0
  7. package/esm/checker/Checker.js +32 -7
  8. package/esm/checker/checks/aor.js +21 -0
  9. package/esm/checker/checks/api.js +21 -0
  10. package/esm/checker/checks/index.js +32 -7
  11. package/esm/checker/checks/webrtc-transport.js +32 -7
  12. package/esm/checker/checks/webrtc.js +32 -7
  13. package/esm/domain/AdHocAPIConference.js +28 -2
  14. package/esm/domain/Features.js +28 -2
  15. package/esm/domain/Phone/CTIPhone.js +28 -2
  16. package/esm/domain/Phone/WebRTCPhone.js +3 -2
  17. package/esm/index.js +86 -15
  18. package/esm/service/CallApi.js +28 -2
  19. package/esm/service/getApiClient.js +34 -3
  20. package/esm/simple/Auth.js +87 -16
  21. package/esm/simple/Configuration.js +86 -15
  22. package/esm/simple/Directory.js +28 -2
  23. package/esm/simple/Phone.js +86 -15
  24. package/esm/simple/Softphone.js +5 -0
  25. package/esm/simple/index.js +86 -15
  26. package/esm/simple/room/LocalParticipant.js +86 -15
  27. package/esm/simple/room/Participant.js +86 -15
  28. package/esm/simple/room/RemoteParticipant.js +86 -15
  29. package/esm/simple/room/Room.js +86 -15
  30. package/esm/simple/room/SipRoom.js +86 -15
  31. package/esm/simple/room/Stream.js +86 -15
  32. package/esm/simple/room/__tests__/Participant.test.js +86 -15
  33. package/esm/simple/room/__tests__/RemoteParticipant.test.js +86 -15
  34. package/esm/simple/utils.js +86 -15
  35. package/esm/web-rtc-client.js +32 -7
  36. package/lib/__tests__/api-client.test.js +21 -0
  37. package/lib/__tests__/web-rtc-client.test.js +32 -7
  38. package/lib/api/auth.js +12 -0
  39. package/lib/api/ctid-ng.js +1 -0
  40. package/lib/api-client.js +21 -0
  41. package/lib/checker/Checker.js +32 -7
  42. package/lib/checker/checks/aor.js +21 -0
  43. package/lib/checker/checks/api.js +21 -0
  44. package/lib/checker/checks/index.js +32 -7
  45. package/lib/checker/checks/webrtc-transport.js +32 -7
  46. package/lib/checker/checks/webrtc.js +32 -7
  47. package/lib/domain/AdHocAPIConference.js +28 -2
  48. package/lib/domain/Features.js +28 -2
  49. package/lib/domain/Phone/CTIPhone.js +28 -2
  50. package/lib/domain/Phone/WebRTCPhone.js +3 -2
  51. package/lib/index.js +86 -15
  52. package/lib/service/CallApi.js +28 -2
  53. package/lib/service/getApiClient.js +34 -2
  54. package/lib/simple/Auth.js +87 -15
  55. package/lib/simple/Configuration.js +86 -15
  56. package/lib/simple/Directory.js +28 -2
  57. package/lib/simple/Phone.js +86 -15
  58. package/lib/simple/Softphone.js +5 -0
  59. package/lib/simple/index.js +86 -15
  60. package/lib/simple/room/LocalParticipant.js +86 -15
  61. package/lib/simple/room/Participant.js +86 -15
  62. package/lib/simple/room/RemoteParticipant.js +86 -15
  63. package/lib/simple/room/Room.js +86 -15
  64. package/lib/simple/room/SipRoom.js +86 -15
  65. package/lib/simple/room/Stream.js +86 -15
  66. package/lib/simple/room/__tests__/Participant.test.js +86 -15
  67. package/lib/simple/room/__tests__/RemoteParticipant.test.js +86 -15
  68. package/lib/simple/utils.js +86 -15
  69. package/lib/web-rtc-client.js +32 -7
  70. package/package.json +2 -2
  71. package/src/api/auth.js +12 -0
  72. package/src/api-client.js +8 -0
  73. package/src/domain/Phone/WebRTCPhone.js +2 -2
  74. package/src/service/getApiClient.js +13 -2
  75. package/src/simple/Auth.js +35 -4
  76. package/src/simple/Softphone.js +5 -0
  77. package/src/simple/index.js +2 -1
  78. package/src/web-rtc-client.js +11 -7
@@ -2241,6 +2241,7 @@ var authMethods = (client , baseUrl ) => ({
2241
2241
 
2242
2242
 
2243
2243
 
2244
+
2244
2245
  ) {
2245
2246
  const body = {
2246
2247
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2261,9 +2262,14 @@ var authMethods = (client , baseUrl ) => ({
2261
2262
  }
2262
2263
 
2263
2264
  if (params.tenantId) {
2265
+ console.warn('Use of `tenantId` is deprecated when calling logIn() method, use `domainName` instead.');
2264
2266
  body.tenant_id = params.tenantId;
2265
2267
  }
2266
2268
 
2269
+ if (params.domainName) {
2270
+ body.domain_name = params.domainName;
2271
+ }
2272
+
2267
2273
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2268
2274
  },
2269
2275
 
@@ -2276,6 +2282,7 @@ var authMethods = (client , baseUrl ) => ({
2276
2282
  expiration ,
2277
2283
  isMobile = false,
2278
2284
  tenantId ,
2285
+ domainName ,
2279
2286
  ) => {
2280
2287
  const body = {
2281
2288
  backend: backend || DEFAULT_BACKEND_USER,
@@ -2285,9 +2292,14 @@ var authMethods = (client , baseUrl ) => ({
2285
2292
  };
2286
2293
 
2287
2294
  if (tenantId) {
2295
+ console.warn('Use of `tenantId` is deprecated when calling refreshToken() method, use `domainName` instead.');
2288
2296
  body.tenant_id = tenantId;
2289
2297
  }
2290
2298
 
2299
+ if (domainName) {
2300
+ body.domain_name = domainName;
2301
+ }
2302
+
2291
2303
  const headers = {
2292
2304
  'Content-Type': 'application/json',
2293
2305
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -5585,6 +5597,7 @@ class ApiClient {
5585
5597
 
5586
5598
 
5587
5599
 
5600
+
5588
5601
 
5589
5602
 
5590
5603
 
@@ -5626,6 +5639,7 @@ class ApiClient {
5626
5639
  refreshToken: this.refreshToken,
5627
5640
  refreshBackend: this.refreshBackend,
5628
5641
  refreshTenantId: this.refreshTenantId,
5642
+ refreshDomainName: this.refreshDomainName,
5629
5643
  refreshExpiration: this.refreshExpiration,
5630
5644
  isMobile: this.isMobile,
5631
5645
  });
@@ -5641,6 +5655,7 @@ class ApiClient {
5641
5655
  this.refreshExpiration,
5642
5656
  this.isMobile,
5643
5657
  this.refreshTenantId,
5658
+ this.refreshDomainName,
5644
5659
  );
5645
5660
 
5646
5661
  logger$a.info('token refreshed', { token: session.token });
@@ -5694,9 +5709,14 @@ class ApiClient {
5694
5709
  }
5695
5710
 
5696
5711
  setRefreshTenantId(tenantId ) {
5712
+ console.warn('Use of `setRefreshTenantId` is deprecated, use `setRefreshDomainName` instead');
5697
5713
  this.refreshTenantId = tenantId;
5698
5714
  }
5699
5715
 
5716
+ setRefreshDomainName(domainName ) {
5717
+ this.refreshDomainName = domainName;
5718
+ }
5719
+
5700
5720
  setIsMobile(isMobile ) {
5701
5721
  this.isMobile = isMobile;
5702
5722
  }
@@ -5721,6 +5741,7 @@ global.wazoClientId = global.wazoClientId || {};
5721
5741
  global.wazoClientToken = global.wazoClientToken || {};
5722
5742
  global.wazoRefreshToken = global.wazoRefreshToken || {};
5723
5743
  global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
5744
+ global.wazoRefreshDomainName = global.wazoRefreshDomainName || {};
5724
5745
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
5725
5746
  global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
5726
5747
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
@@ -5745,9 +5766,14 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
5745
5766
  };
5746
5767
 
5747
5768
  const setRefreshTenantId = (refreshTenantId , forServer = null) => {
5769
+ console.warn('Use of `setRefreshTenantId` is deprecated, please use `setRefreshDomainName` instead');
5748
5770
  global.wazoRefreshTenantId[forServer] = refreshTenantId;
5749
5771
  };
5750
5772
 
5773
+ const setRefreshDomainName = (refreshDomainName , forServer = null) => {
5774
+ global.wazoRefreshDomainName[forServer] = refreshDomainName;
5775
+ };
5776
+
5751
5777
  const setOnRefreshToken = (onRefreshToken , forServer = null) => {
5752
5778
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
5753
5779
  };
@@ -5766,6 +5792,7 @@ const setFetchOptions = (fetchOptions , forServer = null) => {
5766
5792
 
5767
5793
  const fillClient = (apiClient ) => {
5768
5794
  const { server, token, clientId } = apiClient.client;
5795
+ const tenantId = global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId;
5769
5796
 
5770
5797
  // try with null server when dealing with non-related server info
5771
5798
  apiClient.setToken(global.wazoClientToken[server] || global.wazoClientToken[null] || token);
@@ -5774,8 +5801,12 @@ const fillClient = (apiClient ) => {
5774
5801
 
5775
5802
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
5776
5803
 
5777
- apiClient.setRefreshTenantId(
5778
- global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
5804
+ if (tenantId) {
5805
+ apiClient.setRefreshTenantId(tenantId);
5806
+ }
5807
+
5808
+ apiClient.setRefreshDomainName(
5809
+ global.wazoRefreshDomainName[server] || global.wazoRefreshDomainName[null] || apiClient.refreshDomainName,
5779
5810
  );
5780
5811
 
5781
5812
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
@@ -5817,6 +5848,7 @@ var getApiClient = (forServer = null) => {
5817
5848
  class InvalidSubscription extends Error {}
5818
5849
  class InvalidAuthorization extends Error {}
5819
5850
  class NoTenantIdError extends Error {}
5851
+ class NoDomainNameError extends Error {}
5820
5852
 
5821
5853
  const logger$9 = IssueReporter$1.loggerFor('simple-auth');
5822
5854
 
@@ -5880,9 +5912,24 @@ class Auth {
5880
5912
  setFetchOptions(options);
5881
5913
  }
5882
5914
 
5883
- async logIn(username , password , backend , tenantId ) {
5884
- if (backend && backend !== this.BACKEND_WAZO && !tenantId) {
5885
- throw new NoTenantIdError('No tenant id');
5915
+ async logIn(username , password , backend , extra ) {
5916
+ let tenantId = null;
5917
+ let domainName = null;
5918
+ if (typeof extra === 'string') {
5919
+ tenantId = extra;
5920
+ }
5921
+ if (extra && typeof extra === 'object') {
5922
+ domainName = extra.domainName;
5923
+ }
5924
+
5925
+ if (backend && backend !== this.BACKEND_WAZO && !tenantId && !domainName) {
5926
+ if (!tenantId) {
5927
+ throw new NoTenantIdError('No tenant id');
5928
+ }
5929
+
5930
+ if (!domainName) {
5931
+ throw new NoDomainNameError('No domain name');
5932
+ }
5886
5933
  }
5887
5934
 
5888
5935
  this.authenticated = false;
@@ -5892,6 +5939,7 @@ class Auth {
5892
5939
  password,
5893
5940
  backend,
5894
5941
  tenantId,
5942
+ domainName,
5895
5943
  expiration: this.expiration,
5896
5944
  mobile: this.mobile,
5897
5945
  });
@@ -5900,7 +5948,13 @@ class Auth {
5900
5948
  getApiClient().setRefreshBackend(backend);
5901
5949
  }
5902
5950
 
5903
- getApiClient().setRefreshTenantId(tenantId);
5951
+ if (tenantId) {
5952
+ getApiClient().setRefreshTenantId(tenantId);
5953
+ }
5954
+
5955
+ if (domainName) {
5956
+ getApiClient().setRefreshDomainName(domainName);
5957
+ }
5904
5958
 
5905
5959
  return this._onAuthenticated(rawSession);
5906
5960
  }
@@ -5999,11 +6053,18 @@ class Auth {
5999
6053
  }
6000
6054
 
6001
6055
  setRefreshTenantId(refreshTenantId ) {
6056
+ console.warn('Use of `setRefreshTenantId` is deprecated, use `setRefreshDomainName` instead.');
6002
6057
  setRefreshTenantId(refreshTenantId);
6003
6058
 
6004
6059
  getApiClient().setRefreshTenantId(refreshTenantId);
6005
6060
  }
6006
6061
 
6062
+ setRefreshDomainName(domainName ) {
6063
+ setRefreshDomainName(domainName);
6064
+
6065
+ getApiClient().setRefreshDomainName(domainName);
6066
+ }
6067
+
6007
6068
  forceRefreshToken() {
6008
6069
  getApiClient().forceRefreshToken();
6009
6070
  }
@@ -7732,7 +7793,7 @@ class WebRTCClient extends Emitter {
7732
7793
 
7733
7794
  videoSender = transceiverIdx !== -1 ? transceivers[transceiverIdx].sender : null;
7734
7795
  } else {
7735
- videoSender = pc.getSenders().find(sender => sender.track === null);
7796
+ videoSender = pc && pc.getSenders && pc.getSenders().find(sender => sender.track === null);
7736
7797
  }
7737
7798
 
7738
7799
  if (!videoSender) {
@@ -7773,9 +7834,11 @@ class WebRTCClient extends Emitter {
7773
7834
  const videoTracks = localStream.getVideoTracks();
7774
7835
 
7775
7836
  // Remove video senders
7776
- pc.getSenders().filter(sender => sender.track && sender.track.kind === 'video').forEach(videoSender => {
7777
- videoSender.replaceTrack(null);
7778
- });
7837
+ if (pc.getSenders) {
7838
+ pc.getSenders().filter(sender => sender.track && sender.track.kind === 'video').forEach(videoSender => {
7839
+ videoSender.replaceTrack(null);
7840
+ });
7841
+ }
7779
7842
 
7780
7843
  videoTracks.forEach(videoTrack => {
7781
7844
  videoTrack.enabled = false;
@@ -8008,7 +8071,8 @@ class WebRTCClient extends Emitter {
8008
8071
  const constraints = { audio: { deviceId: { exact: deviceId } } };
8009
8072
  const stream = await navigator.mediaDevices.getUserMedia(constraints);
8010
8073
  const audioTrack = stream.getAudioTracks()[0];
8011
- const sender = pc && pc.getSenders().find(s => audioTrack && s && s.track && s.track.kind === audioTrack.kind);
8074
+ const sender = pc && pc.getSenders
8075
+ && pc.getSenders().find(s => audioTrack && s && s.track && s.track.kind === audioTrack.kind);
8012
8076
 
8013
8077
  if (sender) {
8014
8078
  if (sender.track) {
@@ -8071,10 +8135,11 @@ class WebRTCClient extends Emitter {
8071
8135
  // $FlowFixMe
8072
8136
  return navigator.mediaDevices.getUserMedia(constraints).then(async stream => {
8073
8137
  const videoTrack = stream.getVideoTracks()[0];
8074
- let sender = pc && pc.getSenders().find(s => videoTrack && s && s.track && s.track.kind === videoTrack.kind);
8138
+ let sender = pc && pc.getSenders
8139
+ && pc.getSenders().find(s => videoTrack && s && s.track && s.track.kind === videoTrack.kind);
8075
8140
  let wasTrackEnabled = false;
8076
8141
  if (!sender) {
8077
- sender = pc && pc.getSenders().find(s => !s.track);
8142
+ sender = pc && pc.getSenders && pc.getSenders().find(s => !s.track);
8078
8143
  }
8079
8144
 
8080
8145
  if (sender) {
@@ -9608,7 +9673,7 @@ class WebRTCPhone extends Emitter {
9608
9673
  const screenTrack = screenShareStream.getVideoTracks()[0];
9609
9674
  const sipSession = this.currentSipSession;
9610
9675
  const pc = this.client.getPeerConnection(this.getSipSessionId(sipSession));
9611
- const sender = pc && pc.getSenders().find(s => s && s.track && s.track.kind === 'video');
9676
+ const sender = pc && pc.getSenders && pc.getSenders().find(s => s && s.track && s.track.kind === 'video');
9612
9677
  const localStream = this.client.getLocalStream(this.getSipSessionId(sipSession));
9613
9678
  const videoTrack = localStream ? localStream.getTracks().find(track => track.kind === 'video') : null;
9614
9679
  const hadVideo = !!videoTrack;
@@ -9690,7 +9755,7 @@ class WebRTCPhone extends Emitter {
9690
9755
  const screenTrack = screenStream.getVideoTracks()[0];
9691
9756
  const sipSessionId = this.getSipSessionId(sipSession);
9692
9757
  const pc = this.client.getPeerConnection(sipSessionId);
9693
- const sender = pc && pc.getSenders().find(s => s && s.track && s.track.kind === 'video');
9758
+ const sender = pc && pc.getSenders && pc.getSenders().find(s => s && s.track && s.track.kind === 'video');
9694
9759
 
9695
9760
  logger$7.info('WebRTC phone - on screensharing', {
9696
9761
  hadVideo,
@@ -14306,6 +14371,7 @@ class Softphone {
14306
14371
  wrapUpDuration,
14307
14372
  enableAgent = true,
14308
14373
  tenantId,
14374
+ domainName,
14309
14375
  debug = false,
14310
14376
  } = {}) {
14311
14377
  this.url = url || 'https://softphone.wazo.io';
@@ -14330,8 +14396,12 @@ class Softphone {
14330
14396
  config.port = port;
14331
14397
  }
14332
14398
  if (tenantId) {
14399
+ console.warn('Use of `tenantId` is deprecated when calling `Softphone.init()`, use `domainName` instead');
14333
14400
  config.tenantId = tenantId;
14334
14401
  }
14402
+ if (domainName) {
14403
+ config.domainName = domainName;
14404
+ }
14335
14405
  if (wrapUpDuration) {
14336
14406
  config.wrapUpDuration = wrapUpDuration;
14337
14407
  }
@@ -14652,6 +14722,7 @@ const Wazo = {
14652
14722
  CanceledCallError,
14653
14723
  SFUNotAvailableError,
14654
14724
  NoTenantIdError,
14725
+ NoDomainNameError,
14655
14726
  };
14656
14727
 
14657
14728
  if (window) {
@@ -2797,6 +2797,7 @@ var authMethods = (client , baseUrl ) => ({
2797
2797
 
2798
2798
 
2799
2799
 
2800
+
2800
2801
  ) {
2801
2802
  const body = {
2802
2803
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -2817,9 +2818,14 @@ var authMethods = (client , baseUrl ) => ({
2817
2818
  }
2818
2819
 
2819
2820
  if (params.tenantId) {
2821
+ console.warn('Use of `tenantId` is deprecated when calling logIn() method, use `domainName` instead.');
2820
2822
  body.tenant_id = params.tenantId;
2821
2823
  }
2822
2824
 
2825
+ if (params.domainName) {
2826
+ body.domain_name = params.domainName;
2827
+ }
2828
+
2823
2829
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2824
2830
  },
2825
2831
 
@@ -2832,6 +2838,7 @@ var authMethods = (client , baseUrl ) => ({
2832
2838
  expiration ,
2833
2839
  isMobile = false,
2834
2840
  tenantId ,
2841
+ domainName ,
2835
2842
  ) => {
2836
2843
  const body = {
2837
2844
  backend: backend || DEFAULT_BACKEND_USER,
@@ -2841,9 +2848,14 @@ var authMethods = (client , baseUrl ) => ({
2841
2848
  };
2842
2849
 
2843
2850
  if (tenantId) {
2851
+ console.warn('Use of `tenantId` is deprecated when calling refreshToken() method, use `domainName` instead.');
2844
2852
  body.tenant_id = tenantId;
2845
2853
  }
2846
2854
 
2855
+ if (domainName) {
2856
+ body.domain_name = domainName;
2857
+ }
2858
+
2847
2859
  const headers = {
2848
2860
  'Content-Type': 'application/json',
2849
2861
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4270,6 +4282,7 @@ global.wazoClientId = global.wazoClientId || {};
4270
4282
  global.wazoClientToken = global.wazoClientToken || {};
4271
4283
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4272
4284
  global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4285
+ global.wazoRefreshDomainName = global.wazoRefreshDomainName || {};
4273
4286
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4274
4287
  global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4275
4288
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
@@ -5329,6 +5342,7 @@ class ApiClient {
5329
5342
 
5330
5343
 
5331
5344
 
5345
+
5332
5346
 
5333
5347
 
5334
5348
 
@@ -5370,6 +5384,7 @@ class ApiClient {
5370
5384
  refreshToken: this.refreshToken,
5371
5385
  refreshBackend: this.refreshBackend,
5372
5386
  refreshTenantId: this.refreshTenantId,
5387
+ refreshDomainName: this.refreshDomainName,
5373
5388
  refreshExpiration: this.refreshExpiration,
5374
5389
  isMobile: this.isMobile,
5375
5390
  });
@@ -5385,6 +5400,7 @@ class ApiClient {
5385
5400
  this.refreshExpiration,
5386
5401
  this.isMobile,
5387
5402
  this.refreshTenantId,
5403
+ this.refreshDomainName,
5388
5404
  );
5389
5405
 
5390
5406
  logger$1.info('token refreshed', { token: session.token });
@@ -5438,9 +5454,14 @@ class ApiClient {
5438
5454
  }
5439
5455
 
5440
5456
  setRefreshTenantId(tenantId ) {
5457
+ console.warn('Use of `setRefreshTenantId` is deprecated, use `setRefreshDomainName` instead');
5441
5458
  this.refreshTenantId = tenantId;
5442
5459
  }
5443
5460
 
5461
+ setRefreshDomainName(domainName ) {
5462
+ this.refreshDomainName = domainName;
5463
+ }
5464
+
5444
5465
  setIsMobile(isMobile ) {
5445
5466
  this.isMobile = isMobile;
5446
5467
  }
@@ -6361,7 +6382,7 @@ class WebRTCClient extends Emitter {
6361
6382
 
6362
6383
  videoSender = transceiverIdx !== -1 ? transceivers[transceiverIdx].sender : null;
6363
6384
  } else {
6364
- videoSender = pc.getSenders().find(sender => sender.track === null);
6385
+ videoSender = pc && pc.getSenders && pc.getSenders().find(sender => sender.track === null);
6365
6386
  }
6366
6387
 
6367
6388
  if (!videoSender) {
@@ -6402,9 +6423,11 @@ class WebRTCClient extends Emitter {
6402
6423
  const videoTracks = localStream.getVideoTracks();
6403
6424
 
6404
6425
  // Remove video senders
6405
- pc.getSenders().filter(sender => sender.track && sender.track.kind === 'video').forEach(videoSender => {
6406
- videoSender.replaceTrack(null);
6407
- });
6426
+ if (pc.getSenders) {
6427
+ pc.getSenders().filter(sender => sender.track && sender.track.kind === 'video').forEach(videoSender => {
6428
+ videoSender.replaceTrack(null);
6429
+ });
6430
+ }
6408
6431
 
6409
6432
  videoTracks.forEach(videoTrack => {
6410
6433
  videoTrack.enabled = false;
@@ -6637,7 +6660,8 @@ class WebRTCClient extends Emitter {
6637
6660
  const constraints = { audio: { deviceId: { exact: deviceId } } };
6638
6661
  const stream = await navigator.mediaDevices.getUserMedia(constraints);
6639
6662
  const audioTrack = stream.getAudioTracks()[0];
6640
- const sender = pc && pc.getSenders().find(s => audioTrack && s && s.track && s.track.kind === audioTrack.kind);
6663
+ const sender = pc && pc.getSenders
6664
+ && pc.getSenders().find(s => audioTrack && s && s.track && s.track.kind === audioTrack.kind);
6641
6665
 
6642
6666
  if (sender) {
6643
6667
  if (sender.track) {
@@ -6700,10 +6724,11 @@ class WebRTCClient extends Emitter {
6700
6724
  // $FlowFixMe
6701
6725
  return navigator.mediaDevices.getUserMedia(constraints).then(async stream => {
6702
6726
  const videoTrack = stream.getVideoTracks()[0];
6703
- let sender = pc && pc.getSenders().find(s => videoTrack && s && s.track && s.track.kind === videoTrack.kind);
6727
+ let sender = pc && pc.getSenders
6728
+ && pc.getSenders().find(s => videoTrack && s && s.track && s.track.kind === videoTrack.kind);
6704
6729
  let wasTrackEnabled = false;
6705
6730
  if (!sender) {
6706
- sender = pc && pc.getSenders().find(s => !s.track);
6731
+ sender = pc && pc.getSenders && pc.getSenders().find(s => !s.track);
6707
6732
  }
6708
6733
 
6709
6734
  if (sender) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wazo/sdk",
3
- "version": "0.38.9",
3
+ "version": "0.38.12",
4
4
  "description": "Wazo's JavaScript Software Development Kit.",
5
5
  "main": "dist/wazo-sdk.js",
6
6
  "author": "Wazo (http://wazo.io)",
@@ -100,4 +100,4 @@
100
100
  "react-native": {
101
101
  "node-fetch/lib/index": false
102
102
  }
103
- }
103
+ }
package/src/api/auth.js CHANGED
@@ -33,6 +33,7 @@ export default (client: ApiRequester, baseUrl: string) => ({
33
33
  expiration: number,
34
34
  mobile?: boolean,
35
35
  tenantId?: string,
36
+ domainName?: string,
36
37
  }): Promise<?Session> {
37
38
  const body: Object = {
38
39
  backend: params.backend || DEFAULT_BACKEND_USER,
@@ -53,9 +54,14 @@ export default (client: ApiRequester, baseUrl: string) => ({
53
54
  }
54
55
 
55
56
  if (params.tenantId) {
57
+ console.warn('Use of `tenantId` is deprecated when calling logIn() method, use `domainName` instead.');
56
58
  body.tenant_id = params.tenantId;
57
59
  }
58
60
 
61
+ if (params.domainName) {
62
+ body.domain_name = params.domainName;
63
+ }
64
+
59
65
  return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
60
66
  },
61
67
 
@@ -68,6 +74,7 @@ export default (client: ApiRequester, baseUrl: string) => ({
68
74
  expiration: number,
69
75
  isMobile: boolean = false,
70
76
  tenantId: ?string,
77
+ domainName?: string,
71
78
  ): Promise<?Session> => {
72
79
  const body: Object = {
73
80
  backend: backend || DEFAULT_BACKEND_USER,
@@ -77,9 +84,14 @@ export default (client: ApiRequester, baseUrl: string) => ({
77
84
  };
78
85
 
79
86
  if (tenantId) {
87
+ console.warn('Use of `tenantId` is deprecated when calling refreshToken() method, use `domainName` instead.');
80
88
  body.tenant_id = tenantId;
81
89
  }
82
90
 
91
+ if (domainName) {
92
+ body.domain_name = domainName;
93
+ }
94
+
83
95
  const headers: Object = {
84
96
  'Content-Type': 'application/json',
85
97
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
package/src/api-client.js CHANGED
@@ -57,6 +57,7 @@ export default class ApiClient {
57
57
  refreshExpiration: ?number;
58
58
  refreshBackend: ?string;
59
59
  refreshTenantId: ?string;
60
+ refreshDomainName: ?string;
60
61
  isMobile: boolean;
61
62
  fetchOptions: Object;
62
63
 
@@ -98,6 +99,7 @@ export default class ApiClient {
98
99
  refreshToken: this.refreshToken,
99
100
  refreshBackend: this.refreshBackend,
100
101
  refreshTenantId: this.refreshTenantId,
102
+ refreshDomainName: this.refreshDomainName,
101
103
  refreshExpiration: this.refreshExpiration,
102
104
  isMobile: this.isMobile,
103
105
  });
@@ -113,6 +115,7 @@ export default class ApiClient {
113
115
  this.refreshExpiration,
114
116
  this.isMobile,
115
117
  this.refreshTenantId,
118
+ this.refreshDomainName,
116
119
  );
117
120
 
118
121
  logger.info('token refreshed', { token: session.token });
@@ -166,9 +169,14 @@ export default class ApiClient {
166
169
  }
167
170
 
168
171
  setRefreshTenantId(tenantId: ?string) {
172
+ console.warn('Use of `setRefreshTenantId` is deprecated, use `setRefreshDomainName` instead');
169
173
  this.refreshTenantId = tenantId;
170
174
  }
171
175
 
176
+ setRefreshDomainName(domainName: ?string) {
177
+ this.refreshDomainName = domainName;
178
+ }
179
+
172
180
  setIsMobile(isMobile: boolean) {
173
181
  this.isMobile = isMobile;
174
182
  }
@@ -493,7 +493,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
493
493
  const screenTrack = screenShareStream.getVideoTracks()[0];
494
494
  const sipSession = this.currentSipSession;
495
495
  const pc = this.client.getPeerConnection(this.getSipSessionId(sipSession));
496
- const sender = pc && pc.getSenders().find(s => s && s.track && s.track.kind === 'video');
496
+ const sender = pc && pc.getSenders && pc.getSenders().find(s => s && s.track && s.track.kind === 'video');
497
497
  const localStream = this.client.getLocalStream(this.getSipSessionId(sipSession));
498
498
  const videoTrack = localStream ? localStream.getTracks().find(track => track.kind === 'video') : null;
499
499
  const hadVideo = !!videoTrack;
@@ -575,7 +575,7 @@ export default class WebRTCPhone extends Emitter implements Phone {
575
575
  const screenTrack = screenStream.getVideoTracks()[0];
576
576
  const sipSessionId = this.getSipSessionId(sipSession);
577
577
  const pc = this.client.getPeerConnection(sipSessionId);
578
- const sender = pc && pc.getSenders().find(s => s && s.track && s.track.kind === 'video');
578
+ const sender = pc && pc.getSenders && pc.getSenders().find(s => s && s.track && s.track.kind === 'video');
579
579
 
580
580
  logger.info('WebRTC phone - on screensharing', {
581
581
  hadVideo,
@@ -11,6 +11,7 @@ global.wazoClientId = global.wazoClientId || {};
11
11
  global.wazoClientToken = global.wazoClientToken || {};
12
12
  global.wazoRefreshToken = global.wazoRefreshToken || {};
13
13
  global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
14
+ global.wazoRefreshDomainName = global.wazoRefreshDomainName || {};
14
15
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
15
16
  global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
16
17
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
@@ -35,9 +36,14 @@ export const setRefreshToken = (newRefreshToken: ?string, forServer: ?string = n
35
36
  };
36
37
 
37
38
  export const setRefreshTenantId = (refreshTenantId: ?string, forServer: ?string = null) => {
39
+ console.warn('Use of `setRefreshTenantId` is deprecated, please use `setRefreshDomainName` instead');
38
40
  global.wazoRefreshTenantId[forServer] = refreshTenantId;
39
41
  };
40
42
 
43
+ export const setRefreshDomainName = (refreshDomainName: ?string, forServer: ?string = null) => {
44
+ global.wazoRefreshDomainName[forServer] = refreshDomainName;
45
+ };
46
+
41
47
  export const setOnRefreshToken = (onRefreshToken: Function, forServer: ?string = null) => {
42
48
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
43
49
  };
@@ -64,6 +70,7 @@ export const setFetchOptions = (fetchOptions: Object, forServer: ?string = null)
64
70
 
65
71
  const fillClient = (apiClient: WazoApiClient) => {
66
72
  const { server, token, clientId } = apiClient.client;
73
+ const tenantId = global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId;
67
74
 
68
75
  // try with null server when dealing with non-related server info
69
76
  apiClient.setToken(global.wazoClientToken[server] || global.wazoClientToken[null] || token);
@@ -72,8 +79,12 @@ const fillClient = (apiClient: WazoApiClient) => {
72
79
 
73
80
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
74
81
 
75
- apiClient.setRefreshTenantId(
76
- global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
82
+ if (tenantId) {
83
+ apiClient.setRefreshTenantId(tenantId);
84
+ }
85
+
86
+ apiClient.setRefreshDomainName(
87
+ global.wazoRefreshDomainName[server] || global.wazoRefreshDomainName[null] || apiClient.refreshDomainName,
77
88
  );
78
89
 
79
90
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
@@ -11,6 +11,7 @@ import getApiClient, {
11
11
  setOnRefreshToken,
12
12
  setFetchOptions,
13
13
  setRefreshTenantId,
14
+ setRefreshDomainName,
14
15
  setOnRefreshTokenError,
15
16
  } from '../service/getApiClient';
16
17
  import IssueReporter from '../service/IssueReporter';
@@ -20,6 +21,7 @@ import Wazo from './index';
20
21
  export class InvalidSubscription extends Error {}
21
22
  export class InvalidAuthorization extends Error {}
22
23
  export class NoTenantIdError extends Error {}
24
+ export class NoDomainNameError extends Error {}
23
25
 
24
26
  const logger = IssueReporter.loggerFor('simple-auth');
25
27
 
@@ -83,9 +85,24 @@ class Auth {
83
85
  setFetchOptions(options);
84
86
  }
85
87
 
86
- async logIn(username: string, password: string, backend?: string, tenantId?: string) {
87
- if (backend && backend !== this.BACKEND_WAZO && !tenantId) {
88
- throw new NoTenantIdError('No tenant id');
88
+ async logIn(username: string, password: string, backend?: string, extra?: string | Object) {
89
+ let tenantId = null;
90
+ let domainName = null;
91
+ if (typeof extra === 'string') {
92
+ tenantId = extra;
93
+ }
94
+ if (extra && typeof extra === 'object') {
95
+ domainName = extra.domainName;
96
+ }
97
+
98
+ if (backend && backend !== this.BACKEND_WAZO && !tenantId && !domainName) {
99
+ if (!tenantId) {
100
+ throw new NoTenantIdError('No tenant id');
101
+ }
102
+
103
+ if (!domainName) {
104
+ throw new NoDomainNameError('No domain name');
105
+ }
89
106
  }
90
107
 
91
108
  this.authenticated = false;
@@ -95,6 +112,7 @@ class Auth {
95
112
  password,
96
113
  backend,
97
114
  tenantId,
115
+ domainName,
98
116
  expiration: this.expiration,
99
117
  mobile: this.mobile,
100
118
  });
@@ -103,7 +121,13 @@ class Auth {
103
121
  getApiClient().setRefreshBackend(backend);
104
122
  }
105
123
 
106
- getApiClient().setRefreshTenantId(tenantId);
124
+ if (tenantId) {
125
+ getApiClient().setRefreshTenantId(tenantId);
126
+ }
127
+
128
+ if (domainName) {
129
+ getApiClient().setRefreshDomainName(domainName);
130
+ }
107
131
 
108
132
  return this._onAuthenticated(rawSession);
109
133
  }
@@ -202,11 +226,18 @@ class Auth {
202
226
  }
203
227
 
204
228
  setRefreshTenantId(refreshTenantId: string) {
229
+ console.warn('Use of `setRefreshTenantId` is deprecated, use `setRefreshDomainName` instead.');
205
230
  setRefreshTenantId(refreshTenantId);
206
231
 
207
232
  getApiClient().setRefreshTenantId(refreshTenantId);
208
233
  }
209
234
 
235
+ setRefreshDomainName(domainName: string) {
236
+ setRefreshDomainName(domainName);
237
+
238
+ getApiClient().setRefreshDomainName(domainName);
239
+ }
240
+
210
241
  forceRefreshToken() {
211
242
  getApiClient().forceRefreshToken();
212
243
  }