@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
@@ -1921,13 +1921,9 @@ class IssueReporter {
1921
1921
 
1922
1922
  setTimeout(() => {
1923
1923
  if (isArray) {
1924
- payload = payload.map(message => {
1925
- message._retry = retry + 1;
1926
- return message;
1927
- });
1928
- } else {
1929
- // $FlowFixMe
1930
- payload._retry = retry + 1;
1924
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
1925
+ } else if (payload && typeof payload === 'object') {
1926
+ payload = this._writeRetryCount(payload, retry + 1);
1931
1927
  }
1932
1928
 
1933
1929
  this._sendDebugToGrafana(payload, retry + 1);
@@ -1935,6 +1931,15 @@ class IssueReporter {
1935
1931
  });
1936
1932
  }
1937
1933
 
1934
+ _writeRetryCount(message , count ) {
1935
+ if (message && typeof message === 'object') {
1936
+ // $FlowFixMe
1937
+ message._retry = count;
1938
+ }
1939
+
1940
+ return message;
1941
+ }
1942
+
1938
1943
  _isLevelAbove(level1 , level2 ) {
1939
1944
  const index1 = LOG_LEVELS.indexOf(level1);
1940
1945
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2277,9 +2282,12 @@ var authMethods = (client , baseUrl ) => ({
2277
2282
  expiration: expiration || DETAULT_EXPIRATION,
2278
2283
  refresh_token: refreshToken,
2279
2284
  client_id: client.clientId,
2280
- tenant_id: tenantId,
2281
2285
  };
2282
2286
 
2287
+ if (tenantId) {
2288
+ body.tenant_id = tenantId;
2289
+ }
2290
+
2283
2291
  const headers = {
2284
2292
  'Content-Type': 'application/json',
2285
2293
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -5427,6 +5435,7 @@ class ApiClient {
5427
5435
 
5428
5436
 
5429
5437
 
5438
+
5430
5439
 
5431
5440
 
5432
5441
 
@@ -5479,23 +5488,31 @@ class ApiClient {
5479
5488
  return null;
5480
5489
  }
5481
5490
 
5482
- const session = await this.auth.refreshToken(
5483
- this.refreshToken,
5484
- this.refreshBackend,
5485
- this.refreshExpiration,
5486
- this.isMobile,
5487
- this.refreshTenantId,
5488
- );
5491
+ try {
5492
+ const session = await this.auth.refreshToken(
5493
+ this.refreshToken,
5494
+ this.refreshBackend,
5495
+ this.refreshExpiration,
5496
+ this.isMobile,
5497
+ this.refreshTenantId,
5498
+ );
5489
5499
 
5490
- logger$a.info('token refreshed', { token: session.token });
5500
+ logger$a.info('token refreshed', { token: session.token });
5491
5501
 
5492
- if (this.onRefreshToken) {
5493
- this.onRefreshToken(session.token, session);
5494
- }
5502
+ if (this.onRefreshToken) {
5503
+ this.onRefreshToken(session.token, session);
5504
+ }
5495
5505
 
5496
- this.setToken(session.token);
5506
+ this.setToken(session.token);
5507
+
5508
+ return session.token;
5509
+ } catch (error) {
5510
+ logger$a.error('token refresh, error', error);
5497
5511
 
5498
- return session.token;
5512
+ if (this.onRefreshTokenError) {
5513
+ this.onRefreshTokenError(error);
5514
+ }
5515
+ }
5499
5516
  }
5500
5517
 
5501
5518
  setToken(token ) {
@@ -5518,6 +5535,10 @@ class ApiClient {
5518
5535
  this.onRefreshToken = onRefreshToken;
5519
5536
  }
5520
5537
 
5538
+ setOnRefreshTokenError(callback ) {
5539
+ this.onRefreshTokenError = callback;
5540
+ }
5541
+
5521
5542
  setRefreshExpiration(refreshExpiration ) {
5522
5543
  this.refreshExpiration = refreshExpiration;
5523
5544
  }
@@ -5553,7 +5574,9 @@ global.wazoClients = global.wazoClients || {};
5553
5574
  global.wazoClientId = global.wazoClientId || {};
5554
5575
  global.wazoClientToken = global.wazoClientToken || {};
5555
5576
  global.wazoRefreshToken = global.wazoRefreshToken || {};
5577
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
5556
5578
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
5579
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
5557
5580
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
5558
5581
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
5559
5582
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -5575,10 +5598,18 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
5575
5598
  global.wazoRefreshToken[forServer] = newRefreshToken;
5576
5599
  };
5577
5600
 
5601
+ const setRefreshTenantId = (refreshTenantId , forServer = null) => {
5602
+ global.wazoRefreshTenantId[forServer] = refreshTenantId;
5603
+ };
5604
+
5578
5605
  const setOnRefreshToken = (onRefreshToken , forServer = null) => {
5579
5606
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
5580
5607
  };
5581
5608
 
5609
+ const setOnRefreshTokenError = (callback , forServer = null) => {
5610
+ global.wazoOnRefreshTokenError[forServer] = callback;
5611
+ };
5612
+
5582
5613
  const setRefreshExpiration = (refreshExpiration , forServer = null) => {
5583
5614
  global.wazoRefreshExpiration[forServer] = refreshExpiration;
5584
5615
  };
@@ -5597,12 +5628,20 @@ const fillClient = (apiClient ) => {
5597
5628
 
5598
5629
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
5599
5630
 
5631
+ apiClient.setRefreshTenantId(
5632
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
5633
+ );
5634
+
5600
5635
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
5601
5636
 
5602
5637
  apiClient.setOnRefreshToken(
5603
5638
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
5604
5639
  );
5605
5640
 
5641
+ apiClient.setOnRefreshTokenError(
5642
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
5643
+ );
5644
+
5606
5645
  apiClient.setRefreshExpiration(
5607
5646
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
5608
5647
  );
@@ -5616,7 +5655,7 @@ const fillClient = (apiClient ) => {
5616
5655
  return apiClient;
5617
5656
  };
5618
5657
 
5619
- var getApiClient = (forServer ) => {
5658
+ var getApiClient = (forServer = null) => {
5620
5659
  const server = forServer || global.wazoCurrentServer || '';
5621
5660
  if (server in global.wazoClients) {
5622
5661
  return fillClient(global.wazoClients[server]);
@@ -7152,8 +7191,10 @@ class WebRTCClient extends Emitter {
7152
7191
  conference: isConference,
7153
7192
  };
7154
7193
 
7155
- // Avoid sdh to created a new stream
7156
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7194
+ // Avoid sdh to create a new stream
7195
+ if (session.sessionDescriptionHandler) {
7196
+ session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7197
+ }
7157
7198
 
7158
7199
  // Send re-INVITE
7159
7200
  return session.invite(options);
@@ -11164,7 +11205,7 @@ class WebSocketClient extends Emitter {
11164
11205
  this.close();
11165
11206
  }
11166
11207
  const url = `wss://${this.host || ''}/api/websocketd/?token=${this.token || ''}&version=${this.version}`;
11167
- logger$6.log('Wazo WS url computed to reconnect', { url });
11208
+ logger$6.info('Wazo WS url computed to reconnect', { url });
11168
11209
 
11169
11210
  return url;
11170
11211
  }
@@ -13639,6 +13680,153 @@ class Checker {
13639
13680
  }
13640
13681
  }
13641
13682
 
13683
+ //
13684
+ /* eslint-disable no-unused-vars */
13685
+ /* global window, document */
13686
+ const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13687
+ const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13688
+ const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13689
+ const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13690
+ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13691
+
13692
+ class Softphone {
13693
+ url = 'https://softphone.wazo.io';
13694
+ width = 500;
13695
+ height = 600;
13696
+ displayed = false;
13697
+ iframe = null;
13698
+
13699
+ onLinkEnabled(link ) {}
13700
+
13701
+ onCallMade(call ) {}
13702
+ onCallIncoming(call ) {}
13703
+ onCallEnded(call , card , direction , fromExtension ) {}
13704
+ onAuthenticated(session ) {}
13705
+
13706
+ init(url , width , height ) {
13707
+ if (url) {
13708
+ this.url = url;
13709
+ }
13710
+ if (width) {
13711
+ this.width = width;
13712
+ }
13713
+ if (height) {
13714
+ this.height = height;
13715
+ }
13716
+
13717
+ window.addEventListener('message', this._onMessage.bind(this), false);
13718
+
13719
+ this._createIframe();
13720
+ }
13721
+
13722
+ parseLinks() {
13723
+ const links = this._getLinks();
13724
+
13725
+ links.forEach(link => {
13726
+ link.setAttribute('data-wazo-parsed', true);
13727
+ link.addEventListener('click', this._onLinkClick.bind(this));
13728
+ this.onLinkEnabled(link);
13729
+ });
13730
+ }
13731
+
13732
+ makeCall(number ) {
13733
+ this.displaySoftphone();
13734
+
13735
+ if (this.iframe) {
13736
+ this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
13737
+ }
13738
+ }
13739
+
13740
+ toggleSoftphoneDisplay() {
13741
+ if (this.displayed) {
13742
+ this.hideSoftphone();
13743
+ } else {
13744
+ this.displaySoftphone();
13745
+ }
13746
+
13747
+ this.displayed = !this.displayed;
13748
+ }
13749
+
13750
+ displaySoftphone() {
13751
+ if (!this.iframe) {
13752
+ this._createIframe();
13753
+ }
13754
+
13755
+ if (this.iframe) {
13756
+ this.iframe.style.display = 'block';
13757
+ }
13758
+ }
13759
+
13760
+ hideSoftphone() {
13761
+ if (this.iframe) {
13762
+ this.iframe.style.display = 'none';
13763
+ }
13764
+ }
13765
+
13766
+ _createIframe() {
13767
+ this.iframe = document.createElement('iframe');
13768
+ // $FlowFixMe
13769
+ this.iframe.width = this.width;
13770
+ // $FlowFixMe
13771
+ this.iframe.height = this.height;
13772
+ // $FlowFixMe
13773
+ this.iframe.allow = 'camera *; microphone *; autoplay *; display-capture *';
13774
+ this.iframe.style.position = 'absolute';
13775
+ this.iframe.style.left = '0';
13776
+ this.iframe.style.bottom = '0';
13777
+ this.iframe.style.border = '1px solid #aaa';
13778
+ this.iframe.src = this.url;
13779
+ this.iframe.style.display = 'none';
13780
+ this.iframe.id = 'wazo-softphone';
13781
+
13782
+ // $FlowFixMe
13783
+ document.body.appendChild(this.iframe);
13784
+ }
13785
+
13786
+ _getLinks() {
13787
+ return [].slice.call(document.querySelectorAll('a:not([data-wazo-parsed])'), 0)
13788
+ .filter(link => link.href.indexOf('tel:') === 0 || link.href.indexOf('callto:') === 0);
13789
+ }
13790
+
13791
+ _onLinkClick(e ) {
13792
+ e.preventDefault();
13793
+ const number = e.target.href.split(':')[1];
13794
+
13795
+ this.makeCall(number);
13796
+ }
13797
+
13798
+ _onAuthenticated() {
13799
+ this.parseLinks();
13800
+ }
13801
+
13802
+ _onMessage(event ) {
13803
+ if (!event.data) {
13804
+ return;
13805
+ }
13806
+
13807
+ switch (event.data.type) {
13808
+ case SDK_ON_CALL_MADE:
13809
+ this.onCallMade(event.data.callSession);
13810
+ break;
13811
+ case SDK_CALL_ENDED: {
13812
+ const { callSession, content, direction, userExtension } = event.data;
13813
+ this.onCallEnded(callSession, content, direction, userExtension);
13814
+ break;
13815
+ }
13816
+ case SDK_CALL_INCOMING:
13817
+ this.onCallIncoming(event.data.callSession);
13818
+ break;
13819
+ case SDK_AUTHENTICATED:
13820
+ // $FlowFixMe
13821
+ this._onAuthenticated(event.data.session);
13822
+ this.onAuthenticated(event.data.session);
13823
+ break;
13824
+ }
13825
+ }
13826
+ }
13827
+
13828
+ var Softphone$1 = new Softphone();
13829
+
13642
13830
  /* global window */
13643
13831
 
13644
13832
  const Wazo = {
@@ -13659,6 +13847,7 @@ const Wazo = {
13659
13847
  loggerFor: IssueReporter$1.loggerFor.bind(IssueReporter$1),
13660
13848
  Features: Features$1,
13661
13849
  Checker,
13850
+ Softphone: Softphone$1,
13662
13851
 
13663
13852
  // Domain
13664
13853
  domain: {
@@ -13730,6 +13919,7 @@ class Auth {
13730
13919
 
13731
13920
 
13732
13921
 
13922
+
13733
13923
 
13734
13924
 
13735
13925
 
@@ -13767,6 +13957,14 @@ class Auth {
13767
13957
  this.onRefreshTokenCallback(token, session);
13768
13958
  }
13769
13959
  });
13960
+
13961
+ setOnRefreshTokenError(error => {
13962
+ logger.error('on refresh token error', error);
13963
+
13964
+ if (this.onRefreshTokenCallbackError) {
13965
+ this.onRefreshTokenCallbackError(error);
13966
+ }
13967
+ });
13770
13968
  }
13771
13969
 
13772
13970
  setFetchOptions(options ) {
@@ -13855,6 +14053,10 @@ class Auth {
13855
14053
  this.onRefreshTokenCallback = callback;
13856
14054
  }
13857
14055
 
14056
+ setOnRefreshTokenError(callback ) {
14057
+ this.onRefreshTokenCallbackError = callback;
14058
+ }
14059
+
13858
14060
  checkAuthorizations(session , authorizationName ) {
13859
14061
  if (!authorizationName) {
13860
14062
  return;
@@ -13887,6 +14089,12 @@ class Auth {
13887
14089
  setRefreshToken(refreshToken);
13888
14090
  }
13889
14091
 
14092
+ setRefreshTenantId(refreshTenantId ) {
14093
+ setRefreshTenantId(refreshTenantId);
14094
+
14095
+ getApiClient().setRefreshTenantId(refreshTenantId);
14096
+ }
14097
+
13890
14098
  forceRefreshToken() {
13891
14099
  getApiClient().forceRefreshToken();
13892
14100
  }