@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.
@@ -12857,8 +12857,6 @@ class Checker {
12857
12857
  /* eslint-disable no-unused-vars */
12858
12858
  /* global window, document */
12859
12859
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
12860
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
12861
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
12862
12860
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
12863
12861
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
12864
12862
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -12871,6 +12869,9 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
12871
12869
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
12872
12870
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
12873
12871
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
12872
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
12873
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
12874
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
12874
12875
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
12875
12876
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
12876
12877
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -12884,31 +12885,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
12884
12885
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
12885
12886
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
12886
12887
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
12888
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
12889
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
12890
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
12891
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
12892
+
12893
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
12894
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
12887
12895
 
12888
12896
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
12889
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
12897
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
12890
12898
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
12891
12899
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
12892
12900
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
12893
12901
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
12894
12902
 
12895
12903
  class Softphone {
12896
- url = 'https://softphone.wazo.io';
12897
- width = 500;
12898
- height = 600;
12899
- displayed = false;
12900
- iframe = null;
12904
+
12905
+
12906
+
12907
+
12908
+
12909
+
12910
+
12911
+ // Message waiting for the iframe to be loaded
12912
+
12901
12913
 
12902
12914
  onLinkEnabled(link ) {}
12903
12915
  onIFrameLoaded() {}
12904
12916
 
12905
- onCallMade(call ) {}
12917
+ onCallLocallyAnswered(call ) {}
12918
+ onCallEstablished(call ) {}
12919
+ onOutgoingCallMade(call ) {}
12906
12920
  onCallIncoming(call ) {}
12921
+ onCallRejected(call ) {}
12907
12922
  onCallEnded(call , card , direction , fromExtension ) {}
12923
+
12908
12924
  onCardSaved(card ) {}
12925
+ onCardCanceled() {}
12909
12926
  onAuthenticated(session ) {}
12910
12927
  onLoggedOut() {}
12911
- onSearchOptions(fieldId , query ) {}
12928
+
12929
+ onSearchOptions(fieldId , query ) {
12930
+ this.onOptionsResults(fieldId, []);
12931
+ }
12932
+
12912
12933
  onDisplayLinkedOption(optionId ) {}
12913
12934
  onWazoContactSearch(query ) {}
12914
12935
  onAgentLoggedIn() {}
@@ -12931,18 +12952,26 @@ class Softphone {
12931
12952
  onStopRecording() {}
12932
12953
  onUnHandledEvent(event ) {}
12933
12954
 
12934
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
12935
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
12936
- if (url) {
12937
- this.url = url;
12938
- }
12939
- if (width) {
12940
- this.width = width;
12941
- }
12942
- if (height) {
12943
- this.height = height;
12944
- }
12955
+ init({
12956
+ url,
12957
+ width,
12958
+ height,
12959
+ server,
12960
+ port,
12961
+ language,
12962
+ wrapUpDuration,
12963
+ enableAgent = true,
12964
+ tenantId,
12965
+ debug = false,
12966
+ } = {}) {
12967
+ this.url = url || 'https://softphone.wazo.io';
12968
+ this.width = width || 500;
12969
+ this.height = height || 600;
12970
+ this.displayed = false;
12971
+ this.iframeLoaded = false;
12945
12972
 
12973
+ this.iframeLoaded = false;
12974
+ this._pendingMessages = [];
12946
12975
  window.addEventListener('message', this._onMessage.bind(this), false);
12947
12976
 
12948
12977
  if (!server) {
@@ -12950,25 +12979,33 @@ class Softphone {
12950
12979
  server = 'stack.dev.wazo.io';
12951
12980
  }
12952
12981
 
12953
- this._createIframe(() => {
12954
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
12955
- config: {
12956
- server,
12957
- port,
12958
- language,
12959
- wrapUpDuration,
12960
- shouldDisplayLinkedEntities,
12961
- allowContactCreation,
12962
- },
12963
- });
12982
+ const config = { server };
12983
+ if (language) {
12984
+ config.language = language;
12985
+ }
12986
+ if (port) {
12987
+ config.port = port;
12988
+ }
12989
+ if (tenantId) {
12990
+ config.tenantId = tenantId;
12991
+ }
12992
+ if (wrapUpDuration) {
12993
+ config.wrapUpDuration = wrapUpDuration;
12994
+ }
12964
12995
 
12965
- if (withCard) {
12966
- this._sendMessage(BRIDGE_ENABLE_CARD);
12967
- }
12996
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
12968
12997
 
12969
- if (subscriptionType) {
12970
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
12971
- }
12998
+ if (enableAgent) {
12999
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
13000
+ }
13001
+
13002
+ if (debug) {
13003
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
13004
+ }
13005
+
13006
+ this._createIframe(() => {
13007
+ this.iframeLoaded = true;
13008
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
12972
13009
 
12973
13010
  this.onIFrameLoaded();
12974
13011
  });
@@ -13029,6 +13066,18 @@ class Softphone {
13029
13066
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13030
13067
  }
13031
13068
 
13069
+ setCardValue(field , value ) {
13070
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
13071
+ }
13072
+
13073
+ injectCss(css ) {
13074
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
13075
+ }
13076
+
13077
+ customizeAppearance(themes , translations , assets ) {
13078
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
13079
+ }
13080
+
13032
13081
  _createIframe(cb = () => {}) {
13033
13082
  this.iframe = document.createElement('iframe');
13034
13083
  // $FlowFixMe
@@ -13074,8 +13123,8 @@ class Softphone {
13074
13123
  }
13075
13124
 
13076
13125
  switch (event.data.type) {
13077
- case SDK_ON_CALL_MADE:
13078
- this.onCallMade(event.data.callSession);
13126
+ case SDK_ON_OUTGOING_CALL_MADE:
13127
+ this.onOutgoingCallMade(event.data.callSession);
13079
13128
  break;
13080
13129
  case SDK_CALL_ENDED: {
13081
13130
  const { callSession, content, direction, userExtension } = event.data;
@@ -13163,6 +13212,18 @@ class Softphone {
13163
13212
  case BRIDGE_ON_STOP_RECORDING:
13164
13213
  this.onStopRecording();
13165
13214
  break;
13215
+ case BRIDGE_ON_CARD_CANCELED:
13216
+ this.onCardCanceled();
13217
+ break;
13218
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
13219
+ this.onCallLocallyAnswered(event.data.call);
13220
+ break;
13221
+ case BRIDGE_ON_CALL_REJECTED:
13222
+ this.onCallRejected(event.data.call);
13223
+ break;
13224
+ case BRIDGE_ON_CALL_ESTABLISHED:
13225
+ this.onCallEstablished(event.data.call);
13226
+ break;
13166
13227
  default:
13167
13228
  this.onUnHandledEvent(event);
13168
13229
  break;
@@ -13170,8 +13231,8 @@ class Softphone {
13170
13231
  }
13171
13232
 
13172
13233
  _sendMessage(type , payload = {}) {
13173
- if (!this.iframe) {
13174
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
13234
+ if (!this.iframe || !this.iframeLoaded) {
13235
+ this._pendingMessages.push([type, payload]);
13175
13236
  return;
13176
13237
  }
13177
13238
 
@@ -13136,8 +13136,6 @@ class Checker {
13136
13136
  /* eslint-disable no-unused-vars */
13137
13137
  /* global window, document */
13138
13138
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13139
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13140
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13141
13139
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13142
13140
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13143
13141
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -13150,6 +13148,9 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13150
13148
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13151
13149
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13152
13150
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13151
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
13152
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
13153
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
13153
13154
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13154
13155
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13155
13156
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -13163,31 +13164,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
13163
13164
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13164
13165
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13165
13166
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13167
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
13168
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
13169
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
13170
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
13171
+
13172
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
13173
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
13166
13174
 
13167
13175
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13168
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13176
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
13169
13177
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13170
13178
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13171
13179
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13172
13180
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13173
13181
 
13174
13182
  class Softphone {
13175
- url = 'https://softphone.wazo.io';
13176
- width = 500;
13177
- height = 600;
13178
- displayed = false;
13179
- iframe = null;
13183
+
13184
+
13185
+
13186
+
13187
+
13188
+
13189
+
13190
+ // Message waiting for the iframe to be loaded
13191
+
13180
13192
 
13181
13193
  onLinkEnabled(link ) {}
13182
13194
  onIFrameLoaded() {}
13183
13195
 
13184
- onCallMade(call ) {}
13196
+ onCallLocallyAnswered(call ) {}
13197
+ onCallEstablished(call ) {}
13198
+ onOutgoingCallMade(call ) {}
13185
13199
  onCallIncoming(call ) {}
13200
+ onCallRejected(call ) {}
13186
13201
  onCallEnded(call , card , direction , fromExtension ) {}
13202
+
13187
13203
  onCardSaved(card ) {}
13204
+ onCardCanceled() {}
13188
13205
  onAuthenticated(session ) {}
13189
13206
  onLoggedOut() {}
13190
- onSearchOptions(fieldId , query ) {}
13207
+
13208
+ onSearchOptions(fieldId , query ) {
13209
+ this.onOptionsResults(fieldId, []);
13210
+ }
13211
+
13191
13212
  onDisplayLinkedOption(optionId ) {}
13192
13213
  onWazoContactSearch(query ) {}
13193
13214
  onAgentLoggedIn() {}
@@ -13210,18 +13231,26 @@ class Softphone {
13210
13231
  onStopRecording() {}
13211
13232
  onUnHandledEvent(event ) {}
13212
13233
 
13213
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
13214
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13215
- if (url) {
13216
- this.url = url;
13217
- }
13218
- if (width) {
13219
- this.width = width;
13220
- }
13221
- if (height) {
13222
- this.height = height;
13223
- }
13234
+ init({
13235
+ url,
13236
+ width,
13237
+ height,
13238
+ server,
13239
+ port,
13240
+ language,
13241
+ wrapUpDuration,
13242
+ enableAgent = true,
13243
+ tenantId,
13244
+ debug = false,
13245
+ } = {}) {
13246
+ this.url = url || 'https://softphone.wazo.io';
13247
+ this.width = width || 500;
13248
+ this.height = height || 600;
13249
+ this.displayed = false;
13250
+ this.iframeLoaded = false;
13224
13251
 
13252
+ this.iframeLoaded = false;
13253
+ this._pendingMessages = [];
13225
13254
  window.addEventListener('message', this._onMessage.bind(this), false);
13226
13255
 
13227
13256
  if (!server) {
@@ -13229,25 +13258,33 @@ class Softphone {
13229
13258
  server = 'stack.dev.wazo.io';
13230
13259
  }
13231
13260
 
13232
- this._createIframe(() => {
13233
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
13234
- config: {
13235
- server,
13236
- port,
13237
- language,
13238
- wrapUpDuration,
13239
- shouldDisplayLinkedEntities,
13240
- allowContactCreation,
13241
- },
13242
- });
13261
+ const config = { server };
13262
+ if (language) {
13263
+ config.language = language;
13264
+ }
13265
+ if (port) {
13266
+ config.port = port;
13267
+ }
13268
+ if (tenantId) {
13269
+ config.tenantId = tenantId;
13270
+ }
13271
+ if (wrapUpDuration) {
13272
+ config.wrapUpDuration = wrapUpDuration;
13273
+ }
13243
13274
 
13244
- if (withCard) {
13245
- this._sendMessage(BRIDGE_ENABLE_CARD);
13246
- }
13275
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
13247
13276
 
13248
- if (subscriptionType) {
13249
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
13250
- }
13277
+ if (enableAgent) {
13278
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
13279
+ }
13280
+
13281
+ if (debug) {
13282
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
13283
+ }
13284
+
13285
+ this._createIframe(() => {
13286
+ this.iframeLoaded = true;
13287
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
13251
13288
 
13252
13289
  this.onIFrameLoaded();
13253
13290
  });
@@ -13308,6 +13345,18 @@ class Softphone {
13308
13345
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13309
13346
  }
13310
13347
 
13348
+ setCardValue(field , value ) {
13349
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
13350
+ }
13351
+
13352
+ injectCss(css ) {
13353
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
13354
+ }
13355
+
13356
+ customizeAppearance(themes , translations , assets ) {
13357
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
13358
+ }
13359
+
13311
13360
  _createIframe(cb = () => {}) {
13312
13361
  this.iframe = document.createElement('iframe');
13313
13362
  // $FlowFixMe
@@ -13353,8 +13402,8 @@ class Softphone {
13353
13402
  }
13354
13403
 
13355
13404
  switch (event.data.type) {
13356
- case SDK_ON_CALL_MADE:
13357
- this.onCallMade(event.data.callSession);
13405
+ case SDK_ON_OUTGOING_CALL_MADE:
13406
+ this.onOutgoingCallMade(event.data.callSession);
13358
13407
  break;
13359
13408
  case SDK_CALL_ENDED: {
13360
13409
  const { callSession, content, direction, userExtension } = event.data;
@@ -13442,6 +13491,18 @@ class Softphone {
13442
13491
  case BRIDGE_ON_STOP_RECORDING:
13443
13492
  this.onStopRecording();
13444
13493
  break;
13494
+ case BRIDGE_ON_CARD_CANCELED:
13495
+ this.onCardCanceled();
13496
+ break;
13497
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
13498
+ this.onCallLocallyAnswered(event.data.call);
13499
+ break;
13500
+ case BRIDGE_ON_CALL_REJECTED:
13501
+ this.onCallRejected(event.data.call);
13502
+ break;
13503
+ case BRIDGE_ON_CALL_ESTABLISHED:
13504
+ this.onCallEstablished(event.data.call);
13505
+ break;
13445
13506
  default:
13446
13507
  this.onUnHandledEvent(event);
13447
13508
  break;
@@ -13449,8 +13510,8 @@ class Softphone {
13449
13510
  }
13450
13511
 
13451
13512
  _sendMessage(type , payload = {}) {
13452
- if (!this.iframe) {
13453
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
13513
+ if (!this.iframe || !this.iframeLoaded) {
13514
+ this._pendingMessages.push([type, payload]);
13454
13515
  return;
13455
13516
  }
13456
13517
 
@@ -13149,8 +13149,6 @@ class Checker {
13149
13149
  /* eslint-disable no-unused-vars */
13150
13150
  /* global window, document */
13151
13151
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13152
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13153
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13154
13152
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13155
13153
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13156
13154
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -13163,6 +13161,9 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13163
13161
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13164
13162
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13165
13163
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13164
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
13165
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
13166
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
13166
13167
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13167
13168
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13168
13169
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -13176,31 +13177,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
13176
13177
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13177
13178
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13178
13179
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13180
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
13181
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
13182
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
13183
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
13184
+
13185
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
13186
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
13179
13187
 
13180
13188
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13181
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13189
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
13182
13190
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13183
13191
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13184
13192
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13185
13193
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13186
13194
 
13187
13195
  class Softphone {
13188
- url = 'https://softphone.wazo.io';
13189
- width = 500;
13190
- height = 600;
13191
- displayed = false;
13192
- iframe = null;
13196
+
13197
+
13198
+
13199
+
13200
+
13201
+
13202
+
13203
+ // Message waiting for the iframe to be loaded
13204
+
13193
13205
 
13194
13206
  onLinkEnabled(link ) {}
13195
13207
  onIFrameLoaded() {}
13196
13208
 
13197
- onCallMade(call ) {}
13209
+ onCallLocallyAnswered(call ) {}
13210
+ onCallEstablished(call ) {}
13211
+ onOutgoingCallMade(call ) {}
13198
13212
  onCallIncoming(call ) {}
13213
+ onCallRejected(call ) {}
13199
13214
  onCallEnded(call , card , direction , fromExtension ) {}
13215
+
13200
13216
  onCardSaved(card ) {}
13217
+ onCardCanceled() {}
13201
13218
  onAuthenticated(session ) {}
13202
13219
  onLoggedOut() {}
13203
- onSearchOptions(fieldId , query ) {}
13220
+
13221
+ onSearchOptions(fieldId , query ) {
13222
+ this.onOptionsResults(fieldId, []);
13223
+ }
13224
+
13204
13225
  onDisplayLinkedOption(optionId ) {}
13205
13226
  onWazoContactSearch(query ) {}
13206
13227
  onAgentLoggedIn() {}
@@ -13223,18 +13244,26 @@ class Softphone {
13223
13244
  onStopRecording() {}
13224
13245
  onUnHandledEvent(event ) {}
13225
13246
 
13226
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
13227
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13228
- if (url) {
13229
- this.url = url;
13230
- }
13231
- if (width) {
13232
- this.width = width;
13233
- }
13234
- if (height) {
13235
- this.height = height;
13236
- }
13247
+ init({
13248
+ url,
13249
+ width,
13250
+ height,
13251
+ server,
13252
+ port,
13253
+ language,
13254
+ wrapUpDuration,
13255
+ enableAgent = true,
13256
+ tenantId,
13257
+ debug = false,
13258
+ } = {}) {
13259
+ this.url = url || 'https://softphone.wazo.io';
13260
+ this.width = width || 500;
13261
+ this.height = height || 600;
13262
+ this.displayed = false;
13263
+ this.iframeLoaded = false;
13237
13264
 
13265
+ this.iframeLoaded = false;
13266
+ this._pendingMessages = [];
13238
13267
  window.addEventListener('message', this._onMessage.bind(this), false);
13239
13268
 
13240
13269
  if (!server) {
@@ -13242,25 +13271,33 @@ class Softphone {
13242
13271
  server = 'stack.dev.wazo.io';
13243
13272
  }
13244
13273
 
13245
- this._createIframe(() => {
13246
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
13247
- config: {
13248
- server,
13249
- port,
13250
- language,
13251
- wrapUpDuration,
13252
- shouldDisplayLinkedEntities,
13253
- allowContactCreation,
13254
- },
13255
- });
13274
+ const config = { server };
13275
+ if (language) {
13276
+ config.language = language;
13277
+ }
13278
+ if (port) {
13279
+ config.port = port;
13280
+ }
13281
+ if (tenantId) {
13282
+ config.tenantId = tenantId;
13283
+ }
13284
+ if (wrapUpDuration) {
13285
+ config.wrapUpDuration = wrapUpDuration;
13286
+ }
13256
13287
 
13257
- if (withCard) {
13258
- this._sendMessage(BRIDGE_ENABLE_CARD);
13259
- }
13288
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
13260
13289
 
13261
- if (subscriptionType) {
13262
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
13263
- }
13290
+ if (enableAgent) {
13291
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
13292
+ }
13293
+
13294
+ if (debug) {
13295
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
13296
+ }
13297
+
13298
+ this._createIframe(() => {
13299
+ this.iframeLoaded = true;
13300
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
13264
13301
 
13265
13302
  this.onIFrameLoaded();
13266
13303
  });
@@ -13321,6 +13358,18 @@ class Softphone {
13321
13358
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13322
13359
  }
13323
13360
 
13361
+ setCardValue(field , value ) {
13362
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
13363
+ }
13364
+
13365
+ injectCss(css ) {
13366
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
13367
+ }
13368
+
13369
+ customizeAppearance(themes , translations , assets ) {
13370
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
13371
+ }
13372
+
13324
13373
  _createIframe(cb = () => {}) {
13325
13374
  this.iframe = document.createElement('iframe');
13326
13375
  // $FlowFixMe
@@ -13366,8 +13415,8 @@ class Softphone {
13366
13415
  }
13367
13416
 
13368
13417
  switch (event.data.type) {
13369
- case SDK_ON_CALL_MADE:
13370
- this.onCallMade(event.data.callSession);
13418
+ case SDK_ON_OUTGOING_CALL_MADE:
13419
+ this.onOutgoingCallMade(event.data.callSession);
13371
13420
  break;
13372
13421
  case SDK_CALL_ENDED: {
13373
13422
  const { callSession, content, direction, userExtension } = event.data;
@@ -13455,6 +13504,18 @@ class Softphone {
13455
13504
  case BRIDGE_ON_STOP_RECORDING:
13456
13505
  this.onStopRecording();
13457
13506
  break;
13507
+ case BRIDGE_ON_CARD_CANCELED:
13508
+ this.onCardCanceled();
13509
+ break;
13510
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
13511
+ this.onCallLocallyAnswered(event.data.call);
13512
+ break;
13513
+ case BRIDGE_ON_CALL_REJECTED:
13514
+ this.onCallRejected(event.data.call);
13515
+ break;
13516
+ case BRIDGE_ON_CALL_ESTABLISHED:
13517
+ this.onCallEstablished(event.data.call);
13518
+ break;
13458
13519
  default:
13459
13520
  this.onUnHandledEvent(event);
13460
13521
  break;
@@ -13462,8 +13523,8 @@ class Softphone {
13462
13523
  }
13463
13524
 
13464
13525
  _sendMessage(type , payload = {}) {
13465
- if (!this.iframe) {
13466
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
13526
+ if (!this.iframe || !this.iframeLoaded) {
13527
+ this._pendingMessages.push([type, payload]);
13467
13528
  return;
13468
13529
  }
13469
13530