@wazo/sdk 0.37.42 → 0.38.1

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 (109) hide show
  1. package/README.md +218 -0
  2. package/dist/wazo-sdk.js +5 -5
  3. package/esm/__tests__/api-client.test.js +12 -7
  4. package/esm/__tests__/web-rtc-client.test.js +17 -10
  5. package/esm/api/agentd.js +12 -7
  6. package/esm/api/amid.js +12 -7
  7. package/esm/api/application.js +12 -7
  8. package/esm/api/auth.js +12 -7
  9. package/esm/api/call-logd.js +12 -7
  10. package/esm/api/calld.js +12 -7
  11. package/esm/api/chatd.js +12 -7
  12. package/esm/api/confd.js +12 -7
  13. package/esm/api/ctid-ng.js +12 -7
  14. package/esm/api/dird.js +12 -7
  15. package/esm/api/webhookd.js +12 -7
  16. package/esm/api-client.js +12 -7
  17. package/esm/checker/Checker.js +18 -11
  18. package/esm/checker/checks/aor.js +12 -7
  19. package/esm/checker/checks/api.js +12 -7
  20. package/esm/checker/checks/index.js +18 -11
  21. package/esm/checker/checks/wazo-websocket.js +13 -8
  22. package/esm/checker/checks/webrtc-transport.js +17 -10
  23. package/esm/checker/checks/webrtc.js +17 -10
  24. package/esm/domain/AdHocAPIConference.js +12 -7
  25. package/esm/domain/Features.js +12 -7
  26. package/esm/domain/Phone/CTIPhone.js +12 -7
  27. package/esm/domain/Phone/WebRTCPhone.js +12 -7
  28. package/esm/index.js +347 -11
  29. package/esm/lib/WazoSessionDescriptionHandler.js +12 -7
  30. package/esm/service/CallApi.js +12 -7
  31. package/esm/service/IssueReporter.js +12 -7
  32. package/esm/service/__tests__/IssueReporter.test.js +18 -7
  33. package/esm/service/getApiClient.js +12 -7
  34. package/esm/simple/Auth.js +347 -11
  35. package/esm/simple/Configuration.js +347 -11
  36. package/esm/simple/Directory.js +12 -7
  37. package/esm/simple/Phone.js +347 -11
  38. package/esm/simple/Softphone.js +329 -0
  39. package/esm/simple/Websocket.js +13 -8
  40. package/esm/simple/index.js +347 -11
  41. package/esm/simple/room/LocalParticipant.js +347 -11
  42. package/esm/simple/room/Participant.js +347 -11
  43. package/esm/simple/room/RemoteParticipant.js +347 -11
  44. package/esm/simple/room/Room.js +347 -11
  45. package/esm/simple/room/SipRoom.js +347 -11
  46. package/esm/simple/room/Stream.js +347 -11
  47. package/esm/simple/room/__tests__/RemoteParticipant.test.js +347 -11
  48. package/esm/simple/utils.js +347 -11
  49. package/esm/utils/__tests__/api-requester.test.js +12 -7
  50. package/esm/utils/api-requester.js +12 -7
  51. package/esm/web-rtc-client.js +17 -10
  52. package/esm/websocket-client.js +13 -8
  53. package/lib/__tests__/api-client.test.js +12 -7
  54. package/lib/__tests__/web-rtc-client.test.js +17 -10
  55. package/lib/api/agentd.js +12 -7
  56. package/lib/api/amid.js +12 -7
  57. package/lib/api/application.js +12 -7
  58. package/lib/api/auth.js +12 -7
  59. package/lib/api/call-logd.js +12 -7
  60. package/lib/api/calld.js +12 -7
  61. package/lib/api/chatd.js +12 -7
  62. package/lib/api/confd.js +12 -7
  63. package/lib/api/ctid-ng.js +12 -7
  64. package/lib/api/dird.js +12 -7
  65. package/lib/api/webhookd.js +12 -7
  66. package/lib/api-client.js +12 -7
  67. package/lib/checker/Checker.js +18 -11
  68. package/lib/checker/checks/aor.js +12 -7
  69. package/lib/checker/checks/api.js +12 -7
  70. package/lib/checker/checks/index.js +18 -11
  71. package/lib/checker/checks/wazo-websocket.js +13 -8
  72. package/lib/checker/checks/webrtc-transport.js +17 -10
  73. package/lib/checker/checks/webrtc.js +17 -10
  74. package/lib/domain/AdHocAPIConference.js +12 -7
  75. package/lib/domain/Features.js +12 -7
  76. package/lib/domain/Phone/CTIPhone.js +12 -7
  77. package/lib/domain/Phone/WebRTCPhone.js +12 -7
  78. package/lib/index.js +347 -11
  79. package/lib/lib/WazoSessionDescriptionHandler.js +12 -7
  80. package/lib/service/CallApi.js +12 -7
  81. package/lib/service/IssueReporter.js +12 -7
  82. package/lib/service/__tests__/IssueReporter.test.js +18 -7
  83. package/lib/service/getApiClient.js +12 -7
  84. package/lib/simple/Auth.js +347 -11
  85. package/lib/simple/Configuration.js +347 -11
  86. package/lib/simple/Directory.js +12 -7
  87. package/lib/simple/Phone.js +347 -11
  88. package/lib/simple/Softphone.js +331 -0
  89. package/lib/simple/Websocket.js +13 -8
  90. package/lib/simple/index.js +347 -11
  91. package/lib/simple/room/LocalParticipant.js +347 -11
  92. package/lib/simple/room/Participant.js +347 -11
  93. package/lib/simple/room/RemoteParticipant.js +347 -11
  94. package/lib/simple/room/Room.js +347 -11
  95. package/lib/simple/room/SipRoom.js +347 -11
  96. package/lib/simple/room/Stream.js +347 -11
  97. package/lib/simple/room/__tests__/RemoteParticipant.test.js +347 -11
  98. package/lib/simple/utils.js +347 -11
  99. package/lib/utils/__tests__/api-requester.test.js +12 -7
  100. package/lib/utils/api-requester.js +12 -7
  101. package/lib/web-rtc-client.js +17 -10
  102. package/lib/websocket-client.js +13 -8
  103. package/package.json +1 -1
  104. package/src/service/IssueReporter.js +12 -7
  105. package/src/service/__tests__/IssueReporter.test.js +6 -0
  106. package/src/simple/Softphone.js +327 -0
  107. package/src/simple/index.js +2 -0
  108. package/src/web-rtc-client.js +5 -3
  109. 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);
@@ -7487,8 +7492,10 @@ class WebRTCClient extends Emitter {
7487
7492
  conference: isConference,
7488
7493
  };
7489
7494
 
7490
- // Avoid sdh to created a new stream
7491
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7495
+ // Avoid sdh to create a new stream
7496
+ if (session.sessionDescriptionHandler) {
7497
+ session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7498
+ }
7492
7499
 
7493
7500
  // Send re-INVITE
7494
7501
  return session.invite(options);
@@ -8331,7 +8338,7 @@ class WebRTCClient extends Emitter {
8331
8338
  }
8332
8339
 
8333
8340
  async _onHeartbeatTimeout() {
8334
- logger$8.info('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8341
+ logger$8.warn('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8335
8342
 
8336
8343
  if (this.heartbeatTimeoutCb) {
8337
8344
  this.heartbeatTimeoutCb();
@@ -11499,7 +11506,7 @@ class WebSocketClient extends Emitter {
11499
11506
  this.close();
11500
11507
  }
11501
11508
  const url = `wss://${this.host || ''}/api/websocketd/?token=${this.token || ''}&version=${this.version}`;
11502
- logger$5.log('Wazo WS url computed to reconnect', { url });
11509
+ logger$5.info('Wazo WS url computed to reconnect', { url });
11503
11510
 
11504
11511
  return url;
11505
11512
  }
@@ -13958,6 +13965,334 @@ class Checker {
13958
13965
  }
13959
13966
  }
13960
13967
 
13968
+ //
13969
+ /* eslint-disable no-unused-vars */
13970
+ /* global window, document */
13971
+ const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13972
+ const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13973
+ const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13974
+ const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13975
+ const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13976
+ const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
13977
+ const BRIDGE_SEARCH_OPTIONS = 'bridge/BRIDGE_SEARCH_OPTIONS';
13978
+ const BRIDGE_DISPLAY_LINKED_OPTION = 'bridge/DISPLAY_LINKED_OPTION';
13979
+ const BRIDGE_UPDATE_FORM_SCHEMA = 'bridge/BRIDGE_UPDATE_FORM_SCHEMA';
13980
+ const BRIDGE_WAZO_CONTACT_SEARCH = 'bridge/BRIDGE_WAZO_CONTACT_SEARCH';
13981
+ const BRIDGE_ON_AGENT_LOGGED_IN = 'bridge/BRIDGE_ON_AGENT_LOGGED_IN';
13982
+ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13983
+ const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13984
+ const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13985
+ const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13986
+ const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13987
+ const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13988
+ const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
13989
+ const BRIDGE_ON_CALL_UN_MUTED = 'bridge/BRIDGE_ON_CALL_UN_MUTED';
13990
+ const BRIDGE_ON_DTMF = 'bridge/BRIDGE_ON_DTMF';
13991
+ const BRIDGE_ON_DIRECT_TRANSFER = 'bridge/BRIDGE_ON_DIRECT_TRANSFER';
13992
+ const BRIDGE_ON_CREATE_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CREATE_INDIRECT_TRANSFER';
13993
+ const BRIDGE_ON_CANCEL_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CANCEL_INDIRECT_TRANSFER';
13994
+ const BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER';
13995
+ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE';
13996
+ const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13997
+ const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13998
+ const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13999
+
14000
+ const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
14001
+ const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
14002
+ const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
14003
+ const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
14004
+ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14005
+ const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
14006
+
14007
+ class Softphone {
14008
+ url = 'https://softphone.wazo.io';
14009
+ width = 500;
14010
+ height = 600;
14011
+ displayed = false;
14012
+ iframe = null;
14013
+
14014
+ onLinkEnabled(link ) {}
14015
+ onIFrameLoaded() {}
14016
+
14017
+ onCallMade(call ) {}
14018
+ onCallIncoming(call ) {}
14019
+ onCallEnded(call , card , direction , fromExtension ) {}
14020
+ onCardSaved(card ) {}
14021
+ onAuthenticated(session ) {}
14022
+ onLoggedOut() {}
14023
+ onSearchOptions(fieldId , query ) {}
14024
+ onDisplayLinkedOption(optionId ) {}
14025
+ onWazoContactSearch(query ) {}
14026
+ onAgentLoggedIn() {}
14027
+ onAgentLoggedOut() {}
14028
+ onAgentPaused() {}
14029
+ onAgentResumed() {}
14030
+ onLanguageChanged(language ) {}
14031
+ onCallHeld() {}
14032
+ onCallResumed() {}
14033
+ onCallMuted() {}
14034
+ onCallUnMuted() {}
14035
+ onDtmfSent(tone ) {}
14036
+ onDirectTransfer(number ) {}
14037
+ onCreateIndirectTransfer(number ) {}
14038
+ onCancelIndirectTransfer() {}
14039
+ onConfirmIndirectTransfer() {}
14040
+ onIndirectCallMade(call ) {}
14041
+ onIndirectTransferDone(call ) {}
14042
+ onStartRecording() {}
14043
+ onStopRecording() {}
14044
+ onUnHandledEvent(event ) {}
14045
+
14046
+ init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
14047
+ allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
14048
+ if (url) {
14049
+ this.url = url;
14050
+ }
14051
+ if (width) {
14052
+ this.width = width;
14053
+ }
14054
+ if (height) {
14055
+ this.height = height;
14056
+ }
14057
+
14058
+ window.addEventListener('message', this._onMessage.bind(this), false);
14059
+
14060
+ if (!server) {
14061
+ // eslint-disable-next-line no-param-reassign
14062
+ server = 'stack.dev.wazo.io';
14063
+ }
14064
+
14065
+ this._createIframe(() => {
14066
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
14067
+ config: {
14068
+ server,
14069
+ port,
14070
+ language,
14071
+ wrapUpDuration,
14072
+ shouldDisplayLinkedEntities,
14073
+ allowContactCreation,
14074
+ },
14075
+ });
14076
+
14077
+ if (withCard) {
14078
+ this._sendMessage(BRIDGE_ENABLE_CARD);
14079
+ }
14080
+
14081
+ if (subscriptionType) {
14082
+ this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
14083
+ }
14084
+
14085
+ this.onIFrameLoaded();
14086
+ });
14087
+ }
14088
+
14089
+ parseLinks() {
14090
+ const links = this._getLinks();
14091
+
14092
+ links.forEach(link => {
14093
+ link.setAttribute('data-wazo-parsed', true);
14094
+ link.addEventListener('click', this._onLinkClick.bind(this));
14095
+ this.onLinkEnabled(link);
14096
+ });
14097
+ }
14098
+
14099
+ makeCall(number ) {
14100
+ this.displaySoftphone();
14101
+
14102
+ this._sendMessage(SDK_CLICK_TO_CALL, { number });
14103
+ }
14104
+
14105
+ toggleSoftphoneDisplay() {
14106
+ if (this.displayed) {
14107
+ this.hideSoftphone();
14108
+ } else {
14109
+ this.displaySoftphone();
14110
+ }
14111
+ }
14112
+
14113
+ displaySoftphone() {
14114
+ if (!this.iframe) {
14115
+ this._createIframe();
14116
+ }
14117
+
14118
+ if (this.iframe) {
14119
+ this.iframe.style.display = 'block';
14120
+ }
14121
+
14122
+ this.displayed = true;
14123
+ }
14124
+
14125
+ hideSoftphone() {
14126
+ if (this.iframe) {
14127
+ this.iframe.style.display = 'none';
14128
+ }
14129
+ this.displayed = false;
14130
+ }
14131
+
14132
+ optionsFetched(fieldId , options ) {
14133
+ this._sendMessage(BRIDGE_OPTIONS_FETCHED, { fieldId, options });
14134
+ }
14135
+
14136
+ onOptionsResults(fieldId , options ) {
14137
+ this._sendMessage(BRIDGE_OPTIONS_FOUND, { fieldId, options });
14138
+ }
14139
+
14140
+ setFormSchema(schema , uiSchema ) {
14141
+ this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14142
+ }
14143
+
14144
+ _createIframe(cb = () => {}) {
14145
+ this.iframe = document.createElement('iframe');
14146
+ // $FlowFixMe
14147
+ this.iframe.width = this.width;
14148
+ // $FlowFixMe
14149
+ this.iframe.height = this.height;
14150
+ // $FlowFixMe
14151
+ this.iframe.allow = 'camera *; microphone *; autoplay *; display-capture *';
14152
+ this.iframe.style.position = 'absolute';
14153
+ this.iframe.style.left = '0';
14154
+ this.iframe.style.bottom = '0';
14155
+ this.iframe.style.border = '1px solid #aaa';
14156
+ this.iframe.style.backgroundColor = 'white';
14157
+ this.iframe.src = this.url;
14158
+ this.iframe.style.display = 'none';
14159
+ this.iframe.id = 'wazo-softphone';
14160
+
14161
+ this.iframe.onload = cb;
14162
+
14163
+ // $FlowFixMe
14164
+ document.body.appendChild(this.iframe);
14165
+ }
14166
+
14167
+ _getLinks() {
14168
+ return [].slice.call(document.querySelectorAll('a:not([data-wazo-parsed])'), 0)
14169
+ .filter(link => link.href.indexOf('tel:') === 0 || link.href.indexOf('callto:') === 0);
14170
+ }
14171
+
14172
+ _onLinkClick(e ) {
14173
+ e.preventDefault();
14174
+ const number = e.target.href.split(':')[1];
14175
+
14176
+ this.makeCall(number);
14177
+ }
14178
+
14179
+ _onAuthenticated() {
14180
+ this.parseLinks();
14181
+ }
14182
+
14183
+ _onMessage(event ) {
14184
+ if (!event.data) {
14185
+ return;
14186
+ }
14187
+
14188
+ switch (event.data.type) {
14189
+ case SDK_ON_CALL_MADE:
14190
+ this.onCallMade(event.data.callSession);
14191
+ break;
14192
+ case SDK_CALL_ENDED: {
14193
+ const { callSession, content, direction, userExtension } = event.data;
14194
+ this.onCallEnded(callSession, content, direction, userExtension);
14195
+ break;
14196
+ }
14197
+ case SDK_CALL_INCOMING:
14198
+ this.onCallIncoming(event.data.callSession);
14199
+ break;
14200
+ case SDK_AUTHENTICATED:
14201
+ // $FlowFixMe
14202
+ this._onAuthenticated(event.data.session);
14203
+ this.onAuthenticated(event.data.session);
14204
+ break;
14205
+ case SDK_LOGGED_OUT:
14206
+ this.onLoggedOut();
14207
+ break;
14208
+ case BRIDGE_CREATE_OR_UPDATE_CARD: {
14209
+ const { content } = event.data;
14210
+ this.onCardSaved(content);
14211
+ break;
14212
+ }
14213
+ case BRIDGE_SEARCH_OPTIONS: {
14214
+ const { fieldId, query } = event.data;
14215
+ this.onSearchOptions(fieldId, query);
14216
+ break;
14217
+ }
14218
+ case BRIDGE_DISPLAY_LINKED_OPTION:
14219
+ this.onDisplayLinkedOption(event.data.linkedOptionId);
14220
+ break;
14221
+ case BRIDGE_WAZO_CONTACT_SEARCH:
14222
+ this.onWazoContactSearch(event.data.query);
14223
+ break;
14224
+ case BRIDGE_ON_AGENT_LOGGED_IN:
14225
+ this.onAgentLoggedIn();
14226
+ break;
14227
+ case BRIDGE_ON_AGENT_LOGGED_OUT:
14228
+ this.onAgentLoggedOut();
14229
+ break;
14230
+ case BRIDGE_ON_AGENT_PAUSED:
14231
+ this.onAgentPaused();
14232
+ break;
14233
+ case BRIDGE_ON_AGENT_RESUMED:
14234
+ this.onAgentResumed();
14235
+ break;
14236
+ case BRIDGE_ON_LANGUAGE_CHANGED:
14237
+ this.onLanguageChanged(event.data.language);
14238
+ break;
14239
+ case BRIDGE_ON_CALL_HELD:
14240
+ this.onCallHeld();
14241
+ break;
14242
+ case BRIDGE_ON_CALL_RESUMED:
14243
+ this.onCallResumed();
14244
+ break;
14245
+ case BRIDGE_ON_CALL_MUTED:
14246
+ this.onCallMuted();
14247
+ break;
14248
+ case BRIDGE_ON_CALL_UN_MUTED:
14249
+ this.onCallUnMuted();
14250
+ break;
14251
+ case BRIDGE_ON_DTMF:
14252
+ this.onDtmfSent(event.data.tone);
14253
+ break;
14254
+ case BRIDGE_ON_DIRECT_TRANSFER:
14255
+ this.onDirectTransfer(event.data.number);
14256
+ break;
14257
+ case BRIDGE_ON_CREATE_INDIRECT_TRANSFER:
14258
+ this.onCreateIndirectTransfer(event.data.number);
14259
+ break;
14260
+ case BRIDGE_ON_CANCEL_INDIRECT_TRANSFER:
14261
+ this.onCancelIndirectTransfer();
14262
+ break;
14263
+ case BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER:
14264
+ this.onConfirmIndirectTransfer();
14265
+ break;
14266
+ case BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE:
14267
+ this.onIndirectCallMade(event.data.call);
14268
+ break;
14269
+ case BRIDGE_ON_INDIRECT_TRANSFER_DONE:
14270
+ this.onIndirectTransferDone(event.data.call);
14271
+ break;
14272
+ case BRIDGE_ON_START_RECORDING:
14273
+ this.onStartRecording();
14274
+ break;
14275
+ case BRIDGE_ON_STOP_RECORDING:
14276
+ this.onStopRecording();
14277
+ break;
14278
+ default:
14279
+ this.onUnHandledEvent(event);
14280
+ break;
14281
+ }
14282
+ }
14283
+
14284
+ _sendMessage(type , payload = {}) {
14285
+ if (!this.iframe) {
14286
+ console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
14287
+ return;
14288
+ }
14289
+
14290
+ this.iframe.contentWindow.postMessage({ type, ...payload }, '*');
14291
+ }
14292
+ }
14293
+
14294
+ var Softphone$1 = new Softphone();
14295
+
13961
14296
  /* global window */
13962
14297
 
13963
14298
  const Wazo = {
@@ -13978,6 +14313,7 @@ const Wazo = {
13978
14313
  loggerFor: IssueReporter$1.loggerFor.bind(IssueReporter$1),
13979
14314
  Features: Features$1,
13980
14315
  Checker,
14316
+ Softphone: Softphone$1,
13981
14317
 
13982
14318
  // Domain
13983
14319
  domain: {
@@ -398,13 +398,9 @@ class IssueReporter {
398
398
 
399
399
  setTimeout(() => {
400
400
  if (isArray) {
401
- payload = payload.map(message => {
402
- message._retry = retry + 1;
403
- return message;
404
- });
405
- } else {
406
- // $FlowFixMe
407
- payload._retry = retry + 1;
401
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
402
+ } else if (payload && typeof payload === 'object') {
403
+ payload = this._writeRetryCount(payload, retry + 1);
408
404
  }
409
405
 
410
406
  this._sendDebugToGrafana(payload, retry + 1);
@@ -412,6 +408,15 @@ class IssueReporter {
412
408
  });
413
409
  }
414
410
 
411
+ _writeRetryCount(message , count ) {
412
+ if (message && typeof message === 'object') {
413
+ // $FlowFixMe
414
+ message._retry = count;
415
+ }
416
+
417
+ return message;
418
+ }
419
+
415
420
  _isLevelAbove(level1 , level2 ) {
416
421
  const index1 = LOG_LEVELS.indexOf(level1);
417
422
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -400,13 +400,9 @@ class IssueReporter {
400
400
 
401
401
  setTimeout(() => {
402
402
  if (isArray) {
403
- payload = payload.map(message => {
404
- message._retry = retry + 1;
405
- return message;
406
- });
407
- } else {
408
- // $FlowFixMe
409
- payload._retry = retry + 1;
403
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
404
+ } else if (payload && typeof payload === 'object') {
405
+ payload = this._writeRetryCount(payload, retry + 1);
410
406
  }
411
407
 
412
408
  this._sendDebugToGrafana(payload, retry + 1);
@@ -414,6 +410,15 @@ class IssueReporter {
414
410
  });
415
411
  }
416
412
 
413
+ _writeRetryCount(message , count ) {
414
+ if (message && typeof message === 'object') {
415
+ // $FlowFixMe
416
+ message._retry = count;
417
+ }
418
+
419
+ return message;
420
+ }
421
+
417
422
  _isLevelAbove(level1 , level2 ) {
418
423
  const index1 = LOG_LEVELS.indexOf(level1);
419
424
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -689,13 +689,9 @@ class IssueReporter {
689
689
 
690
690
  setTimeout(() => {
691
691
  if (isArray) {
692
- payload = payload.map(message => {
693
- message._retry = retry + 1;
694
- return message;
695
- });
696
- } else {
697
- // $FlowFixMe
698
- payload._retry = retry + 1;
692
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
693
+ } else if (payload && typeof payload === 'object') {
694
+ payload = this._writeRetryCount(payload, retry + 1);
699
695
  }
700
696
 
701
697
  this._sendDebugToGrafana(payload, retry + 1);
@@ -703,6 +699,15 @@ class IssueReporter {
703
699
  });
704
700
  }
705
701
 
702
+ _writeRetryCount(message , count ) {
703
+ if (message && typeof message === 'object') {
704
+ // $FlowFixMe
705
+ message._retry = count;
706
+ }
707
+
708
+ return message;
709
+ }
710
+
706
711
  _isLevelAbove(level1 , level2 ) {
707
712
  const index1 = LOG_LEVELS.indexOf(level1);
708
713
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -6116,8 +6121,10 @@ class WebRTCClient extends Emitter {
6116
6121
  conference: isConference,
6117
6122
  };
6118
6123
 
6119
- // Avoid sdh to created a new stream
6120
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
6124
+ // Avoid sdh to create a new stream
6125
+ if (session.sessionDescriptionHandler) {
6126
+ session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
6127
+ }
6121
6128
 
6122
6129
  // Send re-INVITE
6123
6130
  return session.invite(options);
@@ -6960,7 +6967,7 @@ class WebRTCClient extends Emitter {
6960
6967
  }
6961
6968
 
6962
6969
  async _onHeartbeatTimeout() {
6963
- logger.info('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
6970
+ logger.warn('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
6964
6971
 
6965
6972
  if (this.heartbeatTimeoutCb) {
6966
6973
  this.heartbeatTimeoutCb();
@@ -397,13 +397,9 @@ class IssueReporter {
397
397
 
398
398
  setTimeout(() => {
399
399
  if (isArray) {
400
- payload = payload.map(message => {
401
- message._retry = retry + 1;
402
- return message;
403
- });
404
- } else {
405
- // $FlowFixMe
406
- payload._retry = retry + 1;
400
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
401
+ } else if (payload && typeof payload === 'object') {
402
+ payload = this._writeRetryCount(payload, retry + 1);
407
403
  }
408
404
 
409
405
  this._sendDebugToGrafana(payload, retry + 1);
@@ -411,6 +407,15 @@ class IssueReporter {
411
407
  });
412
408
  }
413
409
 
410
+ _writeRetryCount(message , count ) {
411
+ if (message && typeof message === 'object') {
412
+ // $FlowFixMe
413
+ message._retry = count;
414
+ }
415
+
416
+ return message;
417
+ }
418
+
414
419
  _isLevelAbove(level1 , level2 ) {
415
420
  const index1 = LOG_LEVELS.indexOf(level1);
416
421
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -871,7 +876,7 @@ class WebSocketClient extends Emitter {
871
876
  this.close();
872
877
  }
873
878
  const url = `wss://${this.host || ''}/api/websocketd/?token=${this.token || ''}&version=${this.version}`;
874
- logger.log('Wazo WS url computed to reconnect', { url });
879
+ logger.info('Wazo WS url computed to reconnect', { url });
875
880
 
876
881
  return url;
877
882
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wazo/sdk",
3
- "version": "0.37.42",
3
+ "version": "0.38.1",
4
4
  "description": "Wazo's JavaScript Software Development Kit.",
5
5
  "main": "dist/wazo-sdk.js",
6
6
  "author": "Wazo (http://wazo.io)",
@@ -330,13 +330,9 @@ class IssueReporter {
330
330
 
331
331
  setTimeout(() => {
332
332
  if (isArray) {
333
- payload = payload.map(message => {
334
- message._retry = retry + 1;
335
- return message;
336
- });
337
- } else {
338
- // $FlowFixMe
339
- payload._retry = retry + 1;
333
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
334
+ } else if (payload && typeof payload === 'object') {
335
+ payload = this._writeRetryCount(payload, retry + 1);
340
336
  }
341
337
 
342
338
  this._sendDebugToGrafana(payload, retry + 1);
@@ -344,6 +340,15 @@ class IssueReporter {
344
340
  });
345
341
  }
346
342
 
343
+ _writeRetryCount(message: string | Object, count: number): string | Object {
344
+ if (message && typeof message === 'object') {
345
+ // $FlowFixMe
346
+ message._retry = count;
347
+ }
348
+
349
+ return message;
350
+ }
351
+
347
352
  _isLevelAbove(level1: string, level2: string) {
348
353
  const index1 = LOG_LEVELS.indexOf(level1);
349
354
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -100,4 +100,10 @@ describe('IssueReporter', () => {
100
100
  expect(IssueReporter.removeSlashes('\"')).toBe("'");
101
101
  expect(IssueReporter.removeSlashes('\\\"')).toBe("'");
102
102
  });
103
+
104
+ it('Add retry count', () => {
105
+ expect(IssueReporter._writeRetryCount('', 1)).toBe('');
106
+ expect(IssueReporter._writeRetryCount('{}', 1)).toBe('{}');
107
+ expect(IssueReporter._writeRetryCount({}, 1)).toEqual({ _retry: 1 });
108
+ });
103
109
  });