@wazo/sdk 0.38.0 → 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 (45) hide show
  1. package/README.md +218 -0
  2. package/dist/wazo-sdk.js +5 -5
  3. package/esm/__tests__/web-rtc-client.test.js +1 -1
  4. package/esm/checker/Checker.js +1 -1
  5. package/esm/checker/checks/index.js +1 -1
  6. package/esm/checker/checks/webrtc-transport.js +1 -1
  7. package/esm/checker/checks/webrtc.js +1 -1
  8. package/esm/index.js +191 -10
  9. package/esm/simple/Auth.js +191 -10
  10. package/esm/simple/Configuration.js +191 -10
  11. package/esm/simple/Phone.js +191 -10
  12. package/esm/simple/Softphone.js +189 -8
  13. package/esm/simple/index.js +191 -10
  14. package/esm/simple/room/LocalParticipant.js +191 -10
  15. package/esm/simple/room/Participant.js +191 -10
  16. package/esm/simple/room/RemoteParticipant.js +191 -10
  17. package/esm/simple/room/Room.js +191 -10
  18. package/esm/simple/room/SipRoom.js +191 -10
  19. package/esm/simple/room/Stream.js +191 -10
  20. package/esm/simple/room/__tests__/RemoteParticipant.test.js +191 -10
  21. package/esm/simple/utils.js +191 -10
  22. package/esm/web-rtc-client.js +1 -1
  23. package/lib/__tests__/web-rtc-client.test.js +1 -1
  24. package/lib/checker/Checker.js +1 -1
  25. package/lib/checker/checks/index.js +1 -1
  26. package/lib/checker/checks/webrtc-transport.js +1 -1
  27. package/lib/checker/checks/webrtc.js +1 -1
  28. package/lib/index.js +191 -10
  29. package/lib/simple/Auth.js +191 -10
  30. package/lib/simple/Configuration.js +191 -10
  31. package/lib/simple/Phone.js +191 -10
  32. package/lib/simple/Softphone.js +189 -8
  33. package/lib/simple/index.js +191 -10
  34. package/lib/simple/room/LocalParticipant.js +191 -10
  35. package/lib/simple/room/Participant.js +191 -10
  36. package/lib/simple/room/RemoteParticipant.js +191 -10
  37. package/lib/simple/room/Room.js +191 -10
  38. package/lib/simple/room/SipRoom.js +191 -10
  39. package/lib/simple/room/Stream.js +191 -10
  40. package/lib/simple/room/__tests__/RemoteParticipant.test.js +191 -10
  41. package/lib/simple/utils.js +191 -10
  42. package/lib/web-rtc-client.js +1 -1
  43. package/package.json +1 -1
  44. package/src/simple/Softphone.js +187 -8
  45. package/src/web-rtc-client.js +1 -1
package/lib/index.js CHANGED
@@ -7858,7 +7858,7 @@ class WebRTCClient extends Emitter {
7858
7858
  }
7859
7859
 
7860
7860
  async _onHeartbeatTimeout() {
7861
- 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 });
7862
7862
 
7863
7863
  if (this.heartbeatTimeoutCb) {
7864
7864
  this.heartbeatTimeoutCb();
@@ -14121,11 +14121,41 @@ const createLocalAudioStream = async (options ) => createLocalStream('aud
14121
14121
  //
14122
14122
  /* eslint-disable no-unused-vars */
14123
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
+
14124
14153
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
14125
14154
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
14126
14155
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
14127
14156
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
14128
14157
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14158
+ const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
14129
14159
 
14130
14160
  class Softphone {
14131
14161
  url = 'https://softphone.wazo.io';
@@ -14135,13 +14165,39 @@ class Softphone {
14135
14165
  iframe = null;
14136
14166
 
14137
14167
  onLinkEnabled(link ) {}
14168
+ onIFrameLoaded() {}
14138
14169
 
14139
14170
  onCallMade(call ) {}
14140
14171
  onCallIncoming(call ) {}
14141
14172
  onCallEnded(call , card , direction , fromExtension ) {}
14173
+ onCardSaved(card ) {}
14142
14174
  onAuthenticated(session ) {}
14143
-
14144
- init(url , width , height ) {
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 } = {}) {
14145
14201
  if (url) {
14146
14202
  this.url = url;
14147
14203
  }
@@ -14154,7 +14210,33 @@ class Softphone {
14154
14210
 
14155
14211
  window.addEventListener('message', this._onMessage.bind(this), false);
14156
14212
 
14157
- this._createIframe();
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
+ });
14158
14240
  }
14159
14241
 
14160
14242
  parseLinks() {
@@ -14170,9 +14252,7 @@ class Softphone {
14170
14252
  makeCall(number ) {
14171
14253
  this.displaySoftphone();
14172
14254
 
14173
- if (this.iframe) {
14174
- this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
14175
- }
14255
+ this._sendMessage(SDK_CLICK_TO_CALL, { number });
14176
14256
  }
14177
14257
 
14178
14258
  toggleSoftphoneDisplay() {
@@ -14181,8 +14261,6 @@ class Softphone {
14181
14261
  } else {
14182
14262
  this.displaySoftphone();
14183
14263
  }
14184
-
14185
- this.displayed = !this.displayed;
14186
14264
  }
14187
14265
 
14188
14266
  displaySoftphone() {
@@ -14193,15 +14271,30 @@ class Softphone {
14193
14271
  if (this.iframe) {
14194
14272
  this.iframe.style.display = 'block';
14195
14273
  }
14274
+
14275
+ this.displayed = true;
14196
14276
  }
14197
14277
 
14198
14278
  hideSoftphone() {
14199
14279
  if (this.iframe) {
14200
14280
  this.iframe.style.display = 'none';
14201
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 });
14202
14295
  }
14203
14296
 
14204
- _createIframe() {
14297
+ _createIframe(cb = () => {}) {
14205
14298
  this.iframe = document.createElement('iframe');
14206
14299
  // $FlowFixMe
14207
14300
  this.iframe.width = this.width;
@@ -14213,10 +14306,13 @@ class Softphone {
14213
14306
  this.iframe.style.left = '0';
14214
14307
  this.iframe.style.bottom = '0';
14215
14308
  this.iframe.style.border = '1px solid #aaa';
14309
+ this.iframe.style.backgroundColor = 'white';
14216
14310
  this.iframe.src = this.url;
14217
14311
  this.iframe.style.display = 'none';
14218
14312
  this.iframe.id = 'wazo-softphone';
14219
14313
 
14314
+ this.iframe.onload = cb;
14315
+
14220
14316
  // $FlowFixMe
14221
14317
  document.body.appendChild(this.iframe);
14222
14318
  }
@@ -14259,8 +14355,93 @@ class Softphone {
14259
14355
  this._onAuthenticated(event.data.session);
14260
14356
  this.onAuthenticated(event.data.session);
14261
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;
14262
14434
  }
14263
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
+ }
14264
14445
  }
14265
14446
 
14266
14447
  var Softphone$1 = new Softphone();
@@ -8037,7 +8037,7 @@ class WebRTCClient extends Emitter {
8037
8037
  }
8038
8038
 
8039
8039
  async _onHeartbeatTimeout() {
8040
- logger$9.info('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8040
+ logger$9.warn('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8041
8041
 
8042
8042
  if (this.heartbeatTimeoutCb) {
8043
8043
  this.heartbeatTimeoutCb();
@@ -13683,11 +13683,41 @@ class Checker {
13683
13683
  //
13684
13684
  /* eslint-disable no-unused-vars */
13685
13685
  /* global window, document */
13686
+ const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13687
+ const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13688
+ const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13689
+ const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13690
+ const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13691
+ const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
13692
+ const BRIDGE_SEARCH_OPTIONS = 'bridge/BRIDGE_SEARCH_OPTIONS';
13693
+ const BRIDGE_DISPLAY_LINKED_OPTION = 'bridge/DISPLAY_LINKED_OPTION';
13694
+ const BRIDGE_UPDATE_FORM_SCHEMA = 'bridge/BRIDGE_UPDATE_FORM_SCHEMA';
13695
+ const BRIDGE_WAZO_CONTACT_SEARCH = 'bridge/BRIDGE_WAZO_CONTACT_SEARCH';
13696
+ const BRIDGE_ON_AGENT_LOGGED_IN = 'bridge/BRIDGE_ON_AGENT_LOGGED_IN';
13697
+ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13698
+ const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13699
+ const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13700
+ const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13701
+ const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13702
+ const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13703
+ const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
13704
+ const BRIDGE_ON_CALL_UN_MUTED = 'bridge/BRIDGE_ON_CALL_UN_MUTED';
13705
+ const BRIDGE_ON_DTMF = 'bridge/BRIDGE_ON_DTMF';
13706
+ const BRIDGE_ON_DIRECT_TRANSFER = 'bridge/BRIDGE_ON_DIRECT_TRANSFER';
13707
+ const BRIDGE_ON_CREATE_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CREATE_INDIRECT_TRANSFER';
13708
+ const BRIDGE_ON_CANCEL_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CANCEL_INDIRECT_TRANSFER';
13709
+ const BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER';
13710
+ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE';
13711
+ const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13712
+ const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13713
+ const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13714
+
13686
13715
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13687
13716
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13688
13717
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13689
13718
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13690
13719
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13720
+ const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13691
13721
 
13692
13722
  class Softphone {
13693
13723
  url = 'https://softphone.wazo.io';
@@ -13697,13 +13727,39 @@ class Softphone {
13697
13727
  iframe = null;
13698
13728
 
13699
13729
  onLinkEnabled(link ) {}
13730
+ onIFrameLoaded() {}
13700
13731
 
13701
13732
  onCallMade(call ) {}
13702
13733
  onCallIncoming(call ) {}
13703
13734
  onCallEnded(call , card , direction , fromExtension ) {}
13735
+ onCardSaved(card ) {}
13704
13736
  onAuthenticated(session ) {}
13705
-
13706
- init(url , width , height ) {
13737
+ onLoggedOut() {}
13738
+ onSearchOptions(fieldId , query ) {}
13739
+ onDisplayLinkedOption(optionId ) {}
13740
+ onWazoContactSearch(query ) {}
13741
+ onAgentLoggedIn() {}
13742
+ onAgentLoggedOut() {}
13743
+ onAgentPaused() {}
13744
+ onAgentResumed() {}
13745
+ onLanguageChanged(language ) {}
13746
+ onCallHeld() {}
13747
+ onCallResumed() {}
13748
+ onCallMuted() {}
13749
+ onCallUnMuted() {}
13750
+ onDtmfSent(tone ) {}
13751
+ onDirectTransfer(number ) {}
13752
+ onCreateIndirectTransfer(number ) {}
13753
+ onCancelIndirectTransfer() {}
13754
+ onConfirmIndirectTransfer() {}
13755
+ onIndirectCallMade(call ) {}
13756
+ onIndirectTransferDone(call ) {}
13757
+ onStartRecording() {}
13758
+ onStopRecording() {}
13759
+ onUnHandledEvent(event ) {}
13760
+
13761
+ init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
13762
+ allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13707
13763
  if (url) {
13708
13764
  this.url = url;
13709
13765
  }
@@ -13716,7 +13772,33 @@ class Softphone {
13716
13772
 
13717
13773
  window.addEventListener('message', this._onMessage.bind(this), false);
13718
13774
 
13719
- this._createIframe();
13775
+ if (!server) {
13776
+ // eslint-disable-next-line no-param-reassign
13777
+ server = 'stack.dev.wazo.io';
13778
+ }
13779
+
13780
+ this._createIframe(() => {
13781
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
13782
+ config: {
13783
+ server,
13784
+ port,
13785
+ language,
13786
+ wrapUpDuration,
13787
+ shouldDisplayLinkedEntities,
13788
+ allowContactCreation,
13789
+ },
13790
+ });
13791
+
13792
+ if (withCard) {
13793
+ this._sendMessage(BRIDGE_ENABLE_CARD);
13794
+ }
13795
+
13796
+ if (subscriptionType) {
13797
+ this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
13798
+ }
13799
+
13800
+ this.onIFrameLoaded();
13801
+ });
13720
13802
  }
13721
13803
 
13722
13804
  parseLinks() {
@@ -13732,9 +13814,7 @@ class Softphone {
13732
13814
  makeCall(number ) {
13733
13815
  this.displaySoftphone();
13734
13816
 
13735
- if (this.iframe) {
13736
- this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
13737
- }
13817
+ this._sendMessage(SDK_CLICK_TO_CALL, { number });
13738
13818
  }
13739
13819
 
13740
13820
  toggleSoftphoneDisplay() {
@@ -13743,8 +13823,6 @@ class Softphone {
13743
13823
  } else {
13744
13824
  this.displaySoftphone();
13745
13825
  }
13746
-
13747
- this.displayed = !this.displayed;
13748
13826
  }
13749
13827
 
13750
13828
  displaySoftphone() {
@@ -13755,15 +13833,30 @@ class Softphone {
13755
13833
  if (this.iframe) {
13756
13834
  this.iframe.style.display = 'block';
13757
13835
  }
13836
+
13837
+ this.displayed = true;
13758
13838
  }
13759
13839
 
13760
13840
  hideSoftphone() {
13761
13841
  if (this.iframe) {
13762
13842
  this.iframe.style.display = 'none';
13763
13843
  }
13844
+ this.displayed = false;
13845
+ }
13846
+
13847
+ optionsFetched(fieldId , options ) {
13848
+ this._sendMessage(BRIDGE_OPTIONS_FETCHED, { fieldId, options });
13849
+ }
13850
+
13851
+ onOptionsResults(fieldId , options ) {
13852
+ this._sendMessage(BRIDGE_OPTIONS_FOUND, { fieldId, options });
13853
+ }
13854
+
13855
+ setFormSchema(schema , uiSchema ) {
13856
+ this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13764
13857
  }
13765
13858
 
13766
- _createIframe() {
13859
+ _createIframe(cb = () => {}) {
13767
13860
  this.iframe = document.createElement('iframe');
13768
13861
  // $FlowFixMe
13769
13862
  this.iframe.width = this.width;
@@ -13775,10 +13868,13 @@ class Softphone {
13775
13868
  this.iframe.style.left = '0';
13776
13869
  this.iframe.style.bottom = '0';
13777
13870
  this.iframe.style.border = '1px solid #aaa';
13871
+ this.iframe.style.backgroundColor = 'white';
13778
13872
  this.iframe.src = this.url;
13779
13873
  this.iframe.style.display = 'none';
13780
13874
  this.iframe.id = 'wazo-softphone';
13781
13875
 
13876
+ this.iframe.onload = cb;
13877
+
13782
13878
  // $FlowFixMe
13783
13879
  document.body.appendChild(this.iframe);
13784
13880
  }
@@ -13821,8 +13917,93 @@ class Softphone {
13821
13917
  this._onAuthenticated(event.data.session);
13822
13918
  this.onAuthenticated(event.data.session);
13823
13919
  break;
13920
+ case SDK_LOGGED_OUT:
13921
+ this.onLoggedOut();
13922
+ break;
13923
+ case BRIDGE_CREATE_OR_UPDATE_CARD: {
13924
+ const { content } = event.data;
13925
+ this.onCardSaved(content);
13926
+ break;
13927
+ }
13928
+ case BRIDGE_SEARCH_OPTIONS: {
13929
+ const { fieldId, query } = event.data;
13930
+ this.onSearchOptions(fieldId, query);
13931
+ break;
13932
+ }
13933
+ case BRIDGE_DISPLAY_LINKED_OPTION:
13934
+ this.onDisplayLinkedOption(event.data.linkedOptionId);
13935
+ break;
13936
+ case BRIDGE_WAZO_CONTACT_SEARCH:
13937
+ this.onWazoContactSearch(event.data.query);
13938
+ break;
13939
+ case BRIDGE_ON_AGENT_LOGGED_IN:
13940
+ this.onAgentLoggedIn();
13941
+ break;
13942
+ case BRIDGE_ON_AGENT_LOGGED_OUT:
13943
+ this.onAgentLoggedOut();
13944
+ break;
13945
+ case BRIDGE_ON_AGENT_PAUSED:
13946
+ this.onAgentPaused();
13947
+ break;
13948
+ case BRIDGE_ON_AGENT_RESUMED:
13949
+ this.onAgentResumed();
13950
+ break;
13951
+ case BRIDGE_ON_LANGUAGE_CHANGED:
13952
+ this.onLanguageChanged(event.data.language);
13953
+ break;
13954
+ case BRIDGE_ON_CALL_HELD:
13955
+ this.onCallHeld();
13956
+ break;
13957
+ case BRIDGE_ON_CALL_RESUMED:
13958
+ this.onCallResumed();
13959
+ break;
13960
+ case BRIDGE_ON_CALL_MUTED:
13961
+ this.onCallMuted();
13962
+ break;
13963
+ case BRIDGE_ON_CALL_UN_MUTED:
13964
+ this.onCallUnMuted();
13965
+ break;
13966
+ case BRIDGE_ON_DTMF:
13967
+ this.onDtmfSent(event.data.tone);
13968
+ break;
13969
+ case BRIDGE_ON_DIRECT_TRANSFER:
13970
+ this.onDirectTransfer(event.data.number);
13971
+ break;
13972
+ case BRIDGE_ON_CREATE_INDIRECT_TRANSFER:
13973
+ this.onCreateIndirectTransfer(event.data.number);
13974
+ break;
13975
+ case BRIDGE_ON_CANCEL_INDIRECT_TRANSFER:
13976
+ this.onCancelIndirectTransfer();
13977
+ break;
13978
+ case BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER:
13979
+ this.onConfirmIndirectTransfer();
13980
+ break;
13981
+ case BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE:
13982
+ this.onIndirectCallMade(event.data.call);
13983
+ break;
13984
+ case BRIDGE_ON_INDIRECT_TRANSFER_DONE:
13985
+ this.onIndirectTransferDone(event.data.call);
13986
+ break;
13987
+ case BRIDGE_ON_START_RECORDING:
13988
+ this.onStartRecording();
13989
+ break;
13990
+ case BRIDGE_ON_STOP_RECORDING:
13991
+ this.onStopRecording();
13992
+ break;
13993
+ default:
13994
+ this.onUnHandledEvent(event);
13995
+ break;
13824
13996
  }
13825
13997
  }
13998
+
13999
+ _sendMessage(type , payload = {}) {
14000
+ if (!this.iframe) {
14001
+ console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
14002
+ return;
14003
+ }
14004
+
14005
+ this.iframe.contentWindow.postMessage({ type, ...payload }, '*');
14006
+ }
13826
14007
  }
13827
14008
 
13828
14009
  var Softphone$1 = new Softphone();