@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.
package/esm/index.js CHANGED
@@ -14111,8 +14111,6 @@ const createLocalAudioStream = async (options ) => createLocalStream('aud
14111
14111
  /* eslint-disable no-unused-vars */
14112
14112
  /* global window, document */
14113
14113
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
14114
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
14115
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
14116
14114
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
14117
14115
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
14118
14116
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -14125,6 +14123,9 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
14125
14123
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
14126
14124
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
14127
14125
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
14126
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
14127
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
14128
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
14128
14129
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
14129
14130
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
14130
14131
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -14138,31 +14139,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
14138
14139
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
14139
14140
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
14140
14141
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
14142
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
14143
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
14144
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
14145
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
14146
+
14147
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
14148
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
14141
14149
 
14142
14150
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
14143
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
14151
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
14144
14152
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
14145
14153
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
14146
14154
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14147
14155
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
14148
14156
 
14149
14157
  class Softphone {
14150
- url = 'https://softphone.wazo.io';
14151
- width = 500;
14152
- height = 600;
14153
- displayed = false;
14154
- iframe = null;
14158
+
14159
+
14160
+
14161
+
14162
+
14163
+
14164
+
14165
+ // Message waiting for the iframe to be loaded
14166
+
14155
14167
 
14156
14168
  onLinkEnabled(link ) {}
14157
14169
  onIFrameLoaded() {}
14158
14170
 
14159
- onCallMade(call ) {}
14171
+ onCallLocallyAnswered(call ) {}
14172
+ onCallEstablished(call ) {}
14173
+ onOutgoingCallMade(call ) {}
14160
14174
  onCallIncoming(call ) {}
14175
+ onCallRejected(call ) {}
14161
14176
  onCallEnded(call , card , direction , fromExtension ) {}
14177
+
14162
14178
  onCardSaved(card ) {}
14179
+ onCardCanceled() {}
14163
14180
  onAuthenticated(session ) {}
14164
14181
  onLoggedOut() {}
14165
- onSearchOptions(fieldId , query ) {}
14182
+
14183
+ onSearchOptions(fieldId , query ) {
14184
+ this.onOptionsResults(fieldId, []);
14185
+ }
14186
+
14166
14187
  onDisplayLinkedOption(optionId ) {}
14167
14188
  onWazoContactSearch(query ) {}
14168
14189
  onAgentLoggedIn() {}
@@ -14185,18 +14206,26 @@ class Softphone {
14185
14206
  onStopRecording() {}
14186
14207
  onUnHandledEvent(event ) {}
14187
14208
 
14188
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
14189
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
14190
- if (url) {
14191
- this.url = url;
14192
- }
14193
- if (width) {
14194
- this.width = width;
14195
- }
14196
- if (height) {
14197
- this.height = height;
14198
- }
14209
+ init({
14210
+ url,
14211
+ width,
14212
+ height,
14213
+ server,
14214
+ port,
14215
+ language,
14216
+ wrapUpDuration,
14217
+ enableAgent = true,
14218
+ tenantId,
14219
+ debug = false,
14220
+ } = {}) {
14221
+ this.url = url || 'https://softphone.wazo.io';
14222
+ this.width = width || 500;
14223
+ this.height = height || 600;
14224
+ this.displayed = false;
14225
+ this.iframeLoaded = false;
14199
14226
 
14227
+ this.iframeLoaded = false;
14228
+ this._pendingMessages = [];
14200
14229
  window.addEventListener('message', this._onMessage.bind(this), false);
14201
14230
 
14202
14231
  if (!server) {
@@ -14204,25 +14233,33 @@ class Softphone {
14204
14233
  server = 'stack.dev.wazo.io';
14205
14234
  }
14206
14235
 
14207
- this._createIframe(() => {
14208
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
14209
- config: {
14210
- server,
14211
- port,
14212
- language,
14213
- wrapUpDuration,
14214
- shouldDisplayLinkedEntities,
14215
- allowContactCreation,
14216
- },
14217
- });
14236
+ const config = { server };
14237
+ if (language) {
14238
+ config.language = language;
14239
+ }
14240
+ if (port) {
14241
+ config.port = port;
14242
+ }
14243
+ if (tenantId) {
14244
+ config.tenantId = tenantId;
14245
+ }
14246
+ if (wrapUpDuration) {
14247
+ config.wrapUpDuration = wrapUpDuration;
14248
+ }
14218
14249
 
14219
- if (withCard) {
14220
- this._sendMessage(BRIDGE_ENABLE_CARD);
14221
- }
14250
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
14222
14251
 
14223
- if (subscriptionType) {
14224
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
14225
- }
14252
+ if (enableAgent) {
14253
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
14254
+ }
14255
+
14256
+ if (debug) {
14257
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
14258
+ }
14259
+
14260
+ this._createIframe(() => {
14261
+ this.iframeLoaded = true;
14262
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
14226
14263
 
14227
14264
  this.onIFrameLoaded();
14228
14265
  });
@@ -14283,6 +14320,18 @@ class Softphone {
14283
14320
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14284
14321
  }
14285
14322
 
14323
+ setCardValue(field , value ) {
14324
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
14325
+ }
14326
+
14327
+ injectCss(css ) {
14328
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
14329
+ }
14330
+
14331
+ customizeAppearance(themes , translations , assets ) {
14332
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
14333
+ }
14334
+
14286
14335
  _createIframe(cb = () => {}) {
14287
14336
  this.iframe = document.createElement('iframe');
14288
14337
  // $FlowFixMe
@@ -14328,8 +14377,8 @@ class Softphone {
14328
14377
  }
14329
14378
 
14330
14379
  switch (event.data.type) {
14331
- case SDK_ON_CALL_MADE:
14332
- this.onCallMade(event.data.callSession);
14380
+ case SDK_ON_OUTGOING_CALL_MADE:
14381
+ this.onOutgoingCallMade(event.data.callSession);
14333
14382
  break;
14334
14383
  case SDK_CALL_ENDED: {
14335
14384
  const { callSession, content, direction, userExtension } = event.data;
@@ -14417,6 +14466,18 @@ class Softphone {
14417
14466
  case BRIDGE_ON_STOP_RECORDING:
14418
14467
  this.onStopRecording();
14419
14468
  break;
14469
+ case BRIDGE_ON_CARD_CANCELED:
14470
+ this.onCardCanceled();
14471
+ break;
14472
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
14473
+ this.onCallLocallyAnswered(event.data.call);
14474
+ break;
14475
+ case BRIDGE_ON_CALL_REJECTED:
14476
+ this.onCallRejected(event.data.call);
14477
+ break;
14478
+ case BRIDGE_ON_CALL_ESTABLISHED:
14479
+ this.onCallEstablished(event.data.call);
14480
+ break;
14420
14481
  default:
14421
14482
  this.onUnHandledEvent(event);
14422
14483
  break;
@@ -14424,8 +14485,8 @@ class Softphone {
14424
14485
  }
14425
14486
 
14426
14487
  _sendMessage(type , payload = {}) {
14427
- if (!this.iframe) {
14428
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
14488
+ if (!this.iframe || !this.iframeLoaded) {
14489
+ this._pendingMessages.push([type, payload]);
14429
14490
  return;
14430
14491
  }
14431
14492
 
@@ -13672,8 +13672,6 @@ class Checker {
13672
13672
  /* eslint-disable no-unused-vars */
13673
13673
  /* global window, document */
13674
13674
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13675
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13676
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13677
13675
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13678
13676
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13679
13677
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -13686,6 +13684,9 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13686
13684
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13687
13685
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13688
13686
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13687
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
13688
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
13689
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
13689
13690
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13690
13691
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13691
13692
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -13699,31 +13700,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
13699
13700
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13700
13701
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13701
13702
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13703
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
13704
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
13705
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
13706
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
13707
+
13708
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
13709
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
13702
13710
 
13703
13711
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13704
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13712
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
13705
13713
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13706
13714
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13707
13715
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13708
13716
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13709
13717
 
13710
13718
  class Softphone {
13711
- url = 'https://softphone.wazo.io';
13712
- width = 500;
13713
- height = 600;
13714
- displayed = false;
13715
- iframe = null;
13719
+
13720
+
13721
+
13722
+
13723
+
13724
+
13725
+
13726
+ // Message waiting for the iframe to be loaded
13727
+
13716
13728
 
13717
13729
  onLinkEnabled(link ) {}
13718
13730
  onIFrameLoaded() {}
13719
13731
 
13720
- onCallMade(call ) {}
13732
+ onCallLocallyAnswered(call ) {}
13733
+ onCallEstablished(call ) {}
13734
+ onOutgoingCallMade(call ) {}
13721
13735
  onCallIncoming(call ) {}
13736
+ onCallRejected(call ) {}
13722
13737
  onCallEnded(call , card , direction , fromExtension ) {}
13738
+
13723
13739
  onCardSaved(card ) {}
13740
+ onCardCanceled() {}
13724
13741
  onAuthenticated(session ) {}
13725
13742
  onLoggedOut() {}
13726
- onSearchOptions(fieldId , query ) {}
13743
+
13744
+ onSearchOptions(fieldId , query ) {
13745
+ this.onOptionsResults(fieldId, []);
13746
+ }
13747
+
13727
13748
  onDisplayLinkedOption(optionId ) {}
13728
13749
  onWazoContactSearch(query ) {}
13729
13750
  onAgentLoggedIn() {}
@@ -13746,18 +13767,26 @@ class Softphone {
13746
13767
  onStopRecording() {}
13747
13768
  onUnHandledEvent(event ) {}
13748
13769
 
13749
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
13750
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13751
- if (url) {
13752
- this.url = url;
13753
- }
13754
- if (width) {
13755
- this.width = width;
13756
- }
13757
- if (height) {
13758
- this.height = height;
13759
- }
13770
+ init({
13771
+ url,
13772
+ width,
13773
+ height,
13774
+ server,
13775
+ port,
13776
+ language,
13777
+ wrapUpDuration,
13778
+ enableAgent = true,
13779
+ tenantId,
13780
+ debug = false,
13781
+ } = {}) {
13782
+ this.url = url || 'https://softphone.wazo.io';
13783
+ this.width = width || 500;
13784
+ this.height = height || 600;
13785
+ this.displayed = false;
13786
+ this.iframeLoaded = false;
13760
13787
 
13788
+ this.iframeLoaded = false;
13789
+ this._pendingMessages = [];
13761
13790
  window.addEventListener('message', this._onMessage.bind(this), false);
13762
13791
 
13763
13792
  if (!server) {
@@ -13765,25 +13794,33 @@ class Softphone {
13765
13794
  server = 'stack.dev.wazo.io';
13766
13795
  }
13767
13796
 
13768
- this._createIframe(() => {
13769
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
13770
- config: {
13771
- server,
13772
- port,
13773
- language,
13774
- wrapUpDuration,
13775
- shouldDisplayLinkedEntities,
13776
- allowContactCreation,
13777
- },
13778
- });
13797
+ const config = { server };
13798
+ if (language) {
13799
+ config.language = language;
13800
+ }
13801
+ if (port) {
13802
+ config.port = port;
13803
+ }
13804
+ if (tenantId) {
13805
+ config.tenantId = tenantId;
13806
+ }
13807
+ if (wrapUpDuration) {
13808
+ config.wrapUpDuration = wrapUpDuration;
13809
+ }
13779
13810
 
13780
- if (withCard) {
13781
- this._sendMessage(BRIDGE_ENABLE_CARD);
13782
- }
13811
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
13783
13812
 
13784
- if (subscriptionType) {
13785
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
13786
- }
13813
+ if (enableAgent) {
13814
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
13815
+ }
13816
+
13817
+ if (debug) {
13818
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
13819
+ }
13820
+
13821
+ this._createIframe(() => {
13822
+ this.iframeLoaded = true;
13823
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
13787
13824
 
13788
13825
  this.onIFrameLoaded();
13789
13826
  });
@@ -13844,6 +13881,18 @@ class Softphone {
13844
13881
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13845
13882
  }
13846
13883
 
13884
+ setCardValue(field , value ) {
13885
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
13886
+ }
13887
+
13888
+ injectCss(css ) {
13889
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
13890
+ }
13891
+
13892
+ customizeAppearance(themes , translations , assets ) {
13893
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
13894
+ }
13895
+
13847
13896
  _createIframe(cb = () => {}) {
13848
13897
  this.iframe = document.createElement('iframe');
13849
13898
  // $FlowFixMe
@@ -13889,8 +13938,8 @@ class Softphone {
13889
13938
  }
13890
13939
 
13891
13940
  switch (event.data.type) {
13892
- case SDK_ON_CALL_MADE:
13893
- this.onCallMade(event.data.callSession);
13941
+ case SDK_ON_OUTGOING_CALL_MADE:
13942
+ this.onOutgoingCallMade(event.data.callSession);
13894
13943
  break;
13895
13944
  case SDK_CALL_ENDED: {
13896
13945
  const { callSession, content, direction, userExtension } = event.data;
@@ -13978,6 +14027,18 @@ class Softphone {
13978
14027
  case BRIDGE_ON_STOP_RECORDING:
13979
14028
  this.onStopRecording();
13980
14029
  break;
14030
+ case BRIDGE_ON_CARD_CANCELED:
14031
+ this.onCardCanceled();
14032
+ break;
14033
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
14034
+ this.onCallLocallyAnswered(event.data.call);
14035
+ break;
14036
+ case BRIDGE_ON_CALL_REJECTED:
14037
+ this.onCallRejected(event.data.call);
14038
+ break;
14039
+ case BRIDGE_ON_CALL_ESTABLISHED:
14040
+ this.onCallEstablished(event.data.call);
14041
+ break;
13981
14042
  default:
13982
14043
  this.onUnHandledEvent(event);
13983
14044
  break;
@@ -13985,8 +14046,8 @@ class Softphone {
13985
14046
  }
13986
14047
 
13987
14048
  _sendMessage(type , payload = {}) {
13988
- if (!this.iframe) {
13989
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
14049
+ if (!this.iframe || !this.iframeLoaded) {
14050
+ this._pendingMessages.push([type, payload]);
13990
14051
  return;
13991
14052
  }
13992
14053
 
@@ -13655,8 +13655,6 @@ class Checker {
13655
13655
  /* eslint-disable no-unused-vars */
13656
13656
  /* global window, document */
13657
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
13658
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13661
13659
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13662
13660
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -13669,6 +13667,9 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13669
13667
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13670
13668
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13671
13669
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13670
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
13671
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
13672
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
13672
13673
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13673
13674
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13674
13675
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -13682,31 +13683,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
13682
13683
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13683
13684
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13684
13685
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13686
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
13687
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
13688
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
13689
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
13690
+
13691
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
13692
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
13685
13693
 
13686
13694
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13687
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13695
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
13688
13696
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13689
13697
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13690
13698
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13691
13699
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13692
13700
 
13693
13701
  class Softphone {
13694
- url = 'https://softphone.wazo.io';
13695
- width = 500;
13696
- height = 600;
13697
- displayed = false;
13698
- iframe = null;
13702
+
13703
+
13704
+
13705
+
13706
+
13707
+
13708
+
13709
+ // Message waiting for the iframe to be loaded
13710
+
13699
13711
 
13700
13712
  onLinkEnabled(link ) {}
13701
13713
  onIFrameLoaded() {}
13702
13714
 
13703
- onCallMade(call ) {}
13715
+ onCallLocallyAnswered(call ) {}
13716
+ onCallEstablished(call ) {}
13717
+ onOutgoingCallMade(call ) {}
13704
13718
  onCallIncoming(call ) {}
13719
+ onCallRejected(call ) {}
13705
13720
  onCallEnded(call , card , direction , fromExtension ) {}
13721
+
13706
13722
  onCardSaved(card ) {}
13723
+ onCardCanceled() {}
13707
13724
  onAuthenticated(session ) {}
13708
13725
  onLoggedOut() {}
13709
- onSearchOptions(fieldId , query ) {}
13726
+
13727
+ onSearchOptions(fieldId , query ) {
13728
+ this.onOptionsResults(fieldId, []);
13729
+ }
13730
+
13710
13731
  onDisplayLinkedOption(optionId ) {}
13711
13732
  onWazoContactSearch(query ) {}
13712
13733
  onAgentLoggedIn() {}
@@ -13729,18 +13750,26 @@ class Softphone {
13729
13750
  onStopRecording() {}
13730
13751
  onUnHandledEvent(event ) {}
13731
13752
 
13732
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
13733
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13734
- if (url) {
13735
- this.url = url;
13736
- }
13737
- if (width) {
13738
- this.width = width;
13739
- }
13740
- if (height) {
13741
- this.height = height;
13742
- }
13753
+ init({
13754
+ url,
13755
+ width,
13756
+ height,
13757
+ server,
13758
+ port,
13759
+ language,
13760
+ wrapUpDuration,
13761
+ enableAgent = true,
13762
+ tenantId,
13763
+ debug = false,
13764
+ } = {}) {
13765
+ this.url = url || 'https://softphone.wazo.io';
13766
+ this.width = width || 500;
13767
+ this.height = height || 600;
13768
+ this.displayed = false;
13769
+ this.iframeLoaded = false;
13743
13770
 
13771
+ this.iframeLoaded = false;
13772
+ this._pendingMessages = [];
13744
13773
  window.addEventListener('message', this._onMessage.bind(this), false);
13745
13774
 
13746
13775
  if (!server) {
@@ -13748,25 +13777,33 @@ class Softphone {
13748
13777
  server = 'stack.dev.wazo.io';
13749
13778
  }
13750
13779
 
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
- });
13780
+ const config = { server };
13781
+ if (language) {
13782
+ config.language = language;
13783
+ }
13784
+ if (port) {
13785
+ config.port = port;
13786
+ }
13787
+ if (tenantId) {
13788
+ config.tenantId = tenantId;
13789
+ }
13790
+ if (wrapUpDuration) {
13791
+ config.wrapUpDuration = wrapUpDuration;
13792
+ }
13762
13793
 
13763
- if (withCard) {
13764
- this._sendMessage(BRIDGE_ENABLE_CARD);
13765
- }
13794
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
13766
13795
 
13767
- if (subscriptionType) {
13768
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
13769
- }
13796
+ if (enableAgent) {
13797
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
13798
+ }
13799
+
13800
+ if (debug) {
13801
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
13802
+ }
13803
+
13804
+ this._createIframe(() => {
13805
+ this.iframeLoaded = true;
13806
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
13770
13807
 
13771
13808
  this.onIFrameLoaded();
13772
13809
  });
@@ -13827,6 +13864,18 @@ class Softphone {
13827
13864
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13828
13865
  }
13829
13866
 
13867
+ setCardValue(field , value ) {
13868
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
13869
+ }
13870
+
13871
+ injectCss(css ) {
13872
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
13873
+ }
13874
+
13875
+ customizeAppearance(themes , translations , assets ) {
13876
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
13877
+ }
13878
+
13830
13879
  _createIframe(cb = () => {}) {
13831
13880
  this.iframe = document.createElement('iframe');
13832
13881
  // $FlowFixMe
@@ -13872,8 +13921,8 @@ class Softphone {
13872
13921
  }
13873
13922
 
13874
13923
  switch (event.data.type) {
13875
- case SDK_ON_CALL_MADE:
13876
- this.onCallMade(event.data.callSession);
13924
+ case SDK_ON_OUTGOING_CALL_MADE:
13925
+ this.onOutgoingCallMade(event.data.callSession);
13877
13926
  break;
13878
13927
  case SDK_CALL_ENDED: {
13879
13928
  const { callSession, content, direction, userExtension } = event.data;
@@ -13961,6 +14010,18 @@ class Softphone {
13961
14010
  case BRIDGE_ON_STOP_RECORDING:
13962
14011
  this.onStopRecording();
13963
14012
  break;
14013
+ case BRIDGE_ON_CARD_CANCELED:
14014
+ this.onCardCanceled();
14015
+ break;
14016
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
14017
+ this.onCallLocallyAnswered(event.data.call);
14018
+ break;
14019
+ case BRIDGE_ON_CALL_REJECTED:
14020
+ this.onCallRejected(event.data.call);
14021
+ break;
14022
+ case BRIDGE_ON_CALL_ESTABLISHED:
14023
+ this.onCallEstablished(event.data.call);
14024
+ break;
13964
14025
  default:
13965
14026
  this.onUnHandledEvent(event);
13966
14027
  break;
@@ -13968,8 +14029,8 @@ class Softphone {
13968
14029
  }
13969
14030
 
13970
14031
  _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`);
14032
+ if (!this.iframe || !this.iframeLoaded) {
14033
+ this._pendingMessages.push([type, payload]);
13973
14034
  return;
13974
14035
  }
13975
14036