@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
@@ -8035,7 +8035,7 @@ class WebRTCClient extends Emitter {
8035
8035
  }
8036
8036
 
8037
8037
  async _onHeartbeatTimeout() {
8038
- logger$9.info('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8038
+ logger$9.warn('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8039
8039
 
8040
8040
  if (this.heartbeatTimeoutCb) {
8041
8041
  this.heartbeatTimeoutCb();
@@ -13664,11 +13664,41 @@ class Checker {
13664
13664
  //
13665
13665
  /* eslint-disable no-unused-vars */
13666
13666
  /* global window, document */
13667
+ const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13668
+ const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13669
+ const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13670
+ const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13671
+ const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13672
+ const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
13673
+ const BRIDGE_SEARCH_OPTIONS = 'bridge/BRIDGE_SEARCH_OPTIONS';
13674
+ const BRIDGE_DISPLAY_LINKED_OPTION = 'bridge/DISPLAY_LINKED_OPTION';
13675
+ const BRIDGE_UPDATE_FORM_SCHEMA = 'bridge/BRIDGE_UPDATE_FORM_SCHEMA';
13676
+ const BRIDGE_WAZO_CONTACT_SEARCH = 'bridge/BRIDGE_WAZO_CONTACT_SEARCH';
13677
+ const BRIDGE_ON_AGENT_LOGGED_IN = 'bridge/BRIDGE_ON_AGENT_LOGGED_IN';
13678
+ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13679
+ const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13680
+ const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13681
+ const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13682
+ const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13683
+ const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13684
+ const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
13685
+ const BRIDGE_ON_CALL_UN_MUTED = 'bridge/BRIDGE_ON_CALL_UN_MUTED';
13686
+ const BRIDGE_ON_DTMF = 'bridge/BRIDGE_ON_DTMF';
13687
+ const BRIDGE_ON_DIRECT_TRANSFER = 'bridge/BRIDGE_ON_DIRECT_TRANSFER';
13688
+ const BRIDGE_ON_CREATE_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CREATE_INDIRECT_TRANSFER';
13689
+ const BRIDGE_ON_CANCEL_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CANCEL_INDIRECT_TRANSFER';
13690
+ const BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER';
13691
+ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE';
13692
+ const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13693
+ const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13694
+ const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13695
+
13667
13696
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13668
13697
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13669
13698
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13670
13699
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13671
13700
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13701
+ const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13672
13702
 
13673
13703
  class Softphone {
13674
13704
  url = 'https://softphone.wazo.io';
@@ -13678,13 +13708,39 @@ class Softphone {
13678
13708
  iframe = null;
13679
13709
 
13680
13710
  onLinkEnabled(link ) {}
13711
+ onIFrameLoaded() {}
13681
13712
 
13682
13713
  onCallMade(call ) {}
13683
13714
  onCallIncoming(call ) {}
13684
13715
  onCallEnded(call , card , direction , fromExtension ) {}
13716
+ onCardSaved(card ) {}
13685
13717
  onAuthenticated(session ) {}
13686
-
13687
- init(url , width , height ) {
13718
+ onLoggedOut() {}
13719
+ onSearchOptions(fieldId , query ) {}
13720
+ onDisplayLinkedOption(optionId ) {}
13721
+ onWazoContactSearch(query ) {}
13722
+ onAgentLoggedIn() {}
13723
+ onAgentLoggedOut() {}
13724
+ onAgentPaused() {}
13725
+ onAgentResumed() {}
13726
+ onLanguageChanged(language ) {}
13727
+ onCallHeld() {}
13728
+ onCallResumed() {}
13729
+ onCallMuted() {}
13730
+ onCallUnMuted() {}
13731
+ onDtmfSent(tone ) {}
13732
+ onDirectTransfer(number ) {}
13733
+ onCreateIndirectTransfer(number ) {}
13734
+ onCancelIndirectTransfer() {}
13735
+ onConfirmIndirectTransfer() {}
13736
+ onIndirectCallMade(call ) {}
13737
+ onIndirectTransferDone(call ) {}
13738
+ onStartRecording() {}
13739
+ onStopRecording() {}
13740
+ onUnHandledEvent(event ) {}
13741
+
13742
+ init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
13743
+ allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13688
13744
  if (url) {
13689
13745
  this.url = url;
13690
13746
  }
@@ -13697,7 +13753,33 @@ class Softphone {
13697
13753
 
13698
13754
  window.addEventListener('message', this._onMessage.bind(this), false);
13699
13755
 
13700
- this._createIframe();
13756
+ if (!server) {
13757
+ // eslint-disable-next-line no-param-reassign
13758
+ server = 'stack.dev.wazo.io';
13759
+ }
13760
+
13761
+ this._createIframe(() => {
13762
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
13763
+ config: {
13764
+ server,
13765
+ port,
13766
+ language,
13767
+ wrapUpDuration,
13768
+ shouldDisplayLinkedEntities,
13769
+ allowContactCreation,
13770
+ },
13771
+ });
13772
+
13773
+ if (withCard) {
13774
+ this._sendMessage(BRIDGE_ENABLE_CARD);
13775
+ }
13776
+
13777
+ if (subscriptionType) {
13778
+ this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
13779
+ }
13780
+
13781
+ this.onIFrameLoaded();
13782
+ });
13701
13783
  }
13702
13784
 
13703
13785
  parseLinks() {
@@ -13713,9 +13795,7 @@ class Softphone {
13713
13795
  makeCall(number ) {
13714
13796
  this.displaySoftphone();
13715
13797
 
13716
- if (this.iframe) {
13717
- this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
13718
- }
13798
+ this._sendMessage(SDK_CLICK_TO_CALL, { number });
13719
13799
  }
13720
13800
 
13721
13801
  toggleSoftphoneDisplay() {
@@ -13724,8 +13804,6 @@ class Softphone {
13724
13804
  } else {
13725
13805
  this.displaySoftphone();
13726
13806
  }
13727
-
13728
- this.displayed = !this.displayed;
13729
13807
  }
13730
13808
 
13731
13809
  displaySoftphone() {
@@ -13736,15 +13814,30 @@ class Softphone {
13736
13814
  if (this.iframe) {
13737
13815
  this.iframe.style.display = 'block';
13738
13816
  }
13817
+
13818
+ this.displayed = true;
13739
13819
  }
13740
13820
 
13741
13821
  hideSoftphone() {
13742
13822
  if (this.iframe) {
13743
13823
  this.iframe.style.display = 'none';
13744
13824
  }
13825
+ this.displayed = false;
13826
+ }
13827
+
13828
+ optionsFetched(fieldId , options ) {
13829
+ this._sendMessage(BRIDGE_OPTIONS_FETCHED, { fieldId, options });
13830
+ }
13831
+
13832
+ onOptionsResults(fieldId , options ) {
13833
+ this._sendMessage(BRIDGE_OPTIONS_FOUND, { fieldId, options });
13834
+ }
13835
+
13836
+ setFormSchema(schema , uiSchema ) {
13837
+ this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13745
13838
  }
13746
13839
 
13747
- _createIframe() {
13840
+ _createIframe(cb = () => {}) {
13748
13841
  this.iframe = document.createElement('iframe');
13749
13842
  // $FlowFixMe
13750
13843
  this.iframe.width = this.width;
@@ -13756,10 +13849,13 @@ class Softphone {
13756
13849
  this.iframe.style.left = '0';
13757
13850
  this.iframe.style.bottom = '0';
13758
13851
  this.iframe.style.border = '1px solid #aaa';
13852
+ this.iframe.style.backgroundColor = 'white';
13759
13853
  this.iframe.src = this.url;
13760
13854
  this.iframe.style.display = 'none';
13761
13855
  this.iframe.id = 'wazo-softphone';
13762
13856
 
13857
+ this.iframe.onload = cb;
13858
+
13763
13859
  // $FlowFixMe
13764
13860
  document.body.appendChild(this.iframe);
13765
13861
  }
@@ -13802,8 +13898,93 @@ class Softphone {
13802
13898
  this._onAuthenticated(event.data.session);
13803
13899
  this.onAuthenticated(event.data.session);
13804
13900
  break;
13901
+ case SDK_LOGGED_OUT:
13902
+ this.onLoggedOut();
13903
+ break;
13904
+ case BRIDGE_CREATE_OR_UPDATE_CARD: {
13905
+ const { content } = event.data;
13906
+ this.onCardSaved(content);
13907
+ break;
13908
+ }
13909
+ case BRIDGE_SEARCH_OPTIONS: {
13910
+ const { fieldId, query } = event.data;
13911
+ this.onSearchOptions(fieldId, query);
13912
+ break;
13913
+ }
13914
+ case BRIDGE_DISPLAY_LINKED_OPTION:
13915
+ this.onDisplayLinkedOption(event.data.linkedOptionId);
13916
+ break;
13917
+ case BRIDGE_WAZO_CONTACT_SEARCH:
13918
+ this.onWazoContactSearch(event.data.query);
13919
+ break;
13920
+ case BRIDGE_ON_AGENT_LOGGED_IN:
13921
+ this.onAgentLoggedIn();
13922
+ break;
13923
+ case BRIDGE_ON_AGENT_LOGGED_OUT:
13924
+ this.onAgentLoggedOut();
13925
+ break;
13926
+ case BRIDGE_ON_AGENT_PAUSED:
13927
+ this.onAgentPaused();
13928
+ break;
13929
+ case BRIDGE_ON_AGENT_RESUMED:
13930
+ this.onAgentResumed();
13931
+ break;
13932
+ case BRIDGE_ON_LANGUAGE_CHANGED:
13933
+ this.onLanguageChanged(event.data.language);
13934
+ break;
13935
+ case BRIDGE_ON_CALL_HELD:
13936
+ this.onCallHeld();
13937
+ break;
13938
+ case BRIDGE_ON_CALL_RESUMED:
13939
+ this.onCallResumed();
13940
+ break;
13941
+ case BRIDGE_ON_CALL_MUTED:
13942
+ this.onCallMuted();
13943
+ break;
13944
+ case BRIDGE_ON_CALL_UN_MUTED:
13945
+ this.onCallUnMuted();
13946
+ break;
13947
+ case BRIDGE_ON_DTMF:
13948
+ this.onDtmfSent(event.data.tone);
13949
+ break;
13950
+ case BRIDGE_ON_DIRECT_TRANSFER:
13951
+ this.onDirectTransfer(event.data.number);
13952
+ break;
13953
+ case BRIDGE_ON_CREATE_INDIRECT_TRANSFER:
13954
+ this.onCreateIndirectTransfer(event.data.number);
13955
+ break;
13956
+ case BRIDGE_ON_CANCEL_INDIRECT_TRANSFER:
13957
+ this.onCancelIndirectTransfer();
13958
+ break;
13959
+ case BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER:
13960
+ this.onConfirmIndirectTransfer();
13961
+ break;
13962
+ case BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE:
13963
+ this.onIndirectCallMade(event.data.call);
13964
+ break;
13965
+ case BRIDGE_ON_INDIRECT_TRANSFER_DONE:
13966
+ this.onIndirectTransferDone(event.data.call);
13967
+ break;
13968
+ case BRIDGE_ON_START_RECORDING:
13969
+ this.onStartRecording();
13970
+ break;
13971
+ case BRIDGE_ON_STOP_RECORDING:
13972
+ this.onStopRecording();
13973
+ break;
13974
+ default:
13975
+ this.onUnHandledEvent(event);
13976
+ break;
13805
13977
  }
13806
13978
  }
13979
+
13980
+ _sendMessage(type , payload = {}) {
13981
+ if (!this.iframe) {
13982
+ console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
13983
+ return;
13984
+ }
13985
+
13986
+ this.iframe.contentWindow.postMessage({ type, ...payload }, '*');
13987
+ }
13807
13988
  }
13808
13989
 
13809
13990
  var Softphone$1 = new Softphone();
@@ -8035,7 +8035,7 @@ class WebRTCClient extends Emitter {
8035
8035
  }
8036
8036
 
8037
8037
  async _onHeartbeatTimeout() {
8038
- logger$9.info('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8038
+ logger$9.warn('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8039
8039
 
8040
8040
  if (this.heartbeatTimeoutCb) {
8041
8041
  this.heartbeatTimeoutCb();
@@ -13572,11 +13572,41 @@ class Checker {
13572
13572
  //
13573
13573
  /* eslint-disable no-unused-vars */
13574
13574
  /* global window, document */
13575
+ const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13576
+ const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13577
+ const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13578
+ const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13579
+ const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13580
+ const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
13581
+ const BRIDGE_SEARCH_OPTIONS = 'bridge/BRIDGE_SEARCH_OPTIONS';
13582
+ const BRIDGE_DISPLAY_LINKED_OPTION = 'bridge/DISPLAY_LINKED_OPTION';
13583
+ const BRIDGE_UPDATE_FORM_SCHEMA = 'bridge/BRIDGE_UPDATE_FORM_SCHEMA';
13584
+ const BRIDGE_WAZO_CONTACT_SEARCH = 'bridge/BRIDGE_WAZO_CONTACT_SEARCH';
13585
+ const BRIDGE_ON_AGENT_LOGGED_IN = 'bridge/BRIDGE_ON_AGENT_LOGGED_IN';
13586
+ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13587
+ const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13588
+ const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13589
+ const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13590
+ const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13591
+ const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13592
+ const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
13593
+ const BRIDGE_ON_CALL_UN_MUTED = 'bridge/BRIDGE_ON_CALL_UN_MUTED';
13594
+ const BRIDGE_ON_DTMF = 'bridge/BRIDGE_ON_DTMF';
13595
+ const BRIDGE_ON_DIRECT_TRANSFER = 'bridge/BRIDGE_ON_DIRECT_TRANSFER';
13596
+ const BRIDGE_ON_CREATE_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CREATE_INDIRECT_TRANSFER';
13597
+ const BRIDGE_ON_CANCEL_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CANCEL_INDIRECT_TRANSFER';
13598
+ const BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER';
13599
+ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE';
13600
+ const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13601
+ const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13602
+ const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13603
+
13575
13604
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13576
13605
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13577
13606
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13578
13607
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13579
13608
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13609
+ const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13580
13610
 
13581
13611
  class Softphone {
13582
13612
  url = 'https://softphone.wazo.io';
@@ -13586,13 +13616,39 @@ class Softphone {
13586
13616
  iframe = null;
13587
13617
 
13588
13618
  onLinkEnabled(link ) {}
13619
+ onIFrameLoaded() {}
13589
13620
 
13590
13621
  onCallMade(call ) {}
13591
13622
  onCallIncoming(call ) {}
13592
13623
  onCallEnded(call , card , direction , fromExtension ) {}
13624
+ onCardSaved(card ) {}
13593
13625
  onAuthenticated(session ) {}
13594
-
13595
- init(url , width , height ) {
13626
+ onLoggedOut() {}
13627
+ onSearchOptions(fieldId , query ) {}
13628
+ onDisplayLinkedOption(optionId ) {}
13629
+ onWazoContactSearch(query ) {}
13630
+ onAgentLoggedIn() {}
13631
+ onAgentLoggedOut() {}
13632
+ onAgentPaused() {}
13633
+ onAgentResumed() {}
13634
+ onLanguageChanged(language ) {}
13635
+ onCallHeld() {}
13636
+ onCallResumed() {}
13637
+ onCallMuted() {}
13638
+ onCallUnMuted() {}
13639
+ onDtmfSent(tone ) {}
13640
+ onDirectTransfer(number ) {}
13641
+ onCreateIndirectTransfer(number ) {}
13642
+ onCancelIndirectTransfer() {}
13643
+ onConfirmIndirectTransfer() {}
13644
+ onIndirectCallMade(call ) {}
13645
+ onIndirectTransferDone(call ) {}
13646
+ onStartRecording() {}
13647
+ onStopRecording() {}
13648
+ onUnHandledEvent(event ) {}
13649
+
13650
+ init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
13651
+ allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13596
13652
  if (url) {
13597
13653
  this.url = url;
13598
13654
  }
@@ -13605,7 +13661,33 @@ class Softphone {
13605
13661
 
13606
13662
  window.addEventListener('message', this._onMessage.bind(this), false);
13607
13663
 
13608
- this._createIframe();
13664
+ if (!server) {
13665
+ // eslint-disable-next-line no-param-reassign
13666
+ server = 'stack.dev.wazo.io';
13667
+ }
13668
+
13669
+ this._createIframe(() => {
13670
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
13671
+ config: {
13672
+ server,
13673
+ port,
13674
+ language,
13675
+ wrapUpDuration,
13676
+ shouldDisplayLinkedEntities,
13677
+ allowContactCreation,
13678
+ },
13679
+ });
13680
+
13681
+ if (withCard) {
13682
+ this._sendMessage(BRIDGE_ENABLE_CARD);
13683
+ }
13684
+
13685
+ if (subscriptionType) {
13686
+ this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
13687
+ }
13688
+
13689
+ this.onIFrameLoaded();
13690
+ });
13609
13691
  }
13610
13692
 
13611
13693
  parseLinks() {
@@ -13621,9 +13703,7 @@ class Softphone {
13621
13703
  makeCall(number ) {
13622
13704
  this.displaySoftphone();
13623
13705
 
13624
- if (this.iframe) {
13625
- this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
13626
- }
13706
+ this._sendMessage(SDK_CLICK_TO_CALL, { number });
13627
13707
  }
13628
13708
 
13629
13709
  toggleSoftphoneDisplay() {
@@ -13632,8 +13712,6 @@ class Softphone {
13632
13712
  } else {
13633
13713
  this.displaySoftphone();
13634
13714
  }
13635
-
13636
- this.displayed = !this.displayed;
13637
13715
  }
13638
13716
 
13639
13717
  displaySoftphone() {
@@ -13644,15 +13722,30 @@ class Softphone {
13644
13722
  if (this.iframe) {
13645
13723
  this.iframe.style.display = 'block';
13646
13724
  }
13725
+
13726
+ this.displayed = true;
13647
13727
  }
13648
13728
 
13649
13729
  hideSoftphone() {
13650
13730
  if (this.iframe) {
13651
13731
  this.iframe.style.display = 'none';
13652
13732
  }
13733
+ this.displayed = false;
13734
+ }
13735
+
13736
+ optionsFetched(fieldId , options ) {
13737
+ this._sendMessage(BRIDGE_OPTIONS_FETCHED, { fieldId, options });
13738
+ }
13739
+
13740
+ onOptionsResults(fieldId , options ) {
13741
+ this._sendMessage(BRIDGE_OPTIONS_FOUND, { fieldId, options });
13742
+ }
13743
+
13744
+ setFormSchema(schema , uiSchema ) {
13745
+ this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13653
13746
  }
13654
13747
 
13655
- _createIframe() {
13748
+ _createIframe(cb = () => {}) {
13656
13749
  this.iframe = document.createElement('iframe');
13657
13750
  // $FlowFixMe
13658
13751
  this.iframe.width = this.width;
@@ -13664,10 +13757,13 @@ class Softphone {
13664
13757
  this.iframe.style.left = '0';
13665
13758
  this.iframe.style.bottom = '0';
13666
13759
  this.iframe.style.border = '1px solid #aaa';
13760
+ this.iframe.style.backgroundColor = 'white';
13667
13761
  this.iframe.src = this.url;
13668
13762
  this.iframe.style.display = 'none';
13669
13763
  this.iframe.id = 'wazo-softphone';
13670
13764
 
13765
+ this.iframe.onload = cb;
13766
+
13671
13767
  // $FlowFixMe
13672
13768
  document.body.appendChild(this.iframe);
13673
13769
  }
@@ -13710,8 +13806,93 @@ class Softphone {
13710
13806
  this._onAuthenticated(event.data.session);
13711
13807
  this.onAuthenticated(event.data.session);
13712
13808
  break;
13809
+ case SDK_LOGGED_OUT:
13810
+ this.onLoggedOut();
13811
+ break;
13812
+ case BRIDGE_CREATE_OR_UPDATE_CARD: {
13813
+ const { content } = event.data;
13814
+ this.onCardSaved(content);
13815
+ break;
13816
+ }
13817
+ case BRIDGE_SEARCH_OPTIONS: {
13818
+ const { fieldId, query } = event.data;
13819
+ this.onSearchOptions(fieldId, query);
13820
+ break;
13821
+ }
13822
+ case BRIDGE_DISPLAY_LINKED_OPTION:
13823
+ this.onDisplayLinkedOption(event.data.linkedOptionId);
13824
+ break;
13825
+ case BRIDGE_WAZO_CONTACT_SEARCH:
13826
+ this.onWazoContactSearch(event.data.query);
13827
+ break;
13828
+ case BRIDGE_ON_AGENT_LOGGED_IN:
13829
+ this.onAgentLoggedIn();
13830
+ break;
13831
+ case BRIDGE_ON_AGENT_LOGGED_OUT:
13832
+ this.onAgentLoggedOut();
13833
+ break;
13834
+ case BRIDGE_ON_AGENT_PAUSED:
13835
+ this.onAgentPaused();
13836
+ break;
13837
+ case BRIDGE_ON_AGENT_RESUMED:
13838
+ this.onAgentResumed();
13839
+ break;
13840
+ case BRIDGE_ON_LANGUAGE_CHANGED:
13841
+ this.onLanguageChanged(event.data.language);
13842
+ break;
13843
+ case BRIDGE_ON_CALL_HELD:
13844
+ this.onCallHeld();
13845
+ break;
13846
+ case BRIDGE_ON_CALL_RESUMED:
13847
+ this.onCallResumed();
13848
+ break;
13849
+ case BRIDGE_ON_CALL_MUTED:
13850
+ this.onCallMuted();
13851
+ break;
13852
+ case BRIDGE_ON_CALL_UN_MUTED:
13853
+ this.onCallUnMuted();
13854
+ break;
13855
+ case BRIDGE_ON_DTMF:
13856
+ this.onDtmfSent(event.data.tone);
13857
+ break;
13858
+ case BRIDGE_ON_DIRECT_TRANSFER:
13859
+ this.onDirectTransfer(event.data.number);
13860
+ break;
13861
+ case BRIDGE_ON_CREATE_INDIRECT_TRANSFER:
13862
+ this.onCreateIndirectTransfer(event.data.number);
13863
+ break;
13864
+ case BRIDGE_ON_CANCEL_INDIRECT_TRANSFER:
13865
+ this.onCancelIndirectTransfer();
13866
+ break;
13867
+ case BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER:
13868
+ this.onConfirmIndirectTransfer();
13869
+ break;
13870
+ case BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE:
13871
+ this.onIndirectCallMade(event.data.call);
13872
+ break;
13873
+ case BRIDGE_ON_INDIRECT_TRANSFER_DONE:
13874
+ this.onIndirectTransferDone(event.data.call);
13875
+ break;
13876
+ case BRIDGE_ON_START_RECORDING:
13877
+ this.onStartRecording();
13878
+ break;
13879
+ case BRIDGE_ON_STOP_RECORDING:
13880
+ this.onStopRecording();
13881
+ break;
13882
+ default:
13883
+ this.onUnHandledEvent(event);
13884
+ break;
13713
13885
  }
13714
13886
  }
13887
+
13888
+ _sendMessage(type , payload = {}) {
13889
+ if (!this.iframe) {
13890
+ console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
13891
+ return;
13892
+ }
13893
+
13894
+ this.iframe.contentWindow.postMessage({ type, ...payload }, '*');
13895
+ }
13715
13896
  }
13716
13897
 
13717
13898
  var Softphone$1 = new Softphone();