@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
@@ -687,13 +687,9 @@ class IssueReporter {
687
687
 
688
688
  setTimeout(() => {
689
689
  if (isArray) {
690
- payload = payload.map(message => {
691
- message._retry = retry + 1;
692
- return message;
693
- });
694
- } else {
695
- // $FlowFixMe
696
- payload._retry = retry + 1;
690
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
691
+ } else if (payload && typeof payload === 'object') {
692
+ payload = this._writeRetryCount(payload, retry + 1);
697
693
  }
698
694
 
699
695
  this._sendDebugToGrafana(payload, retry + 1);
@@ -701,6 +697,15 @@ class IssueReporter {
701
697
  });
702
698
  }
703
699
 
700
+ _writeRetryCount(message , count ) {
701
+ if (message && typeof message === 'object') {
702
+ // $FlowFixMe
703
+ message._retry = count;
704
+ }
705
+
706
+ return message;
707
+ }
708
+
704
709
  _isLevelAbove(level1 , level2 ) {
705
710
  const index1 = LOG_LEVELS.indexOf(level1);
706
711
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -6111,8 +6116,10 @@ class WebRTCClient extends Emitter {
6111
6116
  conference: isConference,
6112
6117
  };
6113
6118
 
6114
- // Avoid sdh to created a new stream
6115
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
6119
+ // Avoid sdh to create a new stream
6120
+ if (session.sessionDescriptionHandler) {
6121
+ session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
6122
+ }
6116
6123
 
6117
6124
  // Send re-INVITE
6118
6125
  return session.invite(options);
@@ -6955,7 +6962,7 @@ class WebRTCClient extends Emitter {
6955
6962
  }
6956
6963
 
6957
6964
  async _onHeartbeatTimeout() {
6958
- logger.info('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
6965
+ logger.warn('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
6959
6966
 
6960
6967
  if (this.heartbeatTimeoutCb) {
6961
6968
  this.heartbeatTimeoutCb();
@@ -622,13 +622,9 @@ class IssueReporter {
622
622
 
623
623
  setTimeout(() => {
624
624
  if (isArray) {
625
- payload = payload.map(message => {
626
- message._retry = retry + 1;
627
- return message;
628
- });
629
- } else {
630
- // $FlowFixMe
631
- payload._retry = retry + 1;
625
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
626
+ } else if (payload && typeof payload === 'object') {
627
+ payload = this._writeRetryCount(payload, retry + 1);
632
628
  }
633
629
 
634
630
  this._sendDebugToGrafana(payload, retry + 1);
@@ -636,6 +632,15 @@ class IssueReporter {
636
632
  });
637
633
  }
638
634
 
635
+ _writeRetryCount(message , count ) {
636
+ if (message && typeof message === 'object') {
637
+ // $FlowFixMe
638
+ message._retry = count;
639
+ }
640
+
641
+ return message;
642
+ }
643
+
639
644
  _isLevelAbove(level1 , level2 ) {
640
645
  const index1 = LOG_LEVELS.indexOf(level1);
641
646
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -404,13 +404,9 @@ class IssueReporter {
404
404
 
405
405
  setTimeout(() => {
406
406
  if (isArray) {
407
- payload = payload.map(message => {
408
- message._retry = retry + 1;
409
- return message;
410
- });
411
- } else {
412
- // $FlowFixMe
413
- payload._retry = retry + 1;
407
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
408
+ } else if (payload && typeof payload === 'object') {
409
+ payload = this._writeRetryCount(payload, retry + 1);
414
410
  }
415
411
 
416
412
  this._sendDebugToGrafana(payload, retry + 1);
@@ -418,6 +414,15 @@ class IssueReporter {
418
414
  });
419
415
  }
420
416
 
417
+ _writeRetryCount(message , count ) {
418
+ if (message && typeof message === 'object') {
419
+ // $FlowFixMe
420
+ message._retry = count;
421
+ }
422
+
423
+ return message;
424
+ }
425
+
421
426
  _isLevelAbove(level1 , level2 ) {
422
427
  const index1 = LOG_LEVELS.indexOf(level1);
423
428
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2859,13 +2859,9 @@ class IssueReporter {
2859
2859
 
2860
2860
  setTimeout(() => {
2861
2861
  if (isArray) {
2862
- payload = payload.map(message => {
2863
- message._retry = retry + 1;
2864
- return message;
2865
- });
2866
- } else {
2867
- // $FlowFixMe
2868
- payload._retry = retry + 1;
2862
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
2863
+ } else if (payload && typeof payload === 'object') {
2864
+ payload = this._writeRetryCount(payload, retry + 1);
2869
2865
  }
2870
2866
 
2871
2867
  this._sendDebugToGrafana(payload, retry + 1);
@@ -2873,6 +2869,15 @@ class IssueReporter {
2873
2869
  });
2874
2870
  }
2875
2871
 
2872
+ _writeRetryCount(message , count ) {
2873
+ if (message && typeof message === 'object') {
2874
+ // $FlowFixMe
2875
+ message._retry = count;
2876
+ }
2877
+
2878
+ return message;
2879
+ }
2880
+
2876
2881
  _isLevelAbove(level1 , level2 ) {
2877
2882
  const index1 = LOG_LEVELS.indexOf(level1);
2878
2883
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -811,13 +811,9 @@ class IssueReporter {
811
811
 
812
812
  setTimeout(() => {
813
813
  if (isArray) {
814
- payload = payload.map(message => {
815
- message._retry = retry + 1;
816
- return message;
817
- });
818
- } else {
819
- // $FlowFixMe
820
- payload._retry = retry + 1;
814
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
815
+ } else if (payload && typeof payload === 'object') {
816
+ payload = this._writeRetryCount(payload, retry + 1);
821
817
  }
822
818
 
823
819
  this._sendDebugToGrafana(payload, retry + 1);
@@ -825,6 +821,15 @@ class IssueReporter {
825
821
  });
826
822
  }
827
823
 
824
+ _writeRetryCount(message , count ) {
825
+ if (message && typeof message === 'object') {
826
+ // $FlowFixMe
827
+ message._retry = count;
828
+ }
829
+
830
+ return message;
831
+ }
832
+
828
833
  _isLevelAbove(level1 , level2 ) {
829
834
  const index1 = LOG_LEVELS.indexOf(level1);
830
835
  const index2 = LOG_LEVELS.indexOf(level2);
package/lib/index.js CHANGED
@@ -427,13 +427,9 @@ class IssueReporter {
427
427
 
428
428
  setTimeout(() => {
429
429
  if (isArray) {
430
- payload = payload.map(message => {
431
- message._retry = retry + 1;
432
- return message;
433
- });
434
- } else {
435
- // $FlowFixMe
436
- payload._retry = retry + 1;
430
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
431
+ } else if (payload && typeof payload === 'object') {
432
+ payload = this._writeRetryCount(payload, retry + 1);
437
433
  }
438
434
 
439
435
  this._sendDebugToGrafana(payload, retry + 1);
@@ -441,6 +437,15 @@ class IssueReporter {
441
437
  });
442
438
  }
443
439
 
440
+ _writeRetryCount(message , count ) {
441
+ if (message && typeof message === 'object') {
442
+ // $FlowFixMe
443
+ message._retry = count;
444
+ }
445
+
446
+ return message;
447
+ }
448
+
444
449
  _isLevelAbove(level1 , level2 ) {
445
450
  const index1 = LOG_LEVELS.indexOf(level1);
446
451
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -7007,8 +7012,10 @@ class WebRTCClient extends Emitter {
7007
7012
  conference: isConference,
7008
7013
  };
7009
7014
 
7010
- // Avoid sdh to created a new stream
7011
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7015
+ // Avoid sdh to create a new stream
7016
+ if (session.sessionDescriptionHandler) {
7017
+ session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
7018
+ }
7012
7019
 
7013
7020
  // Send re-INVITE
7014
7021
  return session.invite(options);
@@ -7851,7 +7858,7 @@ class WebRTCClient extends Emitter {
7851
7858
  }
7852
7859
 
7853
7860
  async _onHeartbeatTimeout() {
7854
- logger$9.info('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
7861
+ logger$9.warn('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
7855
7862
 
7856
7863
  if (this.heartbeatTimeoutCb) {
7857
7864
  this.heartbeatTimeoutCb();
@@ -8797,7 +8804,7 @@ class WebSocketClient extends Emitter {
8797
8804
  this.close();
8798
8805
  }
8799
8806
  const url = `wss://${this.host || ''}/api/websocketd/?token=${this.token || ''}&version=${this.version}`;
8800
- logger$8.log('Wazo WS url computed to reconnect', { url });
8807
+ logger$8.info('Wazo WS url computed to reconnect', { url });
8801
8808
 
8802
8809
  return url;
8803
8810
  }
@@ -14111,6 +14118,334 @@ const createLocalVideoStream = async (options ) => createLocalStream('vid
14111
14118
 
14112
14119
  const createLocalAudioStream = async (options ) => createLocalStream('audio', options);
14113
14120
 
14121
+ //
14122
+ /* eslint-disable no-unused-vars */
14123
+ /* global window, document */
14124
+ const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
14125
+ const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
14126
+ const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
14127
+ const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
14128
+ const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
14129
+ const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
14130
+ const BRIDGE_SEARCH_OPTIONS = 'bridge/BRIDGE_SEARCH_OPTIONS';
14131
+ const BRIDGE_DISPLAY_LINKED_OPTION = 'bridge/DISPLAY_LINKED_OPTION';
14132
+ const BRIDGE_UPDATE_FORM_SCHEMA = 'bridge/BRIDGE_UPDATE_FORM_SCHEMA';
14133
+ const BRIDGE_WAZO_CONTACT_SEARCH = 'bridge/BRIDGE_WAZO_CONTACT_SEARCH';
14134
+ const BRIDGE_ON_AGENT_LOGGED_IN = 'bridge/BRIDGE_ON_AGENT_LOGGED_IN';
14135
+ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
14136
+ const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
14137
+ const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
14138
+ const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
14139
+ const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
14140
+ const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
14141
+ const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
14142
+ const BRIDGE_ON_CALL_UN_MUTED = 'bridge/BRIDGE_ON_CALL_UN_MUTED';
14143
+ const BRIDGE_ON_DTMF = 'bridge/BRIDGE_ON_DTMF';
14144
+ const BRIDGE_ON_DIRECT_TRANSFER = 'bridge/BRIDGE_ON_DIRECT_TRANSFER';
14145
+ const BRIDGE_ON_CREATE_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CREATE_INDIRECT_TRANSFER';
14146
+ const BRIDGE_ON_CANCEL_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CANCEL_INDIRECT_TRANSFER';
14147
+ const BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER';
14148
+ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE';
14149
+ const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
14150
+ const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
14151
+ const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
14152
+
14153
+ const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
14154
+ const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
14155
+ const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
14156
+ const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
14157
+ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14158
+ const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
14159
+
14160
+ class Softphone {
14161
+ url = 'https://softphone.wazo.io';
14162
+ width = 500;
14163
+ height = 600;
14164
+ displayed = false;
14165
+ iframe = null;
14166
+
14167
+ onLinkEnabled(link ) {}
14168
+ onIFrameLoaded() {}
14169
+
14170
+ onCallMade(call ) {}
14171
+ onCallIncoming(call ) {}
14172
+ onCallEnded(call , card , direction , fromExtension ) {}
14173
+ onCardSaved(card ) {}
14174
+ onAuthenticated(session ) {}
14175
+ onLoggedOut() {}
14176
+ onSearchOptions(fieldId , query ) {}
14177
+ onDisplayLinkedOption(optionId ) {}
14178
+ onWazoContactSearch(query ) {}
14179
+ onAgentLoggedIn() {}
14180
+ onAgentLoggedOut() {}
14181
+ onAgentPaused() {}
14182
+ onAgentResumed() {}
14183
+ onLanguageChanged(language ) {}
14184
+ onCallHeld() {}
14185
+ onCallResumed() {}
14186
+ onCallMuted() {}
14187
+ onCallUnMuted() {}
14188
+ onDtmfSent(tone ) {}
14189
+ onDirectTransfer(number ) {}
14190
+ onCreateIndirectTransfer(number ) {}
14191
+ onCancelIndirectTransfer() {}
14192
+ onConfirmIndirectTransfer() {}
14193
+ onIndirectCallMade(call ) {}
14194
+ onIndirectTransferDone(call ) {}
14195
+ onStartRecording() {}
14196
+ onStopRecording() {}
14197
+ onUnHandledEvent(event ) {}
14198
+
14199
+ init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
14200
+ allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
14201
+ if (url) {
14202
+ this.url = url;
14203
+ }
14204
+ if (width) {
14205
+ this.width = width;
14206
+ }
14207
+ if (height) {
14208
+ this.height = height;
14209
+ }
14210
+
14211
+ window.addEventListener('message', this._onMessage.bind(this), false);
14212
+
14213
+ if (!server) {
14214
+ // eslint-disable-next-line no-param-reassign
14215
+ server = 'stack.dev.wazo.io';
14216
+ }
14217
+
14218
+ this._createIframe(() => {
14219
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
14220
+ config: {
14221
+ server,
14222
+ port,
14223
+ language,
14224
+ wrapUpDuration,
14225
+ shouldDisplayLinkedEntities,
14226
+ allowContactCreation,
14227
+ },
14228
+ });
14229
+
14230
+ if (withCard) {
14231
+ this._sendMessage(BRIDGE_ENABLE_CARD);
14232
+ }
14233
+
14234
+ if (subscriptionType) {
14235
+ this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
14236
+ }
14237
+
14238
+ this.onIFrameLoaded();
14239
+ });
14240
+ }
14241
+
14242
+ parseLinks() {
14243
+ const links = this._getLinks();
14244
+
14245
+ links.forEach(link => {
14246
+ link.setAttribute('data-wazo-parsed', true);
14247
+ link.addEventListener('click', this._onLinkClick.bind(this));
14248
+ this.onLinkEnabled(link);
14249
+ });
14250
+ }
14251
+
14252
+ makeCall(number ) {
14253
+ this.displaySoftphone();
14254
+
14255
+ this._sendMessage(SDK_CLICK_TO_CALL, { number });
14256
+ }
14257
+
14258
+ toggleSoftphoneDisplay() {
14259
+ if (this.displayed) {
14260
+ this.hideSoftphone();
14261
+ } else {
14262
+ this.displaySoftphone();
14263
+ }
14264
+ }
14265
+
14266
+ displaySoftphone() {
14267
+ if (!this.iframe) {
14268
+ this._createIframe();
14269
+ }
14270
+
14271
+ if (this.iframe) {
14272
+ this.iframe.style.display = 'block';
14273
+ }
14274
+
14275
+ this.displayed = true;
14276
+ }
14277
+
14278
+ hideSoftphone() {
14279
+ if (this.iframe) {
14280
+ this.iframe.style.display = 'none';
14281
+ }
14282
+ this.displayed = false;
14283
+ }
14284
+
14285
+ optionsFetched(fieldId , options ) {
14286
+ this._sendMessage(BRIDGE_OPTIONS_FETCHED, { fieldId, options });
14287
+ }
14288
+
14289
+ onOptionsResults(fieldId , options ) {
14290
+ this._sendMessage(BRIDGE_OPTIONS_FOUND, { fieldId, options });
14291
+ }
14292
+
14293
+ setFormSchema(schema , uiSchema ) {
14294
+ this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14295
+ }
14296
+
14297
+ _createIframe(cb = () => {}) {
14298
+ this.iframe = document.createElement('iframe');
14299
+ // $FlowFixMe
14300
+ this.iframe.width = this.width;
14301
+ // $FlowFixMe
14302
+ this.iframe.height = this.height;
14303
+ // $FlowFixMe
14304
+ this.iframe.allow = 'camera *; microphone *; autoplay *; display-capture *';
14305
+ this.iframe.style.position = 'absolute';
14306
+ this.iframe.style.left = '0';
14307
+ this.iframe.style.bottom = '0';
14308
+ this.iframe.style.border = '1px solid #aaa';
14309
+ this.iframe.style.backgroundColor = 'white';
14310
+ this.iframe.src = this.url;
14311
+ this.iframe.style.display = 'none';
14312
+ this.iframe.id = 'wazo-softphone';
14313
+
14314
+ this.iframe.onload = cb;
14315
+
14316
+ // $FlowFixMe
14317
+ document.body.appendChild(this.iframe);
14318
+ }
14319
+
14320
+ _getLinks() {
14321
+ return [].slice.call(document.querySelectorAll('a:not([data-wazo-parsed])'), 0)
14322
+ .filter(link => link.href.indexOf('tel:') === 0 || link.href.indexOf('callto:') === 0);
14323
+ }
14324
+
14325
+ _onLinkClick(e ) {
14326
+ e.preventDefault();
14327
+ const number = e.target.href.split(':')[1];
14328
+
14329
+ this.makeCall(number);
14330
+ }
14331
+
14332
+ _onAuthenticated() {
14333
+ this.parseLinks();
14334
+ }
14335
+
14336
+ _onMessage(event ) {
14337
+ if (!event.data) {
14338
+ return;
14339
+ }
14340
+
14341
+ switch (event.data.type) {
14342
+ case SDK_ON_CALL_MADE:
14343
+ this.onCallMade(event.data.callSession);
14344
+ break;
14345
+ case SDK_CALL_ENDED: {
14346
+ const { callSession, content, direction, userExtension } = event.data;
14347
+ this.onCallEnded(callSession, content, direction, userExtension);
14348
+ break;
14349
+ }
14350
+ case SDK_CALL_INCOMING:
14351
+ this.onCallIncoming(event.data.callSession);
14352
+ break;
14353
+ case SDK_AUTHENTICATED:
14354
+ // $FlowFixMe
14355
+ this._onAuthenticated(event.data.session);
14356
+ this.onAuthenticated(event.data.session);
14357
+ break;
14358
+ case SDK_LOGGED_OUT:
14359
+ this.onLoggedOut();
14360
+ break;
14361
+ case BRIDGE_CREATE_OR_UPDATE_CARD: {
14362
+ const { content } = event.data;
14363
+ this.onCardSaved(content);
14364
+ break;
14365
+ }
14366
+ case BRIDGE_SEARCH_OPTIONS: {
14367
+ const { fieldId, query } = event.data;
14368
+ this.onSearchOptions(fieldId, query);
14369
+ break;
14370
+ }
14371
+ case BRIDGE_DISPLAY_LINKED_OPTION:
14372
+ this.onDisplayLinkedOption(event.data.linkedOptionId);
14373
+ break;
14374
+ case BRIDGE_WAZO_CONTACT_SEARCH:
14375
+ this.onWazoContactSearch(event.data.query);
14376
+ break;
14377
+ case BRIDGE_ON_AGENT_LOGGED_IN:
14378
+ this.onAgentLoggedIn();
14379
+ break;
14380
+ case BRIDGE_ON_AGENT_LOGGED_OUT:
14381
+ this.onAgentLoggedOut();
14382
+ break;
14383
+ case BRIDGE_ON_AGENT_PAUSED:
14384
+ this.onAgentPaused();
14385
+ break;
14386
+ case BRIDGE_ON_AGENT_RESUMED:
14387
+ this.onAgentResumed();
14388
+ break;
14389
+ case BRIDGE_ON_LANGUAGE_CHANGED:
14390
+ this.onLanguageChanged(event.data.language);
14391
+ break;
14392
+ case BRIDGE_ON_CALL_HELD:
14393
+ this.onCallHeld();
14394
+ break;
14395
+ case BRIDGE_ON_CALL_RESUMED:
14396
+ this.onCallResumed();
14397
+ break;
14398
+ case BRIDGE_ON_CALL_MUTED:
14399
+ this.onCallMuted();
14400
+ break;
14401
+ case BRIDGE_ON_CALL_UN_MUTED:
14402
+ this.onCallUnMuted();
14403
+ break;
14404
+ case BRIDGE_ON_DTMF:
14405
+ this.onDtmfSent(event.data.tone);
14406
+ break;
14407
+ case BRIDGE_ON_DIRECT_TRANSFER:
14408
+ this.onDirectTransfer(event.data.number);
14409
+ break;
14410
+ case BRIDGE_ON_CREATE_INDIRECT_TRANSFER:
14411
+ this.onCreateIndirectTransfer(event.data.number);
14412
+ break;
14413
+ case BRIDGE_ON_CANCEL_INDIRECT_TRANSFER:
14414
+ this.onCancelIndirectTransfer();
14415
+ break;
14416
+ case BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER:
14417
+ this.onConfirmIndirectTransfer();
14418
+ break;
14419
+ case BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE:
14420
+ this.onIndirectCallMade(event.data.call);
14421
+ break;
14422
+ case BRIDGE_ON_INDIRECT_TRANSFER_DONE:
14423
+ this.onIndirectTransferDone(event.data.call);
14424
+ break;
14425
+ case BRIDGE_ON_START_RECORDING:
14426
+ this.onStartRecording();
14427
+ break;
14428
+ case BRIDGE_ON_STOP_RECORDING:
14429
+ this.onStopRecording();
14430
+ break;
14431
+ default:
14432
+ this.onUnHandledEvent(event);
14433
+ break;
14434
+ }
14435
+ }
14436
+
14437
+ _sendMessage(type , payload = {}) {
14438
+ if (!this.iframe) {
14439
+ console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
14440
+ return;
14441
+ }
14442
+
14443
+ this.iframe.contentWindow.postMessage({ type, ...payload }, '*');
14444
+ }
14445
+ }
14446
+
14447
+ var Softphone$1 = new Softphone();
14448
+
14114
14449
  /* global window */
14115
14450
 
14116
14451
  const Wazo = {
@@ -14131,6 +14466,7 @@ const Wazo = {
14131
14466
  loggerFor: IssueReporter$1.loggerFor.bind(IssueReporter$1),
14132
14467
  Features: Features$1,
14133
14468
  Checker,
14469
+ Softphone: Softphone$1,
14134
14470
 
14135
14471
  // Domain
14136
14472
  domain: {
@@ -373,13 +373,9 @@ class IssueReporter {
373
373
 
374
374
  setTimeout(() => {
375
375
  if (isArray) {
376
- payload = payload.map(message => {
377
- message._retry = retry + 1;
378
- return message;
379
- });
380
- } else {
381
- // $FlowFixMe
382
- payload._retry = retry + 1;
376
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
377
+ } else if (payload && typeof payload === 'object') {
378
+ payload = this._writeRetryCount(payload, retry + 1);
383
379
  }
384
380
 
385
381
  this._sendDebugToGrafana(payload, retry + 1);
@@ -387,6 +383,15 @@ class IssueReporter {
387
383
  });
388
384
  }
389
385
 
386
+ _writeRetryCount(message , count ) {
387
+ if (message && typeof message === 'object') {
388
+ // $FlowFixMe
389
+ message._retry = count;
390
+ }
391
+
392
+ return message;
393
+ }
394
+
390
395
  _isLevelAbove(level1 , level2 ) {
391
396
  const index1 = LOG_LEVELS.indexOf(level1);
392
397
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2436,13 +2436,9 @@ class IssueReporter {
2436
2436
 
2437
2437
  setTimeout(() => {
2438
2438
  if (isArray) {
2439
- payload = payload.map(message => {
2440
- message._retry = retry + 1;
2441
- return message;
2442
- });
2443
- } else {
2444
- // $FlowFixMe
2445
- payload._retry = retry + 1;
2439
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
2440
+ } else if (payload && typeof payload === 'object') {
2441
+ payload = this._writeRetryCount(payload, retry + 1);
2446
2442
  }
2447
2443
 
2448
2444
  this._sendDebugToGrafana(payload, retry + 1);
@@ -2450,6 +2446,15 @@ class IssueReporter {
2450
2446
  });
2451
2447
  }
2452
2448
 
2449
+ _writeRetryCount(message , count ) {
2450
+ if (message && typeof message === 'object') {
2451
+ // $FlowFixMe
2452
+ message._retry = count;
2453
+ }
2454
+
2455
+ return message;
2456
+ }
2457
+
2453
2458
  _isLevelAbove(level1 , level2 ) {
2454
2459
  const index1 = LOG_LEVELS.indexOf(level1);
2455
2460
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -365,13 +365,9 @@ class IssueReporter {
365
365
 
366
366
  setTimeout(() => {
367
367
  if (isArray) {
368
- payload = payload.map(message => {
369
- message._retry = retry + 1;
370
- return message;
371
- });
372
- } else {
373
- // $FlowFixMe
374
- payload._retry = retry + 1;
368
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
369
+ } else if (payload && typeof payload === 'object') {
370
+ payload = this._writeRetryCount(payload, retry + 1);
375
371
  }
376
372
 
377
373
  this._sendDebugToGrafana(payload, retry + 1);
@@ -379,6 +375,15 @@ class IssueReporter {
379
375
  });
380
376
  }
381
377
 
378
+ _writeRetryCount(message , count ) {
379
+ if (message && typeof message === 'object') {
380
+ // $FlowFixMe
381
+ message._retry = count;
382
+ }
383
+
384
+ return message;
385
+ }
386
+
382
387
  _isLevelAbove(level1 , level2 ) {
383
388
  const index1 = LOG_LEVELS.indexOf(level1);
384
389
  const index2 = LOG_LEVELS.indexOf(level2);