@wazo/sdk 0.38.1 → 0.38.4

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.
@@ -13684,8 +13684,6 @@ class Checker {
13684
13684
  /* eslint-disable no-unused-vars */
13685
13685
  /* global window, document */
13686
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
13687
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13690
13688
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13691
13689
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -13698,6 +13696,9 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13698
13696
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13699
13697
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13700
13698
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13699
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
13700
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
13701
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
13701
13702
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13702
13703
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13703
13704
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -13711,31 +13712,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
13711
13712
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13712
13713
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13713
13714
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13715
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
13716
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
13717
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
13718
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
13719
+
13720
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
13721
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
13714
13722
 
13715
13723
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13716
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13724
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
13717
13725
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13718
13726
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13719
13727
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13720
13728
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13721
13729
 
13722
13730
  class Softphone {
13723
- url = 'https://softphone.wazo.io';
13724
- width = 500;
13725
- height = 600;
13726
- displayed = false;
13727
- iframe = null;
13731
+
13732
+
13733
+
13734
+
13735
+
13736
+
13737
+
13738
+ // Message waiting for the iframe to be loaded
13739
+
13728
13740
 
13729
13741
  onLinkEnabled(link ) {}
13730
13742
  onIFrameLoaded() {}
13731
13743
 
13732
- onCallMade(call ) {}
13744
+ onCallLocallyAnswered(call ) {}
13745
+ onCallEstablished(call ) {}
13746
+ onOutgoingCallMade(call ) {}
13733
13747
  onCallIncoming(call ) {}
13748
+ onCallRejected(call ) {}
13734
13749
  onCallEnded(call , card , direction , fromExtension ) {}
13750
+
13735
13751
  onCardSaved(card ) {}
13752
+ onCardCanceled() {}
13736
13753
  onAuthenticated(session ) {}
13737
13754
  onLoggedOut() {}
13738
- onSearchOptions(fieldId , query ) {}
13755
+
13756
+ onSearchOptions(fieldId , query ) {
13757
+ this.onOptionsResults(fieldId, []);
13758
+ }
13759
+
13739
13760
  onDisplayLinkedOption(optionId ) {}
13740
13761
  onWazoContactSearch(query ) {}
13741
13762
  onAgentLoggedIn() {}
@@ -13758,18 +13779,26 @@ class Softphone {
13758
13779
  onStopRecording() {}
13759
13780
  onUnHandledEvent(event ) {}
13760
13781
 
13761
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
13762
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13763
- if (url) {
13764
- this.url = url;
13765
- }
13766
- if (width) {
13767
- this.width = width;
13768
- }
13769
- if (height) {
13770
- this.height = height;
13771
- }
13782
+ init({
13783
+ url,
13784
+ width,
13785
+ height,
13786
+ server,
13787
+ port,
13788
+ language,
13789
+ wrapUpDuration,
13790
+ enableAgent = true,
13791
+ tenantId,
13792
+ debug = false,
13793
+ } = {}) {
13794
+ this.url = url || 'https://softphone.wazo.io';
13795
+ this.width = width || 500;
13796
+ this.height = height || 600;
13797
+ this.displayed = false;
13798
+ this.iframeLoaded = false;
13772
13799
 
13800
+ this.iframeLoaded = false;
13801
+ this._pendingMessages = [];
13773
13802
  window.addEventListener('message', this._onMessage.bind(this), false);
13774
13803
 
13775
13804
  if (!server) {
@@ -13777,25 +13806,33 @@ class Softphone {
13777
13806
  server = 'stack.dev.wazo.io';
13778
13807
  }
13779
13808
 
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
- });
13809
+ const config = { server };
13810
+ if (language) {
13811
+ config.language = language;
13812
+ }
13813
+ if (port) {
13814
+ config.port = port;
13815
+ }
13816
+ if (tenantId) {
13817
+ config.tenantId = tenantId;
13818
+ }
13819
+ if (wrapUpDuration) {
13820
+ config.wrapUpDuration = wrapUpDuration;
13821
+ }
13791
13822
 
13792
- if (withCard) {
13793
- this._sendMessage(BRIDGE_ENABLE_CARD);
13794
- }
13823
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
13795
13824
 
13796
- if (subscriptionType) {
13797
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
13798
- }
13825
+ if (enableAgent) {
13826
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
13827
+ }
13828
+
13829
+ if (debug) {
13830
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
13831
+ }
13832
+
13833
+ this._createIframe(() => {
13834
+ this.iframeLoaded = true;
13835
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
13799
13836
 
13800
13837
  this.onIFrameLoaded();
13801
13838
  });
@@ -13856,6 +13893,18 @@ class Softphone {
13856
13893
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13857
13894
  }
13858
13895
 
13896
+ setCardValue(field , value ) {
13897
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
13898
+ }
13899
+
13900
+ injectCss(css ) {
13901
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
13902
+ }
13903
+
13904
+ customizeAppearance(themes , translations , assets ) {
13905
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
13906
+ }
13907
+
13859
13908
  _createIframe(cb = () => {}) {
13860
13909
  this.iframe = document.createElement('iframe');
13861
13910
  // $FlowFixMe
@@ -13901,8 +13950,8 @@ class Softphone {
13901
13950
  }
13902
13951
 
13903
13952
  switch (event.data.type) {
13904
- case SDK_ON_CALL_MADE:
13905
- this.onCallMade(event.data.callSession);
13953
+ case SDK_ON_OUTGOING_CALL_MADE:
13954
+ this.onOutgoingCallMade(event.data.callSession);
13906
13955
  break;
13907
13956
  case SDK_CALL_ENDED: {
13908
13957
  const { callSession, content, direction, userExtension } = event.data;
@@ -13990,6 +14039,18 @@ class Softphone {
13990
14039
  case BRIDGE_ON_STOP_RECORDING:
13991
14040
  this.onStopRecording();
13992
14041
  break;
14042
+ case BRIDGE_ON_CARD_CANCELED:
14043
+ this.onCardCanceled();
14044
+ break;
14045
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
14046
+ this.onCallLocallyAnswered(event.data.call);
14047
+ break;
14048
+ case BRIDGE_ON_CALL_REJECTED:
14049
+ this.onCallRejected(event.data.call);
14050
+ break;
14051
+ case BRIDGE_ON_CALL_ESTABLISHED:
14052
+ this.onCallEstablished(event.data.call);
14053
+ break;
13993
14054
  default:
13994
14055
  this.onUnHandledEvent(event);
13995
14056
  break;
@@ -13997,8 +14058,8 @@ class Softphone {
13997
14058
  }
13998
14059
 
13999
14060
  _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`);
14061
+ if (!this.iframe || !this.iframeLoaded) {
14062
+ this._pendingMessages.push([type, payload]);
14002
14063
  return;
14003
14064
  }
14004
14065
 
@@ -13665,8 +13665,6 @@ class Checker {
13665
13665
  /* eslint-disable no-unused-vars */
13666
13666
  /* global window, document */
13667
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
13668
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13671
13669
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13672
13670
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -13679,6 +13677,9 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13679
13677
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13680
13678
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13681
13679
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13680
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
13681
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
13682
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
13682
13683
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13683
13684
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13684
13685
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -13692,31 +13693,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
13692
13693
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13693
13694
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13694
13695
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13696
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
13697
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
13698
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
13699
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
13700
+
13701
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
13702
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
13695
13703
 
13696
13704
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13697
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13705
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
13698
13706
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13699
13707
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13700
13708
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13701
13709
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13702
13710
 
13703
13711
  class Softphone {
13704
- url = 'https://softphone.wazo.io';
13705
- width = 500;
13706
- height = 600;
13707
- displayed = false;
13708
- iframe = null;
13712
+
13713
+
13714
+
13715
+
13716
+
13717
+
13718
+
13719
+ // Message waiting for the iframe to be loaded
13720
+
13709
13721
 
13710
13722
  onLinkEnabled(link ) {}
13711
13723
  onIFrameLoaded() {}
13712
13724
 
13713
- onCallMade(call ) {}
13725
+ onCallLocallyAnswered(call ) {}
13726
+ onCallEstablished(call ) {}
13727
+ onOutgoingCallMade(call ) {}
13714
13728
  onCallIncoming(call ) {}
13729
+ onCallRejected(call ) {}
13715
13730
  onCallEnded(call , card , direction , fromExtension ) {}
13731
+
13716
13732
  onCardSaved(card ) {}
13733
+ onCardCanceled() {}
13717
13734
  onAuthenticated(session ) {}
13718
13735
  onLoggedOut() {}
13719
- onSearchOptions(fieldId , query ) {}
13736
+
13737
+ onSearchOptions(fieldId , query ) {
13738
+ this.onOptionsResults(fieldId, []);
13739
+ }
13740
+
13720
13741
  onDisplayLinkedOption(optionId ) {}
13721
13742
  onWazoContactSearch(query ) {}
13722
13743
  onAgentLoggedIn() {}
@@ -13739,18 +13760,26 @@ class Softphone {
13739
13760
  onStopRecording() {}
13740
13761
  onUnHandledEvent(event ) {}
13741
13762
 
13742
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
13743
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13744
- if (url) {
13745
- this.url = url;
13746
- }
13747
- if (width) {
13748
- this.width = width;
13749
- }
13750
- if (height) {
13751
- this.height = height;
13752
- }
13763
+ init({
13764
+ url,
13765
+ width,
13766
+ height,
13767
+ server,
13768
+ port,
13769
+ language,
13770
+ wrapUpDuration,
13771
+ enableAgent = true,
13772
+ tenantId,
13773
+ debug = false,
13774
+ } = {}) {
13775
+ this.url = url || 'https://softphone.wazo.io';
13776
+ this.width = width || 500;
13777
+ this.height = height || 600;
13778
+ this.displayed = false;
13779
+ this.iframeLoaded = false;
13753
13780
 
13781
+ this.iframeLoaded = false;
13782
+ this._pendingMessages = [];
13754
13783
  window.addEventListener('message', this._onMessage.bind(this), false);
13755
13784
 
13756
13785
  if (!server) {
@@ -13758,25 +13787,33 @@ class Softphone {
13758
13787
  server = 'stack.dev.wazo.io';
13759
13788
  }
13760
13789
 
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
- });
13790
+ const config = { server };
13791
+ if (language) {
13792
+ config.language = language;
13793
+ }
13794
+ if (port) {
13795
+ config.port = port;
13796
+ }
13797
+ if (tenantId) {
13798
+ config.tenantId = tenantId;
13799
+ }
13800
+ if (wrapUpDuration) {
13801
+ config.wrapUpDuration = wrapUpDuration;
13802
+ }
13772
13803
 
13773
- if (withCard) {
13774
- this._sendMessage(BRIDGE_ENABLE_CARD);
13775
- }
13804
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
13776
13805
 
13777
- if (subscriptionType) {
13778
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
13779
- }
13806
+ if (enableAgent) {
13807
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
13808
+ }
13809
+
13810
+ if (debug) {
13811
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
13812
+ }
13813
+
13814
+ this._createIframe(() => {
13815
+ this.iframeLoaded = true;
13816
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
13780
13817
 
13781
13818
  this.onIFrameLoaded();
13782
13819
  });
@@ -13837,6 +13874,18 @@ class Softphone {
13837
13874
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13838
13875
  }
13839
13876
 
13877
+ setCardValue(field , value ) {
13878
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
13879
+ }
13880
+
13881
+ injectCss(css ) {
13882
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
13883
+ }
13884
+
13885
+ customizeAppearance(themes , translations , assets ) {
13886
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
13887
+ }
13888
+
13840
13889
  _createIframe(cb = () => {}) {
13841
13890
  this.iframe = document.createElement('iframe');
13842
13891
  // $FlowFixMe
@@ -13882,8 +13931,8 @@ class Softphone {
13882
13931
  }
13883
13932
 
13884
13933
  switch (event.data.type) {
13885
- case SDK_ON_CALL_MADE:
13886
- this.onCallMade(event.data.callSession);
13934
+ case SDK_ON_OUTGOING_CALL_MADE:
13935
+ this.onOutgoingCallMade(event.data.callSession);
13887
13936
  break;
13888
13937
  case SDK_CALL_ENDED: {
13889
13938
  const { callSession, content, direction, userExtension } = event.data;
@@ -13971,6 +14020,18 @@ class Softphone {
13971
14020
  case BRIDGE_ON_STOP_RECORDING:
13972
14021
  this.onStopRecording();
13973
14022
  break;
14023
+ case BRIDGE_ON_CARD_CANCELED:
14024
+ this.onCardCanceled();
14025
+ break;
14026
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
14027
+ this.onCallLocallyAnswered(event.data.call);
14028
+ break;
14029
+ case BRIDGE_ON_CALL_REJECTED:
14030
+ this.onCallRejected(event.data.call);
14031
+ break;
14032
+ case BRIDGE_ON_CALL_ESTABLISHED:
14033
+ this.onCallEstablished(event.data.call);
14034
+ break;
13974
14035
  default:
13975
14036
  this.onUnHandledEvent(event);
13976
14037
  break;
@@ -13978,8 +14039,8 @@ class Softphone {
13978
14039
  }
13979
14040
 
13980
14041
  _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`);
14042
+ if (!this.iframe || !this.iframeLoaded) {
14043
+ this._pendingMessages.push([type, payload]);
13983
14044
  return;
13984
14045
  }
13985
14046
 
@@ -13573,8 +13573,6 @@ class Checker {
13573
13573
  /* eslint-disable no-unused-vars */
13574
13574
  /* global window, document */
13575
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
13576
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13579
13577
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13580
13578
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -13587,6 +13585,9 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13587
13585
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13588
13586
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13589
13587
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13588
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
13589
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
13590
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
13590
13591
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13591
13592
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13592
13593
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -13600,31 +13601,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
13600
13601
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13601
13602
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13602
13603
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13604
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
13605
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
13606
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
13607
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
13608
+
13609
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
13610
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
13603
13611
 
13604
13612
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13605
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13613
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
13606
13614
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13607
13615
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13608
13616
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13609
13617
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13610
13618
 
13611
13619
  class Softphone {
13612
- url = 'https://softphone.wazo.io';
13613
- width = 500;
13614
- height = 600;
13615
- displayed = false;
13616
- iframe = null;
13620
+
13621
+
13622
+
13623
+
13624
+
13625
+
13626
+
13627
+ // Message waiting for the iframe to be loaded
13628
+
13617
13629
 
13618
13630
  onLinkEnabled(link ) {}
13619
13631
  onIFrameLoaded() {}
13620
13632
 
13621
- onCallMade(call ) {}
13633
+ onCallLocallyAnswered(call ) {}
13634
+ onCallEstablished(call ) {}
13635
+ onOutgoingCallMade(call ) {}
13622
13636
  onCallIncoming(call ) {}
13637
+ onCallRejected(call ) {}
13623
13638
  onCallEnded(call , card , direction , fromExtension ) {}
13639
+
13624
13640
  onCardSaved(card ) {}
13641
+ onCardCanceled() {}
13625
13642
  onAuthenticated(session ) {}
13626
13643
  onLoggedOut() {}
13627
- onSearchOptions(fieldId , query ) {}
13644
+
13645
+ onSearchOptions(fieldId , query ) {
13646
+ this.onOptionsResults(fieldId, []);
13647
+ }
13648
+
13628
13649
  onDisplayLinkedOption(optionId ) {}
13629
13650
  onWazoContactSearch(query ) {}
13630
13651
  onAgentLoggedIn() {}
@@ -13647,18 +13668,26 @@ class Softphone {
13647
13668
  onStopRecording() {}
13648
13669
  onUnHandledEvent(event ) {}
13649
13670
 
13650
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
13651
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13652
- if (url) {
13653
- this.url = url;
13654
- }
13655
- if (width) {
13656
- this.width = width;
13657
- }
13658
- if (height) {
13659
- this.height = height;
13660
- }
13671
+ init({
13672
+ url,
13673
+ width,
13674
+ height,
13675
+ server,
13676
+ port,
13677
+ language,
13678
+ wrapUpDuration,
13679
+ enableAgent = true,
13680
+ tenantId,
13681
+ debug = false,
13682
+ } = {}) {
13683
+ this.url = url || 'https://softphone.wazo.io';
13684
+ this.width = width || 500;
13685
+ this.height = height || 600;
13686
+ this.displayed = false;
13687
+ this.iframeLoaded = false;
13661
13688
 
13689
+ this.iframeLoaded = false;
13690
+ this._pendingMessages = [];
13662
13691
  window.addEventListener('message', this._onMessage.bind(this), false);
13663
13692
 
13664
13693
  if (!server) {
@@ -13666,25 +13695,33 @@ class Softphone {
13666
13695
  server = 'stack.dev.wazo.io';
13667
13696
  }
13668
13697
 
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
- });
13698
+ const config = { server };
13699
+ if (language) {
13700
+ config.language = language;
13701
+ }
13702
+ if (port) {
13703
+ config.port = port;
13704
+ }
13705
+ if (tenantId) {
13706
+ config.tenantId = tenantId;
13707
+ }
13708
+ if (wrapUpDuration) {
13709
+ config.wrapUpDuration = wrapUpDuration;
13710
+ }
13680
13711
 
13681
- if (withCard) {
13682
- this._sendMessage(BRIDGE_ENABLE_CARD);
13683
- }
13712
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
13684
13713
 
13685
- if (subscriptionType) {
13686
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
13687
- }
13714
+ if (enableAgent) {
13715
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
13716
+ }
13717
+
13718
+ if (debug) {
13719
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
13720
+ }
13721
+
13722
+ this._createIframe(() => {
13723
+ this.iframeLoaded = true;
13724
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
13688
13725
 
13689
13726
  this.onIFrameLoaded();
13690
13727
  });
@@ -13745,6 +13782,18 @@ class Softphone {
13745
13782
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13746
13783
  }
13747
13784
 
13785
+ setCardValue(field , value ) {
13786
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
13787
+ }
13788
+
13789
+ injectCss(css ) {
13790
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
13791
+ }
13792
+
13793
+ customizeAppearance(themes , translations , assets ) {
13794
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
13795
+ }
13796
+
13748
13797
  _createIframe(cb = () => {}) {
13749
13798
  this.iframe = document.createElement('iframe');
13750
13799
  // $FlowFixMe
@@ -13790,8 +13839,8 @@ class Softphone {
13790
13839
  }
13791
13840
 
13792
13841
  switch (event.data.type) {
13793
- case SDK_ON_CALL_MADE:
13794
- this.onCallMade(event.data.callSession);
13842
+ case SDK_ON_OUTGOING_CALL_MADE:
13843
+ this.onOutgoingCallMade(event.data.callSession);
13795
13844
  break;
13796
13845
  case SDK_CALL_ENDED: {
13797
13846
  const { callSession, content, direction, userExtension } = event.data;
@@ -13879,6 +13928,18 @@ class Softphone {
13879
13928
  case BRIDGE_ON_STOP_RECORDING:
13880
13929
  this.onStopRecording();
13881
13930
  break;
13931
+ case BRIDGE_ON_CARD_CANCELED:
13932
+ this.onCardCanceled();
13933
+ break;
13934
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
13935
+ this.onCallLocallyAnswered(event.data.call);
13936
+ break;
13937
+ case BRIDGE_ON_CALL_REJECTED:
13938
+ this.onCallRejected(event.data.call);
13939
+ break;
13940
+ case BRIDGE_ON_CALL_ESTABLISHED:
13941
+ this.onCallEstablished(event.data.call);
13942
+ break;
13882
13943
  default:
13883
13944
  this.onUnHandledEvent(event);
13884
13945
  break;
@@ -13886,8 +13947,8 @@ class Softphone {
13886
13947
  }
13887
13948
 
13888
13949
  _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`);
13950
+ if (!this.iframe || !this.iframeLoaded) {
13951
+ this._pendingMessages.push([type, payload]);
13891
13952
  return;
13892
13953
  }
13893
13954