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