@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
@@ -2850,13 +2850,9 @@ class IssueReporter {
2850
2850
 
2851
2851
  setTimeout(() => {
2852
2852
  if (isArray) {
2853
- payload = payload.map(message => {
2854
- message._retry = retry + 1;
2855
- return message;
2856
- });
2857
- } else {
2858
- // $FlowFixMe
2859
- payload._retry = retry + 1;
2853
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
2854
+ } else if (payload && typeof payload === 'object') {
2855
+ payload = this._writeRetryCount(payload, retry + 1);
2860
2856
  }
2861
2857
 
2862
2858
  this._sendDebugToGrafana(payload, retry + 1);
@@ -2864,6 +2860,15 @@ class IssueReporter {
2864
2860
  });
2865
2861
  }
2866
2862
 
2863
+ _writeRetryCount(message , count ) {
2864
+ if (message && typeof message === 'object') {
2865
+ // $FlowFixMe
2866
+ message._retry = count;
2867
+ }
2868
+
2869
+ return message;
2870
+ }
2871
+
2867
2872
  _isLevelAbove(level1 , level2 ) {
2868
2873
  const index1 = LOG_LEVELS.indexOf(level1);
2869
2874
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -3205,9 +3210,12 @@ var authMethods = (client , baseUrl ) => ({
3205
3210
  expiration: expiration || DETAULT_EXPIRATION,
3206
3211
  refresh_token: refreshToken,
3207
3212
  client_id: client.clientId,
3208
- tenant_id: tenantId,
3209
3213
  };
3210
3214
 
3215
+ if (tenantId) {
3216
+ body.tenant_id = tenantId;
3217
+ }
3218
+
3211
3219
  const headers = {
3212
3220
  'Content-Type': 'application/json',
3213
3221
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4979,6 +4987,7 @@ class ApiClient {
4979
4987
 
4980
4988
 
4981
4989
 
4990
+
4982
4991
 
4983
4992
 
4984
4993
 
@@ -5031,23 +5040,31 @@ class ApiClient {
5031
5040
  return null;
5032
5041
  }
5033
5042
 
5034
- const session = await this.auth.refreshToken(
5035
- this.refreshToken,
5036
- this.refreshBackend,
5037
- this.refreshExpiration,
5038
- this.isMobile,
5039
- this.refreshTenantId,
5040
- );
5041
-
5042
- logger$1.info('token refreshed', { token: session.token });
5043
+ try {
5044
+ const session = await this.auth.refreshToken(
5045
+ this.refreshToken,
5046
+ this.refreshBackend,
5047
+ this.refreshExpiration,
5048
+ this.isMobile,
5049
+ this.refreshTenantId,
5050
+ );
5051
+
5052
+ logger$1.info('token refreshed', { token: session.token });
5053
+
5054
+ if (this.onRefreshToken) {
5055
+ this.onRefreshToken(session.token, session);
5056
+ }
5043
5057
 
5044
- if (this.onRefreshToken) {
5045
- this.onRefreshToken(session.token, session);
5046
- }
5058
+ this.setToken(session.token);
5047
5059
 
5048
- this.setToken(session.token);
5060
+ return session.token;
5061
+ } catch (error) {
5062
+ logger$1.error('token refresh, error', error);
5049
5063
 
5050
- return session.token;
5064
+ if (this.onRefreshTokenError) {
5065
+ this.onRefreshTokenError(error);
5066
+ }
5067
+ }
5051
5068
  }
5052
5069
 
5053
5070
  setToken(token ) {
@@ -5070,6 +5087,10 @@ class ApiClient {
5070
5087
  this.onRefreshToken = onRefreshToken;
5071
5088
  }
5072
5089
 
5090
+ setOnRefreshTokenError(callback ) {
5091
+ this.onRefreshTokenError = callback;
5092
+ }
5093
+
5073
5094
  setRefreshExpiration(refreshExpiration ) {
5074
5095
  this.refreshExpiration = refreshExpiration;
5075
5096
  }
@@ -5105,7 +5126,9 @@ global.wazoClients = global.wazoClients || {};
5105
5126
  global.wazoClientId = global.wazoClientId || {};
5106
5127
  global.wazoClientToken = global.wazoClientToken || {};
5107
5128
  global.wazoRefreshToken = global.wazoRefreshToken || {};
5129
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
5108
5130
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
5131
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
5109
5132
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
5110
5133
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
5111
5134
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -5121,12 +5144,20 @@ const fillClient = (apiClient ) => {
5121
5144
 
5122
5145
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
5123
5146
 
5147
+ apiClient.setRefreshTenantId(
5148
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
5149
+ );
5150
+
5124
5151
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
5125
5152
 
5126
5153
  apiClient.setOnRefreshToken(
5127
5154
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
5128
5155
  );
5129
5156
 
5157
+ apiClient.setOnRefreshTokenError(
5158
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
5159
+ );
5160
+
5130
5161
  apiClient.setRefreshExpiration(
5131
5162
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
5132
5163
  );
@@ -5140,7 +5171,7 @@ const fillClient = (apiClient ) => {
5140
5171
  return apiClient;
5141
5172
  };
5142
5173
 
5143
- var getApiClient = (forServer ) => {
5174
+ var getApiClient = (forServer = null) => {
5144
5175
  const server = forServer || global.wazoCurrentServer || '';
5145
5176
  if (server in global.wazoClients) {
5146
5177
  return fillClient(global.wazoClients[server]);
@@ -802,13 +802,9 @@ class IssueReporter {
802
802
 
803
803
  setTimeout(() => {
804
804
  if (isArray) {
805
- payload = payload.map(message => {
806
- message._retry = retry + 1;
807
- return message;
808
- });
809
- } else {
810
- // $FlowFixMe
811
- payload._retry = retry + 1;
805
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
806
+ } else if (payload && typeof payload === 'object') {
807
+ payload = this._writeRetryCount(payload, retry + 1);
812
808
  }
813
809
 
814
810
  this._sendDebugToGrafana(payload, retry + 1);
@@ -816,6 +812,15 @@ class IssueReporter {
816
812
  });
817
813
  }
818
814
 
815
+ _writeRetryCount(message , count ) {
816
+ if (message && typeof message === 'object') {
817
+ // $FlowFixMe
818
+ message._retry = count;
819
+ }
820
+
821
+ return message;
822
+ }
823
+
819
824
  _isLevelAbove(level1 , level2 ) {
820
825
  const index1 = LOG_LEVELS.indexOf(level1);
821
826
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -888,7 +893,9 @@ global.wazoClients = global.wazoClients || {};
888
893
  global.wazoClientId = global.wazoClientId || {};
889
894
  global.wazoClientToken = global.wazoClientToken || {};
890
895
  global.wazoRefreshToken = global.wazoRefreshToken || {};
896
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
891
897
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
898
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
892
899
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
893
900
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
894
901
  global.wazoIsMobile = global.wazoIsMobile || {};
package/esm/index.js CHANGED
@@ -416,13 +416,9 @@ class IssueReporter {
416
416
 
417
417
  setTimeout(() => {
418
418
  if (isArray) {
419
- payload = payload.map(message => {
420
- message._retry = retry + 1;
421
- return message;
422
- });
423
- } else {
424
- // $FlowFixMe
425
- payload._retry = retry + 1;
419
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
420
+ } else if (payload && typeof payload === 'object') {
421
+ payload = this._writeRetryCount(payload, retry + 1);
426
422
  }
427
423
 
428
424
  this._sendDebugToGrafana(payload, retry + 1);
@@ -430,6 +426,15 @@ class IssueReporter {
430
426
  });
431
427
  }
432
428
 
429
+ _writeRetryCount(message , count ) {
430
+ if (message && typeof message === 'object') {
431
+ // $FlowFixMe
432
+ message._retry = count;
433
+ }
434
+
435
+ return message;
436
+ }
437
+
433
438
  _isLevelAbove(level1 , level2 ) {
434
439
  const index1 = LOG_LEVELS.indexOf(level1);
435
440
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2266,9 +2271,12 @@ var authMethods = (client , baseUrl ) => ({
2266
2271
  expiration: expiration || DETAULT_EXPIRATION,
2267
2272
  refresh_token: refreshToken,
2268
2273
  client_id: client.clientId,
2269
- tenant_id: tenantId,
2270
2274
  };
2271
2275
 
2276
+ if (tenantId) {
2277
+ body.tenant_id = tenantId;
2278
+ }
2279
+
2272
2280
  const headers = {
2273
2281
  'Content-Type': 'application/json',
2274
2282
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -3976,7 +3984,9 @@ global.wazoClients = global.wazoClients || {};
3976
3984
  global.wazoClientId = global.wazoClientId || {};
3977
3985
  global.wazoClientToken = global.wazoClientToken || {};
3978
3986
  global.wazoRefreshToken = global.wazoRefreshToken || {};
3987
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
3979
3988
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
3989
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
3980
3990
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
3981
3991
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
3982
3992
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -3998,10 +4008,18 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
3998
4008
  global.wazoRefreshToken[forServer] = newRefreshToken;
3999
4009
  };
4000
4010
 
4011
+ const setRefreshTenantId = (refreshTenantId , forServer = null) => {
4012
+ global.wazoRefreshTenantId[forServer] = refreshTenantId;
4013
+ };
4014
+
4001
4015
  const setOnRefreshToken = (onRefreshToken , forServer = null) => {
4002
4016
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
4003
4017
  };
4004
4018
 
4019
+ const setOnRefreshTokenError = (callback , forServer = null) => {
4020
+ global.wazoOnRefreshTokenError[forServer] = callback;
4021
+ };
4022
+
4005
4023
  const setRefreshExpiration = (refreshExpiration , forServer = null) => {
4006
4024
  global.wazoRefreshExpiration[forServer] = refreshExpiration;
4007
4025
  };
@@ -4020,12 +4038,20 @@ const fillClient = (apiClient ) => {
4020
4038
 
4021
4039
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4022
4040
 
4041
+ apiClient.setRefreshTenantId(
4042
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
4043
+ );
4044
+
4023
4045
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
4024
4046
 
4025
4047
  apiClient.setOnRefreshToken(
4026
4048
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
4027
4049
  );
4028
4050
 
4051
+ apiClient.setOnRefreshTokenError(
4052
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
4053
+ );
4054
+
4029
4055
  apiClient.setRefreshExpiration(
4030
4056
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
4031
4057
  );
@@ -4039,7 +4065,7 @@ const fillClient = (apiClient ) => {
4039
4065
  return apiClient;
4040
4066
  };
4041
4067
 
4042
- var getApiClient = (forServer ) => {
4068
+ var getApiClient = (forServer = null) => {
4043
4069
  const server = forServer || global.wazoCurrentServer || '';
4044
4070
  if (server in global.wazoClients) {
4045
4071
  return fillClient(global.wazoClients[server]);
@@ -5499,6 +5525,7 @@ class ApiClient {
5499
5525
 
5500
5526
 
5501
5527
 
5528
+
5502
5529
 
5503
5530
 
5504
5531
 
@@ -5551,23 +5578,31 @@ class ApiClient {
5551
5578
  return null;
5552
5579
  }
5553
5580
 
5554
- const session = await this.auth.refreshToken(
5555
- this.refreshToken,
5556
- this.refreshBackend,
5557
- this.refreshExpiration,
5558
- this.isMobile,
5559
- this.refreshTenantId,
5560
- );
5581
+ try {
5582
+ const session = await this.auth.refreshToken(
5583
+ this.refreshToken,
5584
+ this.refreshBackend,
5585
+ this.refreshExpiration,
5586
+ this.isMobile,
5587
+ this.refreshTenantId,
5588
+ );
5561
5589
 
5562
- logger$a.info('token refreshed', { token: session.token });
5590
+ logger$a.info('token refreshed', { token: session.token });
5563
5591
 
5564
- if (this.onRefreshToken) {
5565
- this.onRefreshToken(session.token, session);
5566
- }
5592
+ if (this.onRefreshToken) {
5593
+ this.onRefreshToken(session.token, session);
5594
+ }
5567
5595
 
5568
- this.setToken(session.token);
5596
+ this.setToken(session.token);
5569
5597
 
5570
- return session.token;
5598
+ return session.token;
5599
+ } catch (error) {
5600
+ logger$a.error('token refresh, error', error);
5601
+
5602
+ if (this.onRefreshTokenError) {
5603
+ this.onRefreshTokenError(error);
5604
+ }
5605
+ }
5571
5606
  }
5572
5607
 
5573
5608
  setToken(token ) {
@@ -5590,6 +5625,10 @@ class ApiClient {
5590
5625
  this.onRefreshToken = onRefreshToken;
5591
5626
  }
5592
5627
 
5628
+ setOnRefreshTokenError(callback ) {
5629
+ this.onRefreshTokenError = callback;
5630
+ }
5631
+
5593
5632
  setRefreshExpiration(refreshExpiration ) {
5594
5633
  this.refreshExpiration = refreshExpiration;
5595
5634
  }
@@ -6962,8 +7001,10 @@ class WebRTCClient extends Emitter {
6962
7001
  conference: isConference,
6963
7002
  };
6964
7003
 
6965
- // Avoid sdh to created a new stream
6966
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7004
+ // Avoid sdh to create a new stream
7005
+ if (session.sessionDescriptionHandler) {
7006
+ session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7007
+ }
6967
7008
 
6968
7009
  // Send re-INVITE
6969
7010
  return session.invite(options);
@@ -8752,7 +8793,7 @@ class WebSocketClient extends Emitter {
8752
8793
  this.close();
8753
8794
  }
8754
8795
  const url = `wss://${this.host || ''}/api/websocketd/?token=${this.token || ''}&version=${this.version}`;
8755
- logger$8.log('Wazo WS url computed to reconnect', { url });
8796
+ logger$8.info('Wazo WS url computed to reconnect', { url });
8756
8797
 
8757
8798
  return url;
8758
8799
  }
@@ -11721,6 +11762,7 @@ class Auth {
11721
11762
 
11722
11763
 
11723
11764
 
11765
+
11724
11766
 
11725
11767
 
11726
11768
 
@@ -11758,6 +11800,14 @@ class Auth {
11758
11800
  this.onRefreshTokenCallback(token, session);
11759
11801
  }
11760
11802
  });
11803
+
11804
+ setOnRefreshTokenError(error => {
11805
+ logger$5.error('on refresh token error', error);
11806
+
11807
+ if (this.onRefreshTokenCallbackError) {
11808
+ this.onRefreshTokenCallbackError(error);
11809
+ }
11810
+ });
11761
11811
  }
11762
11812
 
11763
11813
  setFetchOptions(options ) {
@@ -11846,6 +11896,10 @@ class Auth {
11846
11896
  this.onRefreshTokenCallback = callback;
11847
11897
  }
11848
11898
 
11899
+ setOnRefreshTokenError(callback ) {
11900
+ this.onRefreshTokenCallbackError = callback;
11901
+ }
11902
+
11849
11903
  checkAuthorizations(session , authorizationName ) {
11850
11904
  if (!authorizationName) {
11851
11905
  return;
@@ -11878,6 +11932,12 @@ class Auth {
11878
11932
  setRefreshToken(refreshToken);
11879
11933
  }
11880
11934
 
11935
+ setRefreshTenantId(refreshTenantId ) {
11936
+ setRefreshTenantId(refreshTenantId);
11937
+
11938
+ getApiClient().setRefreshTenantId(refreshTenantId);
11939
+ }
11940
+
11881
11941
  forceRefreshToken() {
11882
11942
  getApiClient().forceRefreshToken();
11883
11943
  }
@@ -14047,6 +14107,153 @@ const createLocalVideoStream = async (options ) => createLocalStream('vid
14047
14107
 
14048
14108
  const createLocalAudioStream = async (options ) => createLocalStream('audio', options);
14049
14109
 
14110
+ //
14111
+ /* eslint-disable no-unused-vars */
14112
+ /* global window, document */
14113
+ const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
14114
+ const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
14115
+ const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
14116
+ const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
14117
+ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14118
+
14119
+ class Softphone {
14120
+ url = 'https://softphone.wazo.io';
14121
+ width = 500;
14122
+ height = 600;
14123
+ displayed = false;
14124
+ iframe = null;
14125
+
14126
+ onLinkEnabled(link ) {}
14127
+
14128
+ onCallMade(call ) {}
14129
+ onCallIncoming(call ) {}
14130
+ onCallEnded(call , card , direction , fromExtension ) {}
14131
+ onAuthenticated(session ) {}
14132
+
14133
+ init(url , width , height ) {
14134
+ if (url) {
14135
+ this.url = url;
14136
+ }
14137
+ if (width) {
14138
+ this.width = width;
14139
+ }
14140
+ if (height) {
14141
+ this.height = height;
14142
+ }
14143
+
14144
+ window.addEventListener('message', this._onMessage.bind(this), false);
14145
+
14146
+ this._createIframe();
14147
+ }
14148
+
14149
+ parseLinks() {
14150
+ const links = this._getLinks();
14151
+
14152
+ links.forEach(link => {
14153
+ link.setAttribute('data-wazo-parsed', true);
14154
+ link.addEventListener('click', this._onLinkClick.bind(this));
14155
+ this.onLinkEnabled(link);
14156
+ });
14157
+ }
14158
+
14159
+ makeCall(number ) {
14160
+ this.displaySoftphone();
14161
+
14162
+ if (this.iframe) {
14163
+ this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
14164
+ }
14165
+ }
14166
+
14167
+ toggleSoftphoneDisplay() {
14168
+ if (this.displayed) {
14169
+ this.hideSoftphone();
14170
+ } else {
14171
+ this.displaySoftphone();
14172
+ }
14173
+
14174
+ this.displayed = !this.displayed;
14175
+ }
14176
+
14177
+ displaySoftphone() {
14178
+ if (!this.iframe) {
14179
+ this._createIframe();
14180
+ }
14181
+
14182
+ if (this.iframe) {
14183
+ this.iframe.style.display = 'block';
14184
+ }
14185
+ }
14186
+
14187
+ hideSoftphone() {
14188
+ if (this.iframe) {
14189
+ this.iframe.style.display = 'none';
14190
+ }
14191
+ }
14192
+
14193
+ _createIframe() {
14194
+ this.iframe = document.createElement('iframe');
14195
+ // $FlowFixMe
14196
+ this.iframe.width = this.width;
14197
+ // $FlowFixMe
14198
+ this.iframe.height = this.height;
14199
+ // $FlowFixMe
14200
+ this.iframe.allow = 'camera *; microphone *; autoplay *; display-capture *';
14201
+ this.iframe.style.position = 'absolute';
14202
+ this.iframe.style.left = '0';
14203
+ this.iframe.style.bottom = '0';
14204
+ this.iframe.style.border = '1px solid #aaa';
14205
+ this.iframe.src = this.url;
14206
+ this.iframe.style.display = 'none';
14207
+ this.iframe.id = 'wazo-softphone';
14208
+
14209
+ // $FlowFixMe
14210
+ document.body.appendChild(this.iframe);
14211
+ }
14212
+
14213
+ _getLinks() {
14214
+ return [].slice.call(document.querySelectorAll('a:not([data-wazo-parsed])'), 0)
14215
+ .filter(link => link.href.indexOf('tel:') === 0 || link.href.indexOf('callto:') === 0);
14216
+ }
14217
+
14218
+ _onLinkClick(e ) {
14219
+ e.preventDefault();
14220
+ const number = e.target.href.split(':')[1];
14221
+
14222
+ this.makeCall(number);
14223
+ }
14224
+
14225
+ _onAuthenticated() {
14226
+ this.parseLinks();
14227
+ }
14228
+
14229
+ _onMessage(event ) {
14230
+ if (!event.data) {
14231
+ return;
14232
+ }
14233
+
14234
+ switch (event.data.type) {
14235
+ case SDK_ON_CALL_MADE:
14236
+ this.onCallMade(event.data.callSession);
14237
+ break;
14238
+ case SDK_CALL_ENDED: {
14239
+ const { callSession, content, direction, userExtension } = event.data;
14240
+ this.onCallEnded(callSession, content, direction, userExtension);
14241
+ break;
14242
+ }
14243
+ case SDK_CALL_INCOMING:
14244
+ this.onCallIncoming(event.data.callSession);
14245
+ break;
14246
+ case SDK_AUTHENTICATED:
14247
+ // $FlowFixMe
14248
+ this._onAuthenticated(event.data.session);
14249
+ this.onAuthenticated(event.data.session);
14250
+ break;
14251
+ }
14252
+ }
14253
+ }
14254
+
14255
+ var Softphone$1 = new Softphone();
14256
+
14050
14257
  /* global window */
14051
14258
 
14052
14259
  const Wazo = {
@@ -14067,6 +14274,7 @@ const Wazo = {
14067
14274
  loggerFor: IssueReporter$1.loggerFor.bind(IssueReporter$1),
14068
14275
  Features: Features$1,
14069
14276
  Checker,
14277
+ Softphone: Softphone$1,
14070
14278
 
14071
14279
  // Domain
14072
14280
  domain: {
@@ -363,13 +363,9 @@ class IssueReporter {
363
363
 
364
364
  setTimeout(() => {
365
365
  if (isArray) {
366
- payload = payload.map(message => {
367
- message._retry = retry + 1;
368
- return message;
369
- });
370
- } else {
371
- // $FlowFixMe
372
- payload._retry = retry + 1;
366
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
367
+ } else if (payload && typeof payload === 'object') {
368
+ payload = this._writeRetryCount(payload, retry + 1);
373
369
  }
374
370
 
375
371
  this._sendDebugToGrafana(payload, retry + 1);
@@ -377,6 +373,15 @@ class IssueReporter {
377
373
  });
378
374
  }
379
375
 
376
+ _writeRetryCount(message , count ) {
377
+ if (message && typeof message === 'object') {
378
+ // $FlowFixMe
379
+ message._retry = count;
380
+ }
381
+
382
+ return message;
383
+ }
384
+
380
385
  _isLevelAbove(level1 , level2 ) {
381
386
  const index1 = LOG_LEVELS.indexOf(level1);
382
387
  const index2 = LOG_LEVELS.indexOf(level2);