@wazo/sdk 0.37.41 → 0.38.0

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 (112) hide show
  1. package/dist/wazo-sdk.js +3 -3
  2. package/esm/__tests__/api-client.test.js +45 -22
  3. package/esm/__tests__/web-rtc-client.test.js +49 -24
  4. package/esm/api/agentd.js +12 -7
  5. package/esm/api/amid.js +12 -7
  6. package/esm/api/application.js +12 -7
  7. package/esm/api/auth.js +16 -8
  8. package/esm/api/call-logd.js +12 -7
  9. package/esm/api/calld.js +12 -7
  10. package/esm/api/chatd.js +12 -7
  11. package/esm/api/confd.js +12 -7
  12. package/esm/api/ctid-ng.js +14 -7
  13. package/esm/api/dird.js +12 -7
  14. package/esm/api/webhookd.js +12 -7
  15. package/esm/api-client.js +45 -22
  16. package/esm/checker/Checker.js +50 -25
  17. package/esm/checker/checks/aor.js +45 -22
  18. package/esm/checker/checks/api.js +45 -22
  19. package/esm/checker/checks/index.js +50 -25
  20. package/esm/checker/checks/wazo-websocket.js +13 -8
  21. package/esm/checker/checks/webrtc-transport.js +49 -24
  22. package/esm/checker/checks/webrtc.js +49 -24
  23. package/esm/domain/AdHocAPIConference.js +54 -23
  24. package/esm/domain/Features.js +54 -23
  25. package/esm/domain/Phone/CTIPhone.js +54 -23
  26. package/esm/domain/Phone/WebRTCPhone.js +14 -7
  27. package/esm/index.js +233 -25
  28. package/esm/lib/WazoSessionDescriptionHandler.js +12 -7
  29. package/esm/service/CallApi.js +54 -23
  30. package/esm/service/IssueReporter.js +12 -7
  31. package/esm/service/__tests__/IssueReporter.test.js +18 -7
  32. package/esm/service/getApiClient.js +63 -24
  33. package/esm/simple/Auth.js +233 -25
  34. package/esm/simple/Configuration.js +233 -25
  35. package/esm/simple/Directory.js +54 -23
  36. package/esm/simple/Phone.js +233 -25
  37. package/esm/simple/Softphone.js +148 -0
  38. package/esm/simple/Websocket.js +13 -8
  39. package/esm/simple/index.js +233 -25
  40. package/esm/simple/room/LocalParticipant.js +233 -25
  41. package/esm/simple/room/Participant.js +233 -25
  42. package/esm/simple/room/RemoteParticipant.js +233 -25
  43. package/esm/simple/room/Room.js +233 -25
  44. package/esm/simple/room/SipRoom.js +233 -25
  45. package/esm/simple/room/Stream.js +233 -25
  46. package/esm/simple/room/__tests__/RemoteParticipant.test.js +233 -25
  47. package/esm/simple/utils.js +233 -25
  48. package/esm/utils/__tests__/api-requester.test.js +12 -7
  49. package/esm/utils/api-requester.js +12 -7
  50. package/esm/web-rtc-client.js +49 -24
  51. package/esm/websocket-client.js +13 -8
  52. package/lib/__tests__/api-client.test.js +45 -22
  53. package/lib/__tests__/web-rtc-client.test.js +49 -24
  54. package/lib/api/agentd.js +12 -7
  55. package/lib/api/amid.js +12 -7
  56. package/lib/api/application.js +12 -7
  57. package/lib/api/auth.js +16 -8
  58. package/lib/api/call-logd.js +12 -7
  59. package/lib/api/calld.js +12 -7
  60. package/lib/api/chatd.js +12 -7
  61. package/lib/api/confd.js +12 -7
  62. package/lib/api/ctid-ng.js +14 -7
  63. package/lib/api/dird.js +12 -7
  64. package/lib/api/webhookd.js +12 -7
  65. package/lib/api-client.js +45 -22
  66. package/lib/checker/Checker.js +50 -25
  67. package/lib/checker/checks/aor.js +45 -22
  68. package/lib/checker/checks/api.js +45 -22
  69. package/lib/checker/checks/index.js +50 -25
  70. package/lib/checker/checks/wazo-websocket.js +13 -8
  71. package/lib/checker/checks/webrtc-transport.js +49 -24
  72. package/lib/checker/checks/webrtc.js +49 -24
  73. package/lib/domain/AdHocAPIConference.js +54 -23
  74. package/lib/domain/Features.js +54 -23
  75. package/lib/domain/Phone/CTIPhone.js +54 -23
  76. package/lib/domain/Phone/WebRTCPhone.js +14 -7
  77. package/lib/index.js +233 -25
  78. package/lib/lib/WazoSessionDescriptionHandler.js +12 -7
  79. package/lib/service/CallApi.js +54 -23
  80. package/lib/service/IssueReporter.js +12 -7
  81. package/lib/service/__tests__/IssueReporter.test.js +18 -7
  82. package/lib/service/getApiClient.js +64 -23
  83. package/lib/simple/Auth.js +233 -25
  84. package/lib/simple/Configuration.js +233 -25
  85. package/lib/simple/Directory.js +54 -23
  86. package/lib/simple/Phone.js +233 -25
  87. package/lib/simple/Softphone.js +150 -0
  88. package/lib/simple/Websocket.js +13 -8
  89. package/lib/simple/index.js +233 -25
  90. package/lib/simple/room/LocalParticipant.js +233 -25
  91. package/lib/simple/room/Participant.js +233 -25
  92. package/lib/simple/room/RemoteParticipant.js +233 -25
  93. package/lib/simple/room/Room.js +233 -25
  94. package/lib/simple/room/SipRoom.js +233 -25
  95. package/lib/simple/room/Stream.js +233 -25
  96. package/lib/simple/room/__tests__/RemoteParticipant.test.js +233 -25
  97. package/lib/simple/utils.js +233 -25
  98. package/lib/utils/__tests__/api-requester.test.js +12 -7
  99. package/lib/utils/api-requester.js +12 -7
  100. package/lib/web-rtc-client.js +49 -24
  101. package/lib/websocket-client.js +13 -8
  102. package/package.json +1 -1
  103. package/src/api/auth.js +4 -1
  104. package/src/api-client.js +26 -13
  105. package/src/service/IssueReporter.js +12 -7
  106. package/src/service/__tests__/IssueReporter.test.js +6 -0
  107. package/src/service/getApiClient.js +19 -1
  108. package/src/simple/Auth.js +21 -0
  109. package/src/simple/Softphone.js +148 -0
  110. package/src/simple/index.js +2 -0
  111. package/src/web-rtc-client.js +4 -2
  112. package/src/websocket-client.js +1 -1
@@ -1909,13 +1909,9 @@ class IssueReporter {
1909
1909
 
1910
1910
  setTimeout(() => {
1911
1911
  if (isArray) {
1912
- payload = payload.map(message => {
1913
- message._retry = retry + 1;
1914
- return message;
1915
- });
1916
- } else {
1917
- // $FlowFixMe
1918
- payload._retry = retry + 1;
1912
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
1913
+ } else if (payload && typeof payload === 'object') {
1914
+ payload = this._writeRetryCount(payload, retry + 1);
1919
1915
  }
1920
1916
 
1921
1917
  this._sendDebugToGrafana(payload, retry + 1);
@@ -1923,6 +1919,15 @@ class IssueReporter {
1923
1919
  });
1924
1920
  }
1925
1921
 
1922
+ _writeRetryCount(message , count ) {
1923
+ if (message && typeof message === 'object') {
1924
+ // $FlowFixMe
1925
+ message._retry = count;
1926
+ }
1927
+
1928
+ return message;
1929
+ }
1930
+
1926
1931
  _isLevelAbove(level1 , level2 ) {
1927
1932
  const index1 = LOG_LEVELS.indexOf(level1);
1928
1933
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2265,9 +2270,12 @@ var authMethods = (client , baseUrl ) => ({
2265
2270
  expiration: expiration || DETAULT_EXPIRATION,
2266
2271
  refresh_token: refreshToken,
2267
2272
  client_id: client.clientId,
2268
- tenant_id: tenantId,
2269
2273
  };
2270
2274
 
2275
+ if (tenantId) {
2276
+ body.tenant_id = tenantId;
2277
+ }
2278
+
2271
2279
  const headers = {
2272
2280
  'Content-Type': 'application/json',
2273
2281
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -5415,6 +5423,7 @@ class ApiClient {
5415
5423
 
5416
5424
 
5417
5425
 
5426
+
5418
5427
 
5419
5428
 
5420
5429
 
@@ -5467,23 +5476,31 @@ class ApiClient {
5467
5476
  return null;
5468
5477
  }
5469
5478
 
5470
- const session = await this.auth.refreshToken(
5471
- this.refreshToken,
5472
- this.refreshBackend,
5473
- this.refreshExpiration,
5474
- this.isMobile,
5475
- this.refreshTenantId,
5476
- );
5479
+ try {
5480
+ const session = await this.auth.refreshToken(
5481
+ this.refreshToken,
5482
+ this.refreshBackend,
5483
+ this.refreshExpiration,
5484
+ this.isMobile,
5485
+ this.refreshTenantId,
5486
+ );
5477
5487
 
5478
- logger$a.info('token refreshed', { token: session.token });
5488
+ logger$a.info('token refreshed', { token: session.token });
5479
5489
 
5480
- if (this.onRefreshToken) {
5481
- this.onRefreshToken(session.token, session);
5482
- }
5490
+ if (this.onRefreshToken) {
5491
+ this.onRefreshToken(session.token, session);
5492
+ }
5483
5493
 
5484
- this.setToken(session.token);
5494
+ this.setToken(session.token);
5495
+
5496
+ return session.token;
5497
+ } catch (error) {
5498
+ logger$a.error('token refresh, error', error);
5485
5499
 
5486
- return session.token;
5500
+ if (this.onRefreshTokenError) {
5501
+ this.onRefreshTokenError(error);
5502
+ }
5503
+ }
5487
5504
  }
5488
5505
 
5489
5506
  setToken(token ) {
@@ -5506,6 +5523,10 @@ class ApiClient {
5506
5523
  this.onRefreshToken = onRefreshToken;
5507
5524
  }
5508
5525
 
5526
+ setOnRefreshTokenError(callback ) {
5527
+ this.onRefreshTokenError = callback;
5528
+ }
5529
+
5509
5530
  setRefreshExpiration(refreshExpiration ) {
5510
5531
  this.refreshExpiration = refreshExpiration;
5511
5532
  }
@@ -5541,7 +5562,9 @@ global.wazoClients = global.wazoClients || {};
5541
5562
  global.wazoClientId = global.wazoClientId || {};
5542
5563
  global.wazoClientToken = global.wazoClientToken || {};
5543
5564
  global.wazoRefreshToken = global.wazoRefreshToken || {};
5565
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
5544
5566
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
5567
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
5545
5568
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
5546
5569
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
5547
5570
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -5563,10 +5586,18 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
5563
5586
  global.wazoRefreshToken[forServer] = newRefreshToken;
5564
5587
  };
5565
5588
 
5589
+ const setRefreshTenantId = (refreshTenantId , forServer = null) => {
5590
+ global.wazoRefreshTenantId[forServer] = refreshTenantId;
5591
+ };
5592
+
5566
5593
  const setOnRefreshToken = (onRefreshToken , forServer = null) => {
5567
5594
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
5568
5595
  };
5569
5596
 
5597
+ const setOnRefreshTokenError = (callback , forServer = null) => {
5598
+ global.wazoOnRefreshTokenError[forServer] = callback;
5599
+ };
5600
+
5570
5601
  const setRefreshExpiration = (refreshExpiration , forServer = null) => {
5571
5602
  global.wazoRefreshExpiration[forServer] = refreshExpiration;
5572
5603
  };
@@ -5585,12 +5616,20 @@ const fillClient = (apiClient ) => {
5585
5616
 
5586
5617
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
5587
5618
 
5619
+ apiClient.setRefreshTenantId(
5620
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
5621
+ );
5622
+
5588
5623
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
5589
5624
 
5590
5625
  apiClient.setOnRefreshToken(
5591
5626
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
5592
5627
  );
5593
5628
 
5629
+ apiClient.setOnRefreshTokenError(
5630
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
5631
+ );
5632
+
5594
5633
  apiClient.setRefreshExpiration(
5595
5634
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
5596
5635
  );
@@ -5604,7 +5643,7 @@ const fillClient = (apiClient ) => {
5604
5643
  return apiClient;
5605
5644
  };
5606
5645
 
5607
- var getApiClient = (forServer ) => {
5646
+ var getApiClient = (forServer = null) => {
5608
5647
  const server = forServer || global.wazoCurrentServer || '';
5609
5648
  if (server in global.wazoClients) {
5610
5649
  return fillClient(global.wazoClients[server]);
@@ -7140,8 +7179,10 @@ class WebRTCClient extends Emitter {
7140
7179
  conference: isConference,
7141
7180
  };
7142
7181
 
7143
- // Avoid sdh to created a new stream
7144
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7182
+ // Avoid sdh to create a new stream
7183
+ if (session.sessionDescriptionHandler) {
7184
+ session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7185
+ }
7145
7186
 
7146
7187
  // Send re-INVITE
7147
7188
  return session.invite(options);
@@ -11152,7 +11193,7 @@ class WebSocketClient extends Emitter {
11152
11193
  this.close();
11153
11194
  }
11154
11195
  const url = `wss://${this.host || ''}/api/websocketd/?token=${this.token || ''}&version=${this.version}`;
11155
- logger$6.log('Wazo WS url computed to reconnect', { url });
11196
+ logger$6.info('Wazo WS url computed to reconnect', { url });
11156
11197
 
11157
11198
  return url;
11158
11199
  }
@@ -13610,6 +13651,153 @@ class Checker {
13610
13651
  }
13611
13652
  }
13612
13653
 
13654
+ //
13655
+ /* eslint-disable no-unused-vars */
13656
+ /* global window, document */
13657
+ const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13658
+ const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13659
+ const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13660
+ const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13661
+ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13662
+
13663
+ class Softphone {
13664
+ url = 'https://softphone.wazo.io';
13665
+ width = 500;
13666
+ height = 600;
13667
+ displayed = false;
13668
+ iframe = null;
13669
+
13670
+ onLinkEnabled(link ) {}
13671
+
13672
+ onCallMade(call ) {}
13673
+ onCallIncoming(call ) {}
13674
+ onCallEnded(call , card , direction , fromExtension ) {}
13675
+ onAuthenticated(session ) {}
13676
+
13677
+ init(url , width , height ) {
13678
+ if (url) {
13679
+ this.url = url;
13680
+ }
13681
+ if (width) {
13682
+ this.width = width;
13683
+ }
13684
+ if (height) {
13685
+ this.height = height;
13686
+ }
13687
+
13688
+ window.addEventListener('message', this._onMessage.bind(this), false);
13689
+
13690
+ this._createIframe();
13691
+ }
13692
+
13693
+ parseLinks() {
13694
+ const links = this._getLinks();
13695
+
13696
+ links.forEach(link => {
13697
+ link.setAttribute('data-wazo-parsed', true);
13698
+ link.addEventListener('click', this._onLinkClick.bind(this));
13699
+ this.onLinkEnabled(link);
13700
+ });
13701
+ }
13702
+
13703
+ makeCall(number ) {
13704
+ this.displaySoftphone();
13705
+
13706
+ if (this.iframe) {
13707
+ this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
13708
+ }
13709
+ }
13710
+
13711
+ toggleSoftphoneDisplay() {
13712
+ if (this.displayed) {
13713
+ this.hideSoftphone();
13714
+ } else {
13715
+ this.displaySoftphone();
13716
+ }
13717
+
13718
+ this.displayed = !this.displayed;
13719
+ }
13720
+
13721
+ displaySoftphone() {
13722
+ if (!this.iframe) {
13723
+ this._createIframe();
13724
+ }
13725
+
13726
+ if (this.iframe) {
13727
+ this.iframe.style.display = 'block';
13728
+ }
13729
+ }
13730
+
13731
+ hideSoftphone() {
13732
+ if (this.iframe) {
13733
+ this.iframe.style.display = 'none';
13734
+ }
13735
+ }
13736
+
13737
+ _createIframe() {
13738
+ this.iframe = document.createElement('iframe');
13739
+ // $FlowFixMe
13740
+ this.iframe.width = this.width;
13741
+ // $FlowFixMe
13742
+ this.iframe.height = this.height;
13743
+ // $FlowFixMe
13744
+ this.iframe.allow = 'camera *; microphone *; autoplay *; display-capture *';
13745
+ this.iframe.style.position = 'absolute';
13746
+ this.iframe.style.left = '0';
13747
+ this.iframe.style.bottom = '0';
13748
+ this.iframe.style.border = '1px solid #aaa';
13749
+ this.iframe.src = this.url;
13750
+ this.iframe.style.display = 'none';
13751
+ this.iframe.id = 'wazo-softphone';
13752
+
13753
+ // $FlowFixMe
13754
+ document.body.appendChild(this.iframe);
13755
+ }
13756
+
13757
+ _getLinks() {
13758
+ return [].slice.call(document.querySelectorAll('a:not([data-wazo-parsed])'), 0)
13759
+ .filter(link => link.href.indexOf('tel:') === 0 || link.href.indexOf('callto:') === 0);
13760
+ }
13761
+
13762
+ _onLinkClick(e ) {
13763
+ e.preventDefault();
13764
+ const number = e.target.href.split(':')[1];
13765
+
13766
+ this.makeCall(number);
13767
+ }
13768
+
13769
+ _onAuthenticated() {
13770
+ this.parseLinks();
13771
+ }
13772
+
13773
+ _onMessage(event ) {
13774
+ if (!event.data) {
13775
+ return;
13776
+ }
13777
+
13778
+ switch (event.data.type) {
13779
+ case SDK_ON_CALL_MADE:
13780
+ this.onCallMade(event.data.callSession);
13781
+ break;
13782
+ case SDK_CALL_ENDED: {
13783
+ const { callSession, content, direction, userExtension } = event.data;
13784
+ this.onCallEnded(callSession, content, direction, userExtension);
13785
+ break;
13786
+ }
13787
+ case SDK_CALL_INCOMING:
13788
+ this.onCallIncoming(event.data.callSession);
13789
+ break;
13790
+ case SDK_AUTHENTICATED:
13791
+ // $FlowFixMe
13792
+ this._onAuthenticated(event.data.session);
13793
+ this.onAuthenticated(event.data.session);
13794
+ break;
13795
+ }
13796
+ }
13797
+ }
13798
+
13799
+ var Softphone$1 = new Softphone();
13800
+
13613
13801
  /* global window */
13614
13802
 
13615
13803
  const Wazo = {
@@ -13630,6 +13818,7 @@ const Wazo = {
13630
13818
  loggerFor: IssueReporter$1.loggerFor.bind(IssueReporter$1),
13631
13819
  Features: Features$1,
13632
13820
  Checker,
13821
+ Softphone: Softphone$1,
13633
13822
 
13634
13823
  // Domain
13635
13824
  domain: {
@@ -13701,6 +13890,7 @@ class Auth {
13701
13890
 
13702
13891
 
13703
13892
 
13893
+
13704
13894
 
13705
13895
 
13706
13896
 
@@ -13738,6 +13928,14 @@ class Auth {
13738
13928
  this.onRefreshTokenCallback(token, session);
13739
13929
  }
13740
13930
  });
13931
+
13932
+ setOnRefreshTokenError(error => {
13933
+ logger.error('on refresh token error', error);
13934
+
13935
+ if (this.onRefreshTokenCallbackError) {
13936
+ this.onRefreshTokenCallbackError(error);
13937
+ }
13938
+ });
13741
13939
  }
13742
13940
 
13743
13941
  setFetchOptions(options ) {
@@ -13826,6 +14024,10 @@ class Auth {
13826
14024
  this.onRefreshTokenCallback = callback;
13827
14025
  }
13828
14026
 
14027
+ setOnRefreshTokenError(callback ) {
14028
+ this.onRefreshTokenCallbackError = callback;
14029
+ }
14030
+
13829
14031
  checkAuthorizations(session , authorizationName ) {
13830
14032
  if (!authorizationName) {
13831
14033
  return;
@@ -13858,6 +14060,12 @@ class Auth {
13858
14060
  setRefreshToken(refreshToken);
13859
14061
  }
13860
14062
 
14063
+ setRefreshTenantId(refreshTenantId ) {
14064
+ setRefreshTenantId(refreshTenantId);
14065
+
14066
+ getApiClient().setRefreshTenantId(refreshTenantId);
14067
+ }
14068
+
13861
14069
  forceRefreshToken() {
13862
14070
  getApiClient().forceRefreshToken();
13863
14071
  }
@@ -396,13 +396,9 @@ class IssueReporter {
396
396
 
397
397
  setTimeout(() => {
398
398
  if (isArray) {
399
- payload = payload.map(message => {
400
- message._retry = retry + 1;
401
- return message;
402
- });
403
- } else {
404
- // $FlowFixMe
405
- payload._retry = retry + 1;
399
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
400
+ } else if (payload && typeof payload === 'object') {
401
+ payload = this._writeRetryCount(payload, retry + 1);
406
402
  }
407
403
 
408
404
  this._sendDebugToGrafana(payload, retry + 1);
@@ -410,6 +406,15 @@ class IssueReporter {
410
406
  });
411
407
  }
412
408
 
409
+ _writeRetryCount(message , count ) {
410
+ if (message && typeof message === 'object') {
411
+ // $FlowFixMe
412
+ message._retry = count;
413
+ }
414
+
415
+ return message;
416
+ }
417
+
413
418
  _isLevelAbove(level1 , level2 ) {
414
419
  const index1 = LOG_LEVELS.indexOf(level1);
415
420
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2245,9 +2250,12 @@ var authMethods = (client , baseUrl ) => ({
2245
2250
  expiration: expiration || DETAULT_EXPIRATION,
2246
2251
  refresh_token: refreshToken,
2247
2252
  client_id: client.clientId,
2248
- tenant_id: tenantId,
2249
2253
  };
2250
2254
 
2255
+ if (tenantId) {
2256
+ body.tenant_id = tenantId;
2257
+ }
2258
+
2251
2259
  const headers = {
2252
2260
  'Content-Type': 'application/json',
2253
2261
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4566,6 +4574,7 @@ class ApiClient {
4566
4574
 
4567
4575
 
4568
4576
 
4577
+
4569
4578
 
4570
4579
 
4571
4580
 
@@ -4618,23 +4627,31 @@ class ApiClient {
4618
4627
  return null;
4619
4628
  }
4620
4629
 
4621
- const session = await this.auth.refreshToken(
4622
- this.refreshToken,
4623
- this.refreshBackend,
4624
- this.refreshExpiration,
4625
- this.isMobile,
4626
- this.refreshTenantId,
4627
- );
4628
-
4629
- logger.info('token refreshed', { token: session.token });
4630
+ try {
4631
+ const session = await this.auth.refreshToken(
4632
+ this.refreshToken,
4633
+ this.refreshBackend,
4634
+ this.refreshExpiration,
4635
+ this.isMobile,
4636
+ this.refreshTenantId,
4637
+ );
4638
+
4639
+ logger.info('token refreshed', { token: session.token });
4640
+
4641
+ if (this.onRefreshToken) {
4642
+ this.onRefreshToken(session.token, session);
4643
+ }
4630
4644
 
4631
- if (this.onRefreshToken) {
4632
- this.onRefreshToken(session.token, session);
4633
- }
4645
+ this.setToken(session.token);
4634
4646
 
4635
- this.setToken(session.token);
4647
+ return session.token;
4648
+ } catch (error) {
4649
+ logger.error('token refresh, error', error);
4636
4650
 
4637
- return session.token;
4651
+ if (this.onRefreshTokenError) {
4652
+ this.onRefreshTokenError(error);
4653
+ }
4654
+ }
4638
4655
  }
4639
4656
 
4640
4657
  setToken(token ) {
@@ -4657,6 +4674,10 @@ class ApiClient {
4657
4674
  this.onRefreshToken = onRefreshToken;
4658
4675
  }
4659
4676
 
4677
+ setOnRefreshTokenError(callback ) {
4678
+ this.onRefreshTokenError = callback;
4679
+ }
4680
+
4660
4681
  setRefreshExpiration(refreshExpiration ) {
4661
4682
  this.refreshExpiration = refreshExpiration;
4662
4683
  }
@@ -4692,7 +4713,9 @@ global.wazoClients = global.wazoClients || {};
4692
4713
  global.wazoClientId = global.wazoClientId || {};
4693
4714
  global.wazoClientToken = global.wazoClientToken || {};
4694
4715
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4716
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4695
4717
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4718
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4696
4719
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4697
4720
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4698
4721
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4708,12 +4731,20 @@ const fillClient = (apiClient ) => {
4708
4731
 
4709
4732
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4710
4733
 
4734
+ apiClient.setRefreshTenantId(
4735
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
4736
+ );
4737
+
4711
4738
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
4712
4739
 
4713
4740
  apiClient.setOnRefreshToken(
4714
4741
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
4715
4742
  );
4716
4743
 
4744
+ apiClient.setOnRefreshTokenError(
4745
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
4746
+ );
4747
+
4717
4748
  apiClient.setRefreshExpiration(
4718
4749
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
4719
4750
  );
@@ -4727,7 +4758,7 @@ const fillClient = (apiClient ) => {
4727
4758
  return apiClient;
4728
4759
  };
4729
4760
 
4730
- var getApiClient = (forServer ) => {
4761
+ var getApiClient = (forServer = null) => {
4731
4762
  const server = forServer || global.wazoCurrentServer || '';
4732
4763
  if (server in global.wazoClients) {
4733
4764
  return fillClient(global.wazoClients[server]);