@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.
@@ -12842,8 +12842,6 @@ class Checker {
12842
12842
  /* eslint-disable no-unused-vars */
12843
12843
  /* global window, document */
12844
12844
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
12845
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
12846
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
12847
12845
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
12848
12846
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
12849
12847
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -12856,6 +12854,9 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
12856
12854
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
12857
12855
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
12858
12856
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
12857
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
12858
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
12859
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
12859
12860
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
12860
12861
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
12861
12862
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -12869,31 +12870,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
12869
12870
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
12870
12871
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
12871
12872
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
12873
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
12874
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
12875
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
12876
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
12877
+
12878
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
12879
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
12872
12880
 
12873
12881
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
12874
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
12882
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
12875
12883
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
12876
12884
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
12877
12885
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
12878
12886
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
12879
12887
 
12880
12888
  class Softphone {
12881
- url = 'https://softphone.wazo.io';
12882
- width = 500;
12883
- height = 600;
12884
- displayed = false;
12885
- iframe = null;
12889
+
12890
+
12891
+
12892
+
12893
+
12894
+
12895
+
12896
+ // Message waiting for the iframe to be loaded
12897
+
12886
12898
 
12887
12899
  onLinkEnabled(link ) {}
12888
12900
  onIFrameLoaded() {}
12889
12901
 
12890
- onCallMade(call ) {}
12902
+ onCallLocallyAnswered(call ) {}
12903
+ onCallEstablished(call ) {}
12904
+ onOutgoingCallMade(call ) {}
12891
12905
  onCallIncoming(call ) {}
12906
+ onCallRejected(call ) {}
12892
12907
  onCallEnded(call , card , direction , fromExtension ) {}
12908
+
12893
12909
  onCardSaved(card ) {}
12910
+ onCardCanceled() {}
12894
12911
  onAuthenticated(session ) {}
12895
12912
  onLoggedOut() {}
12896
- onSearchOptions(fieldId , query ) {}
12913
+
12914
+ onSearchOptions(fieldId , query ) {
12915
+ this.onOptionsResults(fieldId, []);
12916
+ }
12917
+
12897
12918
  onDisplayLinkedOption(optionId ) {}
12898
12919
  onWazoContactSearch(query ) {}
12899
12920
  onAgentLoggedIn() {}
@@ -12916,18 +12937,26 @@ class Softphone {
12916
12937
  onStopRecording() {}
12917
12938
  onUnHandledEvent(event ) {}
12918
12939
 
12919
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
12920
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
12921
- if (url) {
12922
- this.url = url;
12923
- }
12924
- if (width) {
12925
- this.width = width;
12926
- }
12927
- if (height) {
12928
- this.height = height;
12929
- }
12940
+ init({
12941
+ url,
12942
+ width,
12943
+ height,
12944
+ server,
12945
+ port,
12946
+ language,
12947
+ wrapUpDuration,
12948
+ enableAgent = true,
12949
+ tenantId,
12950
+ debug = false,
12951
+ } = {}) {
12952
+ this.url = url || 'https://softphone.wazo.io';
12953
+ this.width = width || 500;
12954
+ this.height = height || 600;
12955
+ this.displayed = false;
12956
+ this.iframeLoaded = false;
12930
12957
 
12958
+ this.iframeLoaded = false;
12959
+ this._pendingMessages = [];
12931
12960
  window.addEventListener('message', this._onMessage.bind(this), false);
12932
12961
 
12933
12962
  if (!server) {
@@ -12935,25 +12964,33 @@ class Softphone {
12935
12964
  server = 'stack.dev.wazo.io';
12936
12965
  }
12937
12966
 
12938
- this._createIframe(() => {
12939
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
12940
- config: {
12941
- server,
12942
- port,
12943
- language,
12944
- wrapUpDuration,
12945
- shouldDisplayLinkedEntities,
12946
- allowContactCreation,
12947
- },
12948
- });
12967
+ const config = { server };
12968
+ if (language) {
12969
+ config.language = language;
12970
+ }
12971
+ if (port) {
12972
+ config.port = port;
12973
+ }
12974
+ if (tenantId) {
12975
+ config.tenantId = tenantId;
12976
+ }
12977
+ if (wrapUpDuration) {
12978
+ config.wrapUpDuration = wrapUpDuration;
12979
+ }
12949
12980
 
12950
- if (withCard) {
12951
- this._sendMessage(BRIDGE_ENABLE_CARD);
12952
- }
12981
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
12953
12982
 
12954
- if (subscriptionType) {
12955
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
12956
- }
12983
+ if (enableAgent) {
12984
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
12985
+ }
12986
+
12987
+ if (debug) {
12988
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
12989
+ }
12990
+
12991
+ this._createIframe(() => {
12992
+ this.iframeLoaded = true;
12993
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
12957
12994
 
12958
12995
  this.onIFrameLoaded();
12959
12996
  });
@@ -13014,6 +13051,18 @@ class Softphone {
13014
13051
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13015
13052
  }
13016
13053
 
13054
+ setCardValue(field , value ) {
13055
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
13056
+ }
13057
+
13058
+ injectCss(css ) {
13059
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
13060
+ }
13061
+
13062
+ customizeAppearance(themes , translations , assets ) {
13063
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
13064
+ }
13065
+
13017
13066
  _createIframe(cb = () => {}) {
13018
13067
  this.iframe = document.createElement('iframe');
13019
13068
  // $FlowFixMe
@@ -13059,8 +13108,8 @@ class Softphone {
13059
13108
  }
13060
13109
 
13061
13110
  switch (event.data.type) {
13062
- case SDK_ON_CALL_MADE:
13063
- this.onCallMade(event.data.callSession);
13111
+ case SDK_ON_OUTGOING_CALL_MADE:
13112
+ this.onOutgoingCallMade(event.data.callSession);
13064
13113
  break;
13065
13114
  case SDK_CALL_ENDED: {
13066
13115
  const { callSession, content, direction, userExtension } = event.data;
@@ -13148,6 +13197,18 @@ class Softphone {
13148
13197
  case BRIDGE_ON_STOP_RECORDING:
13149
13198
  this.onStopRecording();
13150
13199
  break;
13200
+ case BRIDGE_ON_CARD_CANCELED:
13201
+ this.onCardCanceled();
13202
+ break;
13203
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
13204
+ this.onCallLocallyAnswered(event.data.call);
13205
+ break;
13206
+ case BRIDGE_ON_CALL_REJECTED:
13207
+ this.onCallRejected(event.data.call);
13208
+ break;
13209
+ case BRIDGE_ON_CALL_ESTABLISHED:
13210
+ this.onCallEstablished(event.data.call);
13211
+ break;
13151
13212
  default:
13152
13213
  this.onUnHandledEvent(event);
13153
13214
  break;
@@ -13155,8 +13216,8 @@ class Softphone {
13155
13216
  }
13156
13217
 
13157
13218
  _sendMessage(type , payload = {}) {
13158
- if (!this.iframe) {
13159
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
13219
+ if (!this.iframe || !this.iframeLoaded) {
13220
+ this._pendingMessages.push([type, payload]);
13160
13221
  return;
13161
13222
  }
13162
13223
 
@@ -12847,8 +12847,6 @@ class Checker {
12847
12847
  /* eslint-disable no-unused-vars */
12848
12848
  /* global window, document */
12849
12849
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
12850
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
12851
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
12852
12850
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
12853
12851
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
12854
12852
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -12861,6 +12859,9 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
12861
12859
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
12862
12860
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
12863
12861
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
12862
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
12863
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
12864
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
12864
12865
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
12865
12866
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
12866
12867
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -12874,31 +12875,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
12874
12875
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
12875
12876
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
12876
12877
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
12878
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
12879
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
12880
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
12881
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
12882
+
12883
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
12884
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
12877
12885
 
12878
12886
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
12879
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
12887
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
12880
12888
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
12881
12889
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
12882
12890
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
12883
12891
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
12884
12892
 
12885
12893
  class Softphone {
12886
- url = 'https://softphone.wazo.io';
12887
- width = 500;
12888
- height = 600;
12889
- displayed = false;
12890
- iframe = null;
12894
+
12895
+
12896
+
12897
+
12898
+
12899
+
12900
+
12901
+ // Message waiting for the iframe to be loaded
12902
+
12891
12903
 
12892
12904
  onLinkEnabled(link ) {}
12893
12905
  onIFrameLoaded() {}
12894
12906
 
12895
- onCallMade(call ) {}
12907
+ onCallLocallyAnswered(call ) {}
12908
+ onCallEstablished(call ) {}
12909
+ onOutgoingCallMade(call ) {}
12896
12910
  onCallIncoming(call ) {}
12911
+ onCallRejected(call ) {}
12897
12912
  onCallEnded(call , card , direction , fromExtension ) {}
12913
+
12898
12914
  onCardSaved(card ) {}
12915
+ onCardCanceled() {}
12899
12916
  onAuthenticated(session ) {}
12900
12917
  onLoggedOut() {}
12901
- onSearchOptions(fieldId , query ) {}
12918
+
12919
+ onSearchOptions(fieldId , query ) {
12920
+ this.onOptionsResults(fieldId, []);
12921
+ }
12922
+
12902
12923
  onDisplayLinkedOption(optionId ) {}
12903
12924
  onWazoContactSearch(query ) {}
12904
12925
  onAgentLoggedIn() {}
@@ -12921,18 +12942,26 @@ class Softphone {
12921
12942
  onStopRecording() {}
12922
12943
  onUnHandledEvent(event ) {}
12923
12944
 
12924
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
12925
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
12926
- if (url) {
12927
- this.url = url;
12928
- }
12929
- if (width) {
12930
- this.width = width;
12931
- }
12932
- if (height) {
12933
- this.height = height;
12934
- }
12945
+ init({
12946
+ url,
12947
+ width,
12948
+ height,
12949
+ server,
12950
+ port,
12951
+ language,
12952
+ wrapUpDuration,
12953
+ enableAgent = true,
12954
+ tenantId,
12955
+ debug = false,
12956
+ } = {}) {
12957
+ this.url = url || 'https://softphone.wazo.io';
12958
+ this.width = width || 500;
12959
+ this.height = height || 600;
12960
+ this.displayed = false;
12961
+ this.iframeLoaded = false;
12935
12962
 
12963
+ this.iframeLoaded = false;
12964
+ this._pendingMessages = [];
12936
12965
  window.addEventListener('message', this._onMessage.bind(this), false);
12937
12966
 
12938
12967
  if (!server) {
@@ -12940,25 +12969,33 @@ class Softphone {
12940
12969
  server = 'stack.dev.wazo.io';
12941
12970
  }
12942
12971
 
12943
- this._createIframe(() => {
12944
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
12945
- config: {
12946
- server,
12947
- port,
12948
- language,
12949
- wrapUpDuration,
12950
- shouldDisplayLinkedEntities,
12951
- allowContactCreation,
12952
- },
12953
- });
12972
+ const config = { server };
12973
+ if (language) {
12974
+ config.language = language;
12975
+ }
12976
+ if (port) {
12977
+ config.port = port;
12978
+ }
12979
+ if (tenantId) {
12980
+ config.tenantId = tenantId;
12981
+ }
12982
+ if (wrapUpDuration) {
12983
+ config.wrapUpDuration = wrapUpDuration;
12984
+ }
12954
12985
 
12955
- if (withCard) {
12956
- this._sendMessage(BRIDGE_ENABLE_CARD);
12957
- }
12986
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
12958
12987
 
12959
- if (subscriptionType) {
12960
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
12961
- }
12988
+ if (enableAgent) {
12989
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
12990
+ }
12991
+
12992
+ if (debug) {
12993
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
12994
+ }
12995
+
12996
+ this._createIframe(() => {
12997
+ this.iframeLoaded = true;
12998
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
12962
12999
 
12963
13000
  this.onIFrameLoaded();
12964
13001
  });
@@ -13019,6 +13056,18 @@ class Softphone {
13019
13056
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13020
13057
  }
13021
13058
 
13059
+ setCardValue(field , value ) {
13060
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
13061
+ }
13062
+
13063
+ injectCss(css ) {
13064
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
13065
+ }
13066
+
13067
+ customizeAppearance(themes , translations , assets ) {
13068
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
13069
+ }
13070
+
13022
13071
  _createIframe(cb = () => {}) {
13023
13072
  this.iframe = document.createElement('iframe');
13024
13073
  // $FlowFixMe
@@ -13064,8 +13113,8 @@ class Softphone {
13064
13113
  }
13065
13114
 
13066
13115
  switch (event.data.type) {
13067
- case SDK_ON_CALL_MADE:
13068
- this.onCallMade(event.data.callSession);
13116
+ case SDK_ON_OUTGOING_CALL_MADE:
13117
+ this.onOutgoingCallMade(event.data.callSession);
13069
13118
  break;
13070
13119
  case SDK_CALL_ENDED: {
13071
13120
  const { callSession, content, direction, userExtension } = event.data;
@@ -13153,6 +13202,18 @@ class Softphone {
13153
13202
  case BRIDGE_ON_STOP_RECORDING:
13154
13203
  this.onStopRecording();
13155
13204
  break;
13205
+ case BRIDGE_ON_CARD_CANCELED:
13206
+ this.onCardCanceled();
13207
+ break;
13208
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
13209
+ this.onCallLocallyAnswered(event.data.call);
13210
+ break;
13211
+ case BRIDGE_ON_CALL_REJECTED:
13212
+ this.onCallRejected(event.data.call);
13213
+ break;
13214
+ case BRIDGE_ON_CALL_ESTABLISHED:
13215
+ this.onCallEstablished(event.data.call);
13216
+ break;
13156
13217
  default:
13157
13218
  this.onUnHandledEvent(event);
13158
13219
  break;
@@ -13160,8 +13221,8 @@ class Softphone {
13160
13221
  }
13161
13222
 
13162
13223
  _sendMessage(type , payload = {}) {
13163
- if (!this.iframe) {
13164
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
13224
+ if (!this.iframe || !this.iframeLoaded) {
13225
+ this._pendingMessages.push([type, payload]);
13165
13226
  return;
13166
13227
  }
13167
13228
 
@@ -13126,8 +13126,6 @@ class Checker {
13126
13126
  /* eslint-disable no-unused-vars */
13127
13127
  /* global window, document */
13128
13128
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13129
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13130
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13131
13129
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13132
13130
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13133
13131
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -13140,6 +13138,9 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13140
13138
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13141
13139
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13142
13140
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13141
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
13142
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
13143
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
13143
13144
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13144
13145
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13145
13146
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -13153,31 +13154,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
13153
13154
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13154
13155
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13155
13156
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13157
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
13158
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
13159
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
13160
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
13161
+
13162
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
13163
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
13156
13164
 
13157
13165
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13158
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13166
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
13159
13167
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13160
13168
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13161
13169
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13162
13170
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13163
13171
 
13164
13172
  class Softphone {
13165
- url = 'https://softphone.wazo.io';
13166
- width = 500;
13167
- height = 600;
13168
- displayed = false;
13169
- iframe = null;
13173
+
13174
+
13175
+
13176
+
13177
+
13178
+
13179
+
13180
+ // Message waiting for the iframe to be loaded
13181
+
13170
13182
 
13171
13183
  onLinkEnabled(link ) {}
13172
13184
  onIFrameLoaded() {}
13173
13185
 
13174
- onCallMade(call ) {}
13186
+ onCallLocallyAnswered(call ) {}
13187
+ onCallEstablished(call ) {}
13188
+ onOutgoingCallMade(call ) {}
13175
13189
  onCallIncoming(call ) {}
13190
+ onCallRejected(call ) {}
13176
13191
  onCallEnded(call , card , direction , fromExtension ) {}
13192
+
13177
13193
  onCardSaved(card ) {}
13194
+ onCardCanceled() {}
13178
13195
  onAuthenticated(session ) {}
13179
13196
  onLoggedOut() {}
13180
- onSearchOptions(fieldId , query ) {}
13197
+
13198
+ onSearchOptions(fieldId , query ) {
13199
+ this.onOptionsResults(fieldId, []);
13200
+ }
13201
+
13181
13202
  onDisplayLinkedOption(optionId ) {}
13182
13203
  onWazoContactSearch(query ) {}
13183
13204
  onAgentLoggedIn() {}
@@ -13200,18 +13221,26 @@ class Softphone {
13200
13221
  onStopRecording() {}
13201
13222
  onUnHandledEvent(event ) {}
13202
13223
 
13203
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
13204
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13205
- if (url) {
13206
- this.url = url;
13207
- }
13208
- if (width) {
13209
- this.width = width;
13210
- }
13211
- if (height) {
13212
- this.height = height;
13213
- }
13224
+ init({
13225
+ url,
13226
+ width,
13227
+ height,
13228
+ server,
13229
+ port,
13230
+ language,
13231
+ wrapUpDuration,
13232
+ enableAgent = true,
13233
+ tenantId,
13234
+ debug = false,
13235
+ } = {}) {
13236
+ this.url = url || 'https://softphone.wazo.io';
13237
+ this.width = width || 500;
13238
+ this.height = height || 600;
13239
+ this.displayed = false;
13240
+ this.iframeLoaded = false;
13214
13241
 
13242
+ this.iframeLoaded = false;
13243
+ this._pendingMessages = [];
13215
13244
  window.addEventListener('message', this._onMessage.bind(this), false);
13216
13245
 
13217
13246
  if (!server) {
@@ -13219,25 +13248,33 @@ class Softphone {
13219
13248
  server = 'stack.dev.wazo.io';
13220
13249
  }
13221
13250
 
13222
- this._createIframe(() => {
13223
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
13224
- config: {
13225
- server,
13226
- port,
13227
- language,
13228
- wrapUpDuration,
13229
- shouldDisplayLinkedEntities,
13230
- allowContactCreation,
13231
- },
13232
- });
13251
+ const config = { server };
13252
+ if (language) {
13253
+ config.language = language;
13254
+ }
13255
+ if (port) {
13256
+ config.port = port;
13257
+ }
13258
+ if (tenantId) {
13259
+ config.tenantId = tenantId;
13260
+ }
13261
+ if (wrapUpDuration) {
13262
+ config.wrapUpDuration = wrapUpDuration;
13263
+ }
13233
13264
 
13234
- if (withCard) {
13235
- this._sendMessage(BRIDGE_ENABLE_CARD);
13236
- }
13265
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
13237
13266
 
13238
- if (subscriptionType) {
13239
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
13240
- }
13267
+ if (enableAgent) {
13268
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
13269
+ }
13270
+
13271
+ if (debug) {
13272
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
13273
+ }
13274
+
13275
+ this._createIframe(() => {
13276
+ this.iframeLoaded = true;
13277
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
13241
13278
 
13242
13279
  this.onIFrameLoaded();
13243
13280
  });
@@ -13298,6 +13335,18 @@ class Softphone {
13298
13335
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13299
13336
  }
13300
13337
 
13338
+ setCardValue(field , value ) {
13339
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
13340
+ }
13341
+
13342
+ injectCss(css ) {
13343
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
13344
+ }
13345
+
13346
+ customizeAppearance(themes , translations , assets ) {
13347
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
13348
+ }
13349
+
13301
13350
  _createIframe(cb = () => {}) {
13302
13351
  this.iframe = document.createElement('iframe');
13303
13352
  // $FlowFixMe
@@ -13343,8 +13392,8 @@ class Softphone {
13343
13392
  }
13344
13393
 
13345
13394
  switch (event.data.type) {
13346
- case SDK_ON_CALL_MADE:
13347
- this.onCallMade(event.data.callSession);
13395
+ case SDK_ON_OUTGOING_CALL_MADE:
13396
+ this.onOutgoingCallMade(event.data.callSession);
13348
13397
  break;
13349
13398
  case SDK_CALL_ENDED: {
13350
13399
  const { callSession, content, direction, userExtension } = event.data;
@@ -13432,6 +13481,18 @@ class Softphone {
13432
13481
  case BRIDGE_ON_STOP_RECORDING:
13433
13482
  this.onStopRecording();
13434
13483
  break;
13484
+ case BRIDGE_ON_CARD_CANCELED:
13485
+ this.onCardCanceled();
13486
+ break;
13487
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
13488
+ this.onCallLocallyAnswered(event.data.call);
13489
+ break;
13490
+ case BRIDGE_ON_CALL_REJECTED:
13491
+ this.onCallRejected(event.data.call);
13492
+ break;
13493
+ case BRIDGE_ON_CALL_ESTABLISHED:
13494
+ this.onCallEstablished(event.data.call);
13495
+ break;
13435
13496
  default:
13436
13497
  this.onUnHandledEvent(event);
13437
13498
  break;
@@ -13439,8 +13500,8 @@ class Softphone {
13439
13500
  }
13440
13501
 
13441
13502
  _sendMessage(type , payload = {}) {
13442
- if (!this.iframe) {
13443
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
13503
+ if (!this.iframe || !this.iframeLoaded) {
13504
+ this._pendingMessages.push([type, payload]);
13444
13505
  return;
13445
13506
  }
13446
13507