@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
@@ -8326,7 +8326,7 @@ class WebRTCClient extends Emitter {
8326
8326
  }
8327
8327
 
8328
8328
  async _onHeartbeatTimeout() {
8329
- logger$8.info('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8329
+ logger$8.warn('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8330
8330
 
8331
8331
  if (this.heartbeatTimeoutCb) {
8332
8332
  this.heartbeatTimeoutCb();
@@ -13833,11 +13833,41 @@ class Checker {
13833
13833
  //
13834
13834
  /* eslint-disable no-unused-vars */
13835
13835
  /* global window, document */
13836
+ const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13837
+ const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13838
+ const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13839
+ const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13840
+ const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13841
+ const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
13842
+ const BRIDGE_SEARCH_OPTIONS = 'bridge/BRIDGE_SEARCH_OPTIONS';
13843
+ const BRIDGE_DISPLAY_LINKED_OPTION = 'bridge/DISPLAY_LINKED_OPTION';
13844
+ const BRIDGE_UPDATE_FORM_SCHEMA = 'bridge/BRIDGE_UPDATE_FORM_SCHEMA';
13845
+ const BRIDGE_WAZO_CONTACT_SEARCH = 'bridge/BRIDGE_WAZO_CONTACT_SEARCH';
13846
+ const BRIDGE_ON_AGENT_LOGGED_IN = 'bridge/BRIDGE_ON_AGENT_LOGGED_IN';
13847
+ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13848
+ const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13849
+ const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13850
+ const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13851
+ const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13852
+ const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13853
+ const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
13854
+ const BRIDGE_ON_CALL_UN_MUTED = 'bridge/BRIDGE_ON_CALL_UN_MUTED';
13855
+ const BRIDGE_ON_DTMF = 'bridge/BRIDGE_ON_DTMF';
13856
+ const BRIDGE_ON_DIRECT_TRANSFER = 'bridge/BRIDGE_ON_DIRECT_TRANSFER';
13857
+ const BRIDGE_ON_CREATE_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CREATE_INDIRECT_TRANSFER';
13858
+ const BRIDGE_ON_CANCEL_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CANCEL_INDIRECT_TRANSFER';
13859
+ const BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER';
13860
+ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE';
13861
+ const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13862
+ const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13863
+ const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13864
+
13836
13865
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13837
13866
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13838
13867
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13839
13868
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13840
13869
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13870
+ const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13841
13871
 
13842
13872
  class Softphone {
13843
13873
  url = 'https://softphone.wazo.io';
@@ -13847,13 +13877,39 @@ class Softphone {
13847
13877
  iframe = null;
13848
13878
 
13849
13879
  onLinkEnabled(link ) {}
13880
+ onIFrameLoaded() {}
13850
13881
 
13851
13882
  onCallMade(call ) {}
13852
13883
  onCallIncoming(call ) {}
13853
13884
  onCallEnded(call , card , direction , fromExtension ) {}
13885
+ onCardSaved(card ) {}
13854
13886
  onAuthenticated(session ) {}
13855
-
13856
- init(url , width , height ) {
13887
+ onLoggedOut() {}
13888
+ onSearchOptions(fieldId , query ) {}
13889
+ onDisplayLinkedOption(optionId ) {}
13890
+ onWazoContactSearch(query ) {}
13891
+ onAgentLoggedIn() {}
13892
+ onAgentLoggedOut() {}
13893
+ onAgentPaused() {}
13894
+ onAgentResumed() {}
13895
+ onLanguageChanged(language ) {}
13896
+ onCallHeld() {}
13897
+ onCallResumed() {}
13898
+ onCallMuted() {}
13899
+ onCallUnMuted() {}
13900
+ onDtmfSent(tone ) {}
13901
+ onDirectTransfer(number ) {}
13902
+ onCreateIndirectTransfer(number ) {}
13903
+ onCancelIndirectTransfer() {}
13904
+ onConfirmIndirectTransfer() {}
13905
+ onIndirectCallMade(call ) {}
13906
+ onIndirectTransferDone(call ) {}
13907
+ onStartRecording() {}
13908
+ onStopRecording() {}
13909
+ onUnHandledEvent(event ) {}
13910
+
13911
+ init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
13912
+ allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13857
13913
  if (url) {
13858
13914
  this.url = url;
13859
13915
  }
@@ -13866,7 +13922,33 @@ class Softphone {
13866
13922
 
13867
13923
  window.addEventListener('message', this._onMessage.bind(this), false);
13868
13924
 
13869
- this._createIframe();
13925
+ if (!server) {
13926
+ // eslint-disable-next-line no-param-reassign
13927
+ server = 'stack.dev.wazo.io';
13928
+ }
13929
+
13930
+ this._createIframe(() => {
13931
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
13932
+ config: {
13933
+ server,
13934
+ port,
13935
+ language,
13936
+ wrapUpDuration,
13937
+ shouldDisplayLinkedEntities,
13938
+ allowContactCreation,
13939
+ },
13940
+ });
13941
+
13942
+ if (withCard) {
13943
+ this._sendMessage(BRIDGE_ENABLE_CARD);
13944
+ }
13945
+
13946
+ if (subscriptionType) {
13947
+ this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
13948
+ }
13949
+
13950
+ this.onIFrameLoaded();
13951
+ });
13870
13952
  }
13871
13953
 
13872
13954
  parseLinks() {
@@ -13882,9 +13964,7 @@ class Softphone {
13882
13964
  makeCall(number ) {
13883
13965
  this.displaySoftphone();
13884
13966
 
13885
- if (this.iframe) {
13886
- this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
13887
- }
13967
+ this._sendMessage(SDK_CLICK_TO_CALL, { number });
13888
13968
  }
13889
13969
 
13890
13970
  toggleSoftphoneDisplay() {
@@ -13893,8 +13973,6 @@ class Softphone {
13893
13973
  } else {
13894
13974
  this.displaySoftphone();
13895
13975
  }
13896
-
13897
- this.displayed = !this.displayed;
13898
13976
  }
13899
13977
 
13900
13978
  displaySoftphone() {
@@ -13905,15 +13983,30 @@ class Softphone {
13905
13983
  if (this.iframe) {
13906
13984
  this.iframe.style.display = 'block';
13907
13985
  }
13986
+
13987
+ this.displayed = true;
13908
13988
  }
13909
13989
 
13910
13990
  hideSoftphone() {
13911
13991
  if (this.iframe) {
13912
13992
  this.iframe.style.display = 'none';
13913
13993
  }
13994
+ this.displayed = false;
13995
+ }
13996
+
13997
+ optionsFetched(fieldId , options ) {
13998
+ this._sendMessage(BRIDGE_OPTIONS_FETCHED, { fieldId, options });
13999
+ }
14000
+
14001
+ onOptionsResults(fieldId , options ) {
14002
+ this._sendMessage(BRIDGE_OPTIONS_FOUND, { fieldId, options });
14003
+ }
14004
+
14005
+ setFormSchema(schema , uiSchema ) {
14006
+ this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13914
14007
  }
13915
14008
 
13916
- _createIframe() {
14009
+ _createIframe(cb = () => {}) {
13917
14010
  this.iframe = document.createElement('iframe');
13918
14011
  // $FlowFixMe
13919
14012
  this.iframe.width = this.width;
@@ -13925,10 +14018,13 @@ class Softphone {
13925
14018
  this.iframe.style.left = '0';
13926
14019
  this.iframe.style.bottom = '0';
13927
14020
  this.iframe.style.border = '1px solid #aaa';
14021
+ this.iframe.style.backgroundColor = 'white';
13928
14022
  this.iframe.src = this.url;
13929
14023
  this.iframe.style.display = 'none';
13930
14024
  this.iframe.id = 'wazo-softphone';
13931
14025
 
14026
+ this.iframe.onload = cb;
14027
+
13932
14028
  // $FlowFixMe
13933
14029
  document.body.appendChild(this.iframe);
13934
14030
  }
@@ -13971,8 +14067,93 @@ class Softphone {
13971
14067
  this._onAuthenticated(event.data.session);
13972
14068
  this.onAuthenticated(event.data.session);
13973
14069
  break;
14070
+ case SDK_LOGGED_OUT:
14071
+ this.onLoggedOut();
14072
+ break;
14073
+ case BRIDGE_CREATE_OR_UPDATE_CARD: {
14074
+ const { content } = event.data;
14075
+ this.onCardSaved(content);
14076
+ break;
14077
+ }
14078
+ case BRIDGE_SEARCH_OPTIONS: {
14079
+ const { fieldId, query } = event.data;
14080
+ this.onSearchOptions(fieldId, query);
14081
+ break;
14082
+ }
14083
+ case BRIDGE_DISPLAY_LINKED_OPTION:
14084
+ this.onDisplayLinkedOption(event.data.linkedOptionId);
14085
+ break;
14086
+ case BRIDGE_WAZO_CONTACT_SEARCH:
14087
+ this.onWazoContactSearch(event.data.query);
14088
+ break;
14089
+ case BRIDGE_ON_AGENT_LOGGED_IN:
14090
+ this.onAgentLoggedIn();
14091
+ break;
14092
+ case BRIDGE_ON_AGENT_LOGGED_OUT:
14093
+ this.onAgentLoggedOut();
14094
+ break;
14095
+ case BRIDGE_ON_AGENT_PAUSED:
14096
+ this.onAgentPaused();
14097
+ break;
14098
+ case BRIDGE_ON_AGENT_RESUMED:
14099
+ this.onAgentResumed();
14100
+ break;
14101
+ case BRIDGE_ON_LANGUAGE_CHANGED:
14102
+ this.onLanguageChanged(event.data.language);
14103
+ break;
14104
+ case BRIDGE_ON_CALL_HELD:
14105
+ this.onCallHeld();
14106
+ break;
14107
+ case BRIDGE_ON_CALL_RESUMED:
14108
+ this.onCallResumed();
14109
+ break;
14110
+ case BRIDGE_ON_CALL_MUTED:
14111
+ this.onCallMuted();
14112
+ break;
14113
+ case BRIDGE_ON_CALL_UN_MUTED:
14114
+ this.onCallUnMuted();
14115
+ break;
14116
+ case BRIDGE_ON_DTMF:
14117
+ this.onDtmfSent(event.data.tone);
14118
+ break;
14119
+ case BRIDGE_ON_DIRECT_TRANSFER:
14120
+ this.onDirectTransfer(event.data.number);
14121
+ break;
14122
+ case BRIDGE_ON_CREATE_INDIRECT_TRANSFER:
14123
+ this.onCreateIndirectTransfer(event.data.number);
14124
+ break;
14125
+ case BRIDGE_ON_CANCEL_INDIRECT_TRANSFER:
14126
+ this.onCancelIndirectTransfer();
14127
+ break;
14128
+ case BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER:
14129
+ this.onConfirmIndirectTransfer();
14130
+ break;
14131
+ case BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE:
14132
+ this.onIndirectCallMade(event.data.call);
14133
+ break;
14134
+ case BRIDGE_ON_INDIRECT_TRANSFER_DONE:
14135
+ this.onIndirectTransferDone(event.data.call);
14136
+ break;
14137
+ case BRIDGE_ON_START_RECORDING:
14138
+ this.onStartRecording();
14139
+ break;
14140
+ case BRIDGE_ON_STOP_RECORDING:
14141
+ this.onStopRecording();
14142
+ break;
14143
+ default:
14144
+ this.onUnHandledEvent(event);
14145
+ break;
13974
14146
  }
13975
14147
  }
14148
+
14149
+ _sendMessage(type , payload = {}) {
14150
+ if (!this.iframe) {
14151
+ console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
14152
+ return;
14153
+ }
14154
+
14155
+ this.iframe.contentWindow.postMessage({ type, ...payload }, '*');
14156
+ }
13976
14157
  }
13977
14158
 
13978
14159
  var Softphone$1 = new Softphone();
@@ -8326,7 +8326,7 @@ class WebRTCClient extends Emitter {
8326
8326
  }
8327
8327
 
8328
8328
  async _onHeartbeatTimeout() {
8329
- logger$8.info('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8329
+ logger$8.warn('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8330
8330
 
8331
8331
  if (this.heartbeatTimeoutCb) {
8332
8332
  this.heartbeatTimeoutCb();
@@ -13914,11 +13914,41 @@ class Checker {
13914
13914
  //
13915
13915
  /* eslint-disable no-unused-vars */
13916
13916
  /* global window, document */
13917
+ const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13918
+ const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13919
+ const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13920
+ const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13921
+ const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13922
+ const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
13923
+ const BRIDGE_SEARCH_OPTIONS = 'bridge/BRIDGE_SEARCH_OPTIONS';
13924
+ const BRIDGE_DISPLAY_LINKED_OPTION = 'bridge/DISPLAY_LINKED_OPTION';
13925
+ const BRIDGE_UPDATE_FORM_SCHEMA = 'bridge/BRIDGE_UPDATE_FORM_SCHEMA';
13926
+ const BRIDGE_WAZO_CONTACT_SEARCH = 'bridge/BRIDGE_WAZO_CONTACT_SEARCH';
13927
+ const BRIDGE_ON_AGENT_LOGGED_IN = 'bridge/BRIDGE_ON_AGENT_LOGGED_IN';
13928
+ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13929
+ const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13930
+ const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13931
+ const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13932
+ const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13933
+ const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13934
+ const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
13935
+ const BRIDGE_ON_CALL_UN_MUTED = 'bridge/BRIDGE_ON_CALL_UN_MUTED';
13936
+ const BRIDGE_ON_DTMF = 'bridge/BRIDGE_ON_DTMF';
13937
+ const BRIDGE_ON_DIRECT_TRANSFER = 'bridge/BRIDGE_ON_DIRECT_TRANSFER';
13938
+ const BRIDGE_ON_CREATE_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CREATE_INDIRECT_TRANSFER';
13939
+ const BRIDGE_ON_CANCEL_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CANCEL_INDIRECT_TRANSFER';
13940
+ const BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER';
13941
+ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE';
13942
+ const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13943
+ const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13944
+ const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13945
+
13917
13946
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13918
13947
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13919
13948
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13920
13949
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13921
13950
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13951
+ const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13922
13952
 
13923
13953
  class Softphone {
13924
13954
  url = 'https://softphone.wazo.io';
@@ -13928,13 +13958,39 @@ class Softphone {
13928
13958
  iframe = null;
13929
13959
 
13930
13960
  onLinkEnabled(link ) {}
13961
+ onIFrameLoaded() {}
13931
13962
 
13932
13963
  onCallMade(call ) {}
13933
13964
  onCallIncoming(call ) {}
13934
13965
  onCallEnded(call , card , direction , fromExtension ) {}
13966
+ onCardSaved(card ) {}
13935
13967
  onAuthenticated(session ) {}
13936
-
13937
- init(url , width , height ) {
13968
+ onLoggedOut() {}
13969
+ onSearchOptions(fieldId , query ) {}
13970
+ onDisplayLinkedOption(optionId ) {}
13971
+ onWazoContactSearch(query ) {}
13972
+ onAgentLoggedIn() {}
13973
+ onAgentLoggedOut() {}
13974
+ onAgentPaused() {}
13975
+ onAgentResumed() {}
13976
+ onLanguageChanged(language ) {}
13977
+ onCallHeld() {}
13978
+ onCallResumed() {}
13979
+ onCallMuted() {}
13980
+ onCallUnMuted() {}
13981
+ onDtmfSent(tone ) {}
13982
+ onDirectTransfer(number ) {}
13983
+ onCreateIndirectTransfer(number ) {}
13984
+ onCancelIndirectTransfer() {}
13985
+ onConfirmIndirectTransfer() {}
13986
+ onIndirectCallMade(call ) {}
13987
+ onIndirectTransferDone(call ) {}
13988
+ onStartRecording() {}
13989
+ onStopRecording() {}
13990
+ onUnHandledEvent(event ) {}
13991
+
13992
+ init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
13993
+ allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13938
13994
  if (url) {
13939
13995
  this.url = url;
13940
13996
  }
@@ -13947,7 +14003,33 @@ class Softphone {
13947
14003
 
13948
14004
  window.addEventListener('message', this._onMessage.bind(this), false);
13949
14005
 
13950
- this._createIframe();
14006
+ if (!server) {
14007
+ // eslint-disable-next-line no-param-reassign
14008
+ server = 'stack.dev.wazo.io';
14009
+ }
14010
+
14011
+ this._createIframe(() => {
14012
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
14013
+ config: {
14014
+ server,
14015
+ port,
14016
+ language,
14017
+ wrapUpDuration,
14018
+ shouldDisplayLinkedEntities,
14019
+ allowContactCreation,
14020
+ },
14021
+ });
14022
+
14023
+ if (withCard) {
14024
+ this._sendMessage(BRIDGE_ENABLE_CARD);
14025
+ }
14026
+
14027
+ if (subscriptionType) {
14028
+ this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
14029
+ }
14030
+
14031
+ this.onIFrameLoaded();
14032
+ });
13951
14033
  }
13952
14034
 
13953
14035
  parseLinks() {
@@ -13963,9 +14045,7 @@ class Softphone {
13963
14045
  makeCall(number ) {
13964
14046
  this.displaySoftphone();
13965
14047
 
13966
- if (this.iframe) {
13967
- this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
13968
- }
14048
+ this._sendMessage(SDK_CLICK_TO_CALL, { number });
13969
14049
  }
13970
14050
 
13971
14051
  toggleSoftphoneDisplay() {
@@ -13974,8 +14054,6 @@ class Softphone {
13974
14054
  } else {
13975
14055
  this.displaySoftphone();
13976
14056
  }
13977
-
13978
- this.displayed = !this.displayed;
13979
14057
  }
13980
14058
 
13981
14059
  displaySoftphone() {
@@ -13986,15 +14064,30 @@ class Softphone {
13986
14064
  if (this.iframe) {
13987
14065
  this.iframe.style.display = 'block';
13988
14066
  }
14067
+
14068
+ this.displayed = true;
13989
14069
  }
13990
14070
 
13991
14071
  hideSoftphone() {
13992
14072
  if (this.iframe) {
13993
14073
  this.iframe.style.display = 'none';
13994
14074
  }
14075
+ this.displayed = false;
14076
+ }
14077
+
14078
+ optionsFetched(fieldId , options ) {
14079
+ this._sendMessage(BRIDGE_OPTIONS_FETCHED, { fieldId, options });
14080
+ }
14081
+
14082
+ onOptionsResults(fieldId , options ) {
14083
+ this._sendMessage(BRIDGE_OPTIONS_FOUND, { fieldId, options });
14084
+ }
14085
+
14086
+ setFormSchema(schema , uiSchema ) {
14087
+ this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13995
14088
  }
13996
14089
 
13997
- _createIframe() {
14090
+ _createIframe(cb = () => {}) {
13998
14091
  this.iframe = document.createElement('iframe');
13999
14092
  // $FlowFixMe
14000
14093
  this.iframe.width = this.width;
@@ -14006,10 +14099,13 @@ class Softphone {
14006
14099
  this.iframe.style.left = '0';
14007
14100
  this.iframe.style.bottom = '0';
14008
14101
  this.iframe.style.border = '1px solid #aaa';
14102
+ this.iframe.style.backgroundColor = 'white';
14009
14103
  this.iframe.src = this.url;
14010
14104
  this.iframe.style.display = 'none';
14011
14105
  this.iframe.id = 'wazo-softphone';
14012
14106
 
14107
+ this.iframe.onload = cb;
14108
+
14013
14109
  // $FlowFixMe
14014
14110
  document.body.appendChild(this.iframe);
14015
14111
  }
@@ -14052,8 +14148,93 @@ class Softphone {
14052
14148
  this._onAuthenticated(event.data.session);
14053
14149
  this.onAuthenticated(event.data.session);
14054
14150
  break;
14151
+ case SDK_LOGGED_OUT:
14152
+ this.onLoggedOut();
14153
+ break;
14154
+ case BRIDGE_CREATE_OR_UPDATE_CARD: {
14155
+ const { content } = event.data;
14156
+ this.onCardSaved(content);
14157
+ break;
14158
+ }
14159
+ case BRIDGE_SEARCH_OPTIONS: {
14160
+ const { fieldId, query } = event.data;
14161
+ this.onSearchOptions(fieldId, query);
14162
+ break;
14163
+ }
14164
+ case BRIDGE_DISPLAY_LINKED_OPTION:
14165
+ this.onDisplayLinkedOption(event.data.linkedOptionId);
14166
+ break;
14167
+ case BRIDGE_WAZO_CONTACT_SEARCH:
14168
+ this.onWazoContactSearch(event.data.query);
14169
+ break;
14170
+ case BRIDGE_ON_AGENT_LOGGED_IN:
14171
+ this.onAgentLoggedIn();
14172
+ break;
14173
+ case BRIDGE_ON_AGENT_LOGGED_OUT:
14174
+ this.onAgentLoggedOut();
14175
+ break;
14176
+ case BRIDGE_ON_AGENT_PAUSED:
14177
+ this.onAgentPaused();
14178
+ break;
14179
+ case BRIDGE_ON_AGENT_RESUMED:
14180
+ this.onAgentResumed();
14181
+ break;
14182
+ case BRIDGE_ON_LANGUAGE_CHANGED:
14183
+ this.onLanguageChanged(event.data.language);
14184
+ break;
14185
+ case BRIDGE_ON_CALL_HELD:
14186
+ this.onCallHeld();
14187
+ break;
14188
+ case BRIDGE_ON_CALL_RESUMED:
14189
+ this.onCallResumed();
14190
+ break;
14191
+ case BRIDGE_ON_CALL_MUTED:
14192
+ this.onCallMuted();
14193
+ break;
14194
+ case BRIDGE_ON_CALL_UN_MUTED:
14195
+ this.onCallUnMuted();
14196
+ break;
14197
+ case BRIDGE_ON_DTMF:
14198
+ this.onDtmfSent(event.data.tone);
14199
+ break;
14200
+ case BRIDGE_ON_DIRECT_TRANSFER:
14201
+ this.onDirectTransfer(event.data.number);
14202
+ break;
14203
+ case BRIDGE_ON_CREATE_INDIRECT_TRANSFER:
14204
+ this.onCreateIndirectTransfer(event.data.number);
14205
+ break;
14206
+ case BRIDGE_ON_CANCEL_INDIRECT_TRANSFER:
14207
+ this.onCancelIndirectTransfer();
14208
+ break;
14209
+ case BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER:
14210
+ this.onConfirmIndirectTransfer();
14211
+ break;
14212
+ case BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE:
14213
+ this.onIndirectCallMade(event.data.call);
14214
+ break;
14215
+ case BRIDGE_ON_INDIRECT_TRANSFER_DONE:
14216
+ this.onIndirectTransferDone(event.data.call);
14217
+ break;
14218
+ case BRIDGE_ON_START_RECORDING:
14219
+ this.onStartRecording();
14220
+ break;
14221
+ case BRIDGE_ON_STOP_RECORDING:
14222
+ this.onStopRecording();
14223
+ break;
14224
+ default:
14225
+ this.onUnHandledEvent(event);
14226
+ break;
14055
14227
  }
14056
14228
  }
14229
+
14230
+ _sendMessage(type , payload = {}) {
14231
+ if (!this.iframe) {
14232
+ console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
14233
+ return;
14234
+ }
14235
+
14236
+ this.iframe.contentWindow.postMessage({ type, ...payload }, '*');
14237
+ }
14057
14238
  }
14058
14239
 
14059
14240
  var Softphone$1 = new Softphone();