@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.
@@ -13973,8 +13973,6 @@ class Checker {
13973
13973
  /* eslint-disable no-unused-vars */
13974
13974
  /* global window, document */
13975
13975
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13976
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13977
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13978
13976
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13979
13977
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13980
13978
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -13987,6 +13985,9 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13987
13985
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13988
13986
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13989
13987
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13988
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
13989
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
13990
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
13990
13991
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13991
13992
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13992
13993
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -14000,31 +14001,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
14000
14001
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
14001
14002
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
14002
14003
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
14004
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
14005
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
14006
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
14007
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
14008
+
14009
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
14010
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
14003
14011
 
14004
14012
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
14005
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
14013
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
14006
14014
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
14007
14015
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
14008
14016
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14009
14017
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
14010
14018
 
14011
14019
  class Softphone {
14012
- url = 'https://softphone.wazo.io';
14013
- width = 500;
14014
- height = 600;
14015
- displayed = false;
14016
- iframe = null;
14020
+
14021
+
14022
+
14023
+
14024
+
14025
+
14026
+
14027
+ // Message waiting for the iframe to be loaded
14028
+
14017
14029
 
14018
14030
  onLinkEnabled(link ) {}
14019
14031
  onIFrameLoaded() {}
14020
14032
 
14021
- onCallMade(call ) {}
14033
+ onCallLocallyAnswered(call ) {}
14034
+ onCallEstablished(call ) {}
14035
+ onOutgoingCallMade(call ) {}
14022
14036
  onCallIncoming(call ) {}
14037
+ onCallRejected(call ) {}
14023
14038
  onCallEnded(call , card , direction , fromExtension ) {}
14039
+
14024
14040
  onCardSaved(card ) {}
14041
+ onCardCanceled() {}
14025
14042
  onAuthenticated(session ) {}
14026
14043
  onLoggedOut() {}
14027
- onSearchOptions(fieldId , query ) {}
14044
+
14045
+ onSearchOptions(fieldId , query ) {
14046
+ this.onOptionsResults(fieldId, []);
14047
+ }
14048
+
14028
14049
  onDisplayLinkedOption(optionId ) {}
14029
14050
  onWazoContactSearch(query ) {}
14030
14051
  onAgentLoggedIn() {}
@@ -14047,18 +14068,26 @@ class Softphone {
14047
14068
  onStopRecording() {}
14048
14069
  onUnHandledEvent(event ) {}
14049
14070
 
14050
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
14051
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
14052
- if (url) {
14053
- this.url = url;
14054
- }
14055
- if (width) {
14056
- this.width = width;
14057
- }
14058
- if (height) {
14059
- this.height = height;
14060
- }
14071
+ init({
14072
+ url,
14073
+ width,
14074
+ height,
14075
+ server,
14076
+ port,
14077
+ language,
14078
+ wrapUpDuration,
14079
+ enableAgent = true,
14080
+ tenantId,
14081
+ debug = false,
14082
+ } = {}) {
14083
+ this.url = url || 'https://softphone.wazo.io';
14084
+ this.width = width || 500;
14085
+ this.height = height || 600;
14086
+ this.displayed = false;
14087
+ this.iframeLoaded = false;
14061
14088
 
14089
+ this.iframeLoaded = false;
14090
+ this._pendingMessages = [];
14062
14091
  window.addEventListener('message', this._onMessage.bind(this), false);
14063
14092
 
14064
14093
  if (!server) {
@@ -14066,25 +14095,33 @@ class Softphone {
14066
14095
  server = 'stack.dev.wazo.io';
14067
14096
  }
14068
14097
 
14069
- this._createIframe(() => {
14070
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
14071
- config: {
14072
- server,
14073
- port,
14074
- language,
14075
- wrapUpDuration,
14076
- shouldDisplayLinkedEntities,
14077
- allowContactCreation,
14078
- },
14079
- });
14098
+ const config = { server };
14099
+ if (language) {
14100
+ config.language = language;
14101
+ }
14102
+ if (port) {
14103
+ config.port = port;
14104
+ }
14105
+ if (tenantId) {
14106
+ config.tenantId = tenantId;
14107
+ }
14108
+ if (wrapUpDuration) {
14109
+ config.wrapUpDuration = wrapUpDuration;
14110
+ }
14080
14111
 
14081
- if (withCard) {
14082
- this._sendMessage(BRIDGE_ENABLE_CARD);
14083
- }
14112
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
14084
14113
 
14085
- if (subscriptionType) {
14086
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
14087
- }
14114
+ if (enableAgent) {
14115
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
14116
+ }
14117
+
14118
+ if (debug) {
14119
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
14120
+ }
14121
+
14122
+ this._createIframe(() => {
14123
+ this.iframeLoaded = true;
14124
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
14088
14125
 
14089
14126
  this.onIFrameLoaded();
14090
14127
  });
@@ -14145,6 +14182,18 @@ class Softphone {
14145
14182
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14146
14183
  }
14147
14184
 
14185
+ setCardValue(field , value ) {
14186
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
14187
+ }
14188
+
14189
+ injectCss(css ) {
14190
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
14191
+ }
14192
+
14193
+ customizeAppearance(themes , translations , assets ) {
14194
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
14195
+ }
14196
+
14148
14197
  _createIframe(cb = () => {}) {
14149
14198
  this.iframe = document.createElement('iframe');
14150
14199
  // $FlowFixMe
@@ -14190,8 +14239,8 @@ class Softphone {
14190
14239
  }
14191
14240
 
14192
14241
  switch (event.data.type) {
14193
- case SDK_ON_CALL_MADE:
14194
- this.onCallMade(event.data.callSession);
14242
+ case SDK_ON_OUTGOING_CALL_MADE:
14243
+ this.onOutgoingCallMade(event.data.callSession);
14195
14244
  break;
14196
14245
  case SDK_CALL_ENDED: {
14197
14246
  const { callSession, content, direction, userExtension } = event.data;
@@ -14279,6 +14328,18 @@ class Softphone {
14279
14328
  case BRIDGE_ON_STOP_RECORDING:
14280
14329
  this.onStopRecording();
14281
14330
  break;
14331
+ case BRIDGE_ON_CARD_CANCELED:
14332
+ this.onCardCanceled();
14333
+ break;
14334
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
14335
+ this.onCallLocallyAnswered(event.data.call);
14336
+ break;
14337
+ case BRIDGE_ON_CALL_REJECTED:
14338
+ this.onCallRejected(event.data.call);
14339
+ break;
14340
+ case BRIDGE_ON_CALL_ESTABLISHED:
14341
+ this.onCallEstablished(event.data.call);
14342
+ break;
14282
14343
  default:
14283
14344
  this.onUnHandledEvent(event);
14284
14345
  break;
@@ -14286,8 +14347,8 @@ class Softphone {
14286
14347
  }
14287
14348
 
14288
14349
  _sendMessage(type , payload = {}) {
14289
- if (!this.iframe) {
14290
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
14350
+ if (!this.iframe || !this.iframeLoaded) {
14351
+ this._pendingMessages.push([type, payload]);
14291
14352
  return;
14292
14353
  }
14293
14354
 
@@ -13957,8 +13957,6 @@ class Checker {
13957
13957
  /* eslint-disable no-unused-vars */
13958
13958
  /* global window, document */
13959
13959
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13960
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13961
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13962
13960
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13963
13961
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13964
13962
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -13971,6 +13969,9 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13971
13969
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13972
13970
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13973
13971
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13972
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
13973
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
13974
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
13974
13975
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13975
13976
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13976
13977
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -13984,31 +13985,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
13984
13985
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13985
13986
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13986
13987
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13988
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
13989
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
13990
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
13991
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
13992
+
13993
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
13994
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
13987
13995
 
13988
13996
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13989
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13997
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
13990
13998
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13991
13999
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13992
14000
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13993
14001
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13994
14002
 
13995
14003
  class Softphone {
13996
- url = 'https://softphone.wazo.io';
13997
- width = 500;
13998
- height = 600;
13999
- displayed = false;
14000
- iframe = null;
14004
+
14005
+
14006
+
14007
+
14008
+
14009
+
14010
+
14011
+ // Message waiting for the iframe to be loaded
14012
+
14001
14013
 
14002
14014
  onLinkEnabled(link ) {}
14003
14015
  onIFrameLoaded() {}
14004
14016
 
14005
- onCallMade(call ) {}
14017
+ onCallLocallyAnswered(call ) {}
14018
+ onCallEstablished(call ) {}
14019
+ onOutgoingCallMade(call ) {}
14006
14020
  onCallIncoming(call ) {}
14021
+ onCallRejected(call ) {}
14007
14022
  onCallEnded(call , card , direction , fromExtension ) {}
14023
+
14008
14024
  onCardSaved(card ) {}
14025
+ onCardCanceled() {}
14009
14026
  onAuthenticated(session ) {}
14010
14027
  onLoggedOut() {}
14011
- onSearchOptions(fieldId , query ) {}
14028
+
14029
+ onSearchOptions(fieldId , query ) {
14030
+ this.onOptionsResults(fieldId, []);
14031
+ }
14032
+
14012
14033
  onDisplayLinkedOption(optionId ) {}
14013
14034
  onWazoContactSearch(query ) {}
14014
14035
  onAgentLoggedIn() {}
@@ -14031,18 +14052,26 @@ class Softphone {
14031
14052
  onStopRecording() {}
14032
14053
  onUnHandledEvent(event ) {}
14033
14054
 
14034
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
14035
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
14036
- if (url) {
14037
- this.url = url;
14038
- }
14039
- if (width) {
14040
- this.width = width;
14041
- }
14042
- if (height) {
14043
- this.height = height;
14044
- }
14055
+ init({
14056
+ url,
14057
+ width,
14058
+ height,
14059
+ server,
14060
+ port,
14061
+ language,
14062
+ wrapUpDuration,
14063
+ enableAgent = true,
14064
+ tenantId,
14065
+ debug = false,
14066
+ } = {}) {
14067
+ this.url = url || 'https://softphone.wazo.io';
14068
+ this.width = width || 500;
14069
+ this.height = height || 600;
14070
+ this.displayed = false;
14071
+ this.iframeLoaded = false;
14045
14072
 
14073
+ this.iframeLoaded = false;
14074
+ this._pendingMessages = [];
14046
14075
  window.addEventListener('message', this._onMessage.bind(this), false);
14047
14076
 
14048
14077
  if (!server) {
@@ -14050,25 +14079,33 @@ class Softphone {
14050
14079
  server = 'stack.dev.wazo.io';
14051
14080
  }
14052
14081
 
14053
- this._createIframe(() => {
14054
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
14055
- config: {
14056
- server,
14057
- port,
14058
- language,
14059
- wrapUpDuration,
14060
- shouldDisplayLinkedEntities,
14061
- allowContactCreation,
14062
- },
14063
- });
14082
+ const config = { server };
14083
+ if (language) {
14084
+ config.language = language;
14085
+ }
14086
+ if (port) {
14087
+ config.port = port;
14088
+ }
14089
+ if (tenantId) {
14090
+ config.tenantId = tenantId;
14091
+ }
14092
+ if (wrapUpDuration) {
14093
+ config.wrapUpDuration = wrapUpDuration;
14094
+ }
14064
14095
 
14065
- if (withCard) {
14066
- this._sendMessage(BRIDGE_ENABLE_CARD);
14067
- }
14096
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
14068
14097
 
14069
- if (subscriptionType) {
14070
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
14071
- }
14098
+ if (enableAgent) {
14099
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
14100
+ }
14101
+
14102
+ if (debug) {
14103
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
14104
+ }
14105
+
14106
+ this._createIframe(() => {
14107
+ this.iframeLoaded = true;
14108
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
14072
14109
 
14073
14110
  this.onIFrameLoaded();
14074
14111
  });
@@ -14129,6 +14166,18 @@ class Softphone {
14129
14166
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14130
14167
  }
14131
14168
 
14169
+ setCardValue(field , value ) {
14170
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
14171
+ }
14172
+
14173
+ injectCss(css ) {
14174
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
14175
+ }
14176
+
14177
+ customizeAppearance(themes , translations , assets ) {
14178
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
14179
+ }
14180
+
14132
14181
  _createIframe(cb = () => {}) {
14133
14182
  this.iframe = document.createElement('iframe');
14134
14183
  // $FlowFixMe
@@ -14174,8 +14223,8 @@ class Softphone {
14174
14223
  }
14175
14224
 
14176
14225
  switch (event.data.type) {
14177
- case SDK_ON_CALL_MADE:
14178
- this.onCallMade(event.data.callSession);
14226
+ case SDK_ON_OUTGOING_CALL_MADE:
14227
+ this.onOutgoingCallMade(event.data.callSession);
14179
14228
  break;
14180
14229
  case SDK_CALL_ENDED: {
14181
14230
  const { callSession, content, direction, userExtension } = event.data;
@@ -14263,6 +14312,18 @@ class Softphone {
14263
14312
  case BRIDGE_ON_STOP_RECORDING:
14264
14313
  this.onStopRecording();
14265
14314
  break;
14315
+ case BRIDGE_ON_CARD_CANCELED:
14316
+ this.onCardCanceled();
14317
+ break;
14318
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
14319
+ this.onCallLocallyAnswered(event.data.call);
14320
+ break;
14321
+ case BRIDGE_ON_CALL_REJECTED:
14322
+ this.onCallRejected(event.data.call);
14323
+ break;
14324
+ case BRIDGE_ON_CALL_ESTABLISHED:
14325
+ this.onCallEstablished(event.data.call);
14326
+ break;
14266
14327
  default:
14267
14328
  this.onUnHandledEvent(event);
14268
14329
  break;
@@ -14270,8 +14331,8 @@ class Softphone {
14270
14331
  }
14271
14332
 
14272
14333
  _sendMessage(type , payload = {}) {
14273
- if (!this.iframe) {
14274
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
14334
+ if (!this.iframe || !this.iframeLoaded) {
14335
+ this._pendingMessages.push([type, payload]);
14275
14336
  return;
14276
14337
  }
14277
14338
 
package/lib/index.js CHANGED
@@ -14122,8 +14122,6 @@ const createLocalAudioStream = async (options ) => createLocalStream('aud
14122
14122
  /* eslint-disable no-unused-vars */
14123
14123
  /* global window, document */
14124
14124
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
14125
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
14126
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
14127
14125
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
14128
14126
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
14129
14127
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -14136,6 +14134,9 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
14136
14134
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
14137
14135
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
14138
14136
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
14137
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
14138
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
14139
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
14139
14140
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
14140
14141
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
14141
14142
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -14149,31 +14150,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
14149
14150
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
14150
14151
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
14151
14152
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
14153
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
14154
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
14155
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
14156
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
14157
+
14158
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
14159
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
14152
14160
 
14153
14161
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
14154
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
14162
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
14155
14163
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
14156
14164
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
14157
14165
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14158
14166
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
14159
14167
 
14160
14168
  class Softphone {
14161
- url = 'https://softphone.wazo.io';
14162
- width = 500;
14163
- height = 600;
14164
- displayed = false;
14165
- iframe = null;
14169
+
14170
+
14171
+
14172
+
14173
+
14174
+
14175
+
14176
+ // Message waiting for the iframe to be loaded
14177
+
14166
14178
 
14167
14179
  onLinkEnabled(link ) {}
14168
14180
  onIFrameLoaded() {}
14169
14181
 
14170
- onCallMade(call ) {}
14182
+ onCallLocallyAnswered(call ) {}
14183
+ onCallEstablished(call ) {}
14184
+ onOutgoingCallMade(call ) {}
14171
14185
  onCallIncoming(call ) {}
14186
+ onCallRejected(call ) {}
14172
14187
  onCallEnded(call , card , direction , fromExtension ) {}
14188
+
14173
14189
  onCardSaved(card ) {}
14190
+ onCardCanceled() {}
14174
14191
  onAuthenticated(session ) {}
14175
14192
  onLoggedOut() {}
14176
- onSearchOptions(fieldId , query ) {}
14193
+
14194
+ onSearchOptions(fieldId , query ) {
14195
+ this.onOptionsResults(fieldId, []);
14196
+ }
14197
+
14177
14198
  onDisplayLinkedOption(optionId ) {}
14178
14199
  onWazoContactSearch(query ) {}
14179
14200
  onAgentLoggedIn() {}
@@ -14196,18 +14217,26 @@ class Softphone {
14196
14217
  onStopRecording() {}
14197
14218
  onUnHandledEvent(event ) {}
14198
14219
 
14199
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
14200
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
14201
- if (url) {
14202
- this.url = url;
14203
- }
14204
- if (width) {
14205
- this.width = width;
14206
- }
14207
- if (height) {
14208
- this.height = height;
14209
- }
14220
+ init({
14221
+ url,
14222
+ width,
14223
+ height,
14224
+ server,
14225
+ port,
14226
+ language,
14227
+ wrapUpDuration,
14228
+ enableAgent = true,
14229
+ tenantId,
14230
+ debug = false,
14231
+ } = {}) {
14232
+ this.url = url || 'https://softphone.wazo.io';
14233
+ this.width = width || 500;
14234
+ this.height = height || 600;
14235
+ this.displayed = false;
14236
+ this.iframeLoaded = false;
14210
14237
 
14238
+ this.iframeLoaded = false;
14239
+ this._pendingMessages = [];
14211
14240
  window.addEventListener('message', this._onMessage.bind(this), false);
14212
14241
 
14213
14242
  if (!server) {
@@ -14215,25 +14244,33 @@ class Softphone {
14215
14244
  server = 'stack.dev.wazo.io';
14216
14245
  }
14217
14246
 
14218
- this._createIframe(() => {
14219
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
14220
- config: {
14221
- server,
14222
- port,
14223
- language,
14224
- wrapUpDuration,
14225
- shouldDisplayLinkedEntities,
14226
- allowContactCreation,
14227
- },
14228
- });
14247
+ const config = { server };
14248
+ if (language) {
14249
+ config.language = language;
14250
+ }
14251
+ if (port) {
14252
+ config.port = port;
14253
+ }
14254
+ if (tenantId) {
14255
+ config.tenantId = tenantId;
14256
+ }
14257
+ if (wrapUpDuration) {
14258
+ config.wrapUpDuration = wrapUpDuration;
14259
+ }
14229
14260
 
14230
- if (withCard) {
14231
- this._sendMessage(BRIDGE_ENABLE_CARD);
14232
- }
14261
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
14233
14262
 
14234
- if (subscriptionType) {
14235
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
14236
- }
14263
+ if (enableAgent) {
14264
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
14265
+ }
14266
+
14267
+ if (debug) {
14268
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
14269
+ }
14270
+
14271
+ this._createIframe(() => {
14272
+ this.iframeLoaded = true;
14273
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
14237
14274
 
14238
14275
  this.onIFrameLoaded();
14239
14276
  });
@@ -14294,6 +14331,18 @@ class Softphone {
14294
14331
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14295
14332
  }
14296
14333
 
14334
+ setCardValue(field , value ) {
14335
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
14336
+ }
14337
+
14338
+ injectCss(css ) {
14339
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
14340
+ }
14341
+
14342
+ customizeAppearance(themes , translations , assets ) {
14343
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
14344
+ }
14345
+
14297
14346
  _createIframe(cb = () => {}) {
14298
14347
  this.iframe = document.createElement('iframe');
14299
14348
  // $FlowFixMe
@@ -14339,8 +14388,8 @@ class Softphone {
14339
14388
  }
14340
14389
 
14341
14390
  switch (event.data.type) {
14342
- case SDK_ON_CALL_MADE:
14343
- this.onCallMade(event.data.callSession);
14391
+ case SDK_ON_OUTGOING_CALL_MADE:
14392
+ this.onOutgoingCallMade(event.data.callSession);
14344
14393
  break;
14345
14394
  case SDK_CALL_ENDED: {
14346
14395
  const { callSession, content, direction, userExtension } = event.data;
@@ -14428,6 +14477,18 @@ class Softphone {
14428
14477
  case BRIDGE_ON_STOP_RECORDING:
14429
14478
  this.onStopRecording();
14430
14479
  break;
14480
+ case BRIDGE_ON_CARD_CANCELED:
14481
+ this.onCardCanceled();
14482
+ break;
14483
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
14484
+ this.onCallLocallyAnswered(event.data.call);
14485
+ break;
14486
+ case BRIDGE_ON_CALL_REJECTED:
14487
+ this.onCallRejected(event.data.call);
14488
+ break;
14489
+ case BRIDGE_ON_CALL_ESTABLISHED:
14490
+ this.onCallEstablished(event.data.call);
14491
+ break;
14431
14492
  default:
14432
14493
  this.onUnHandledEvent(event);
14433
14494
  break;
@@ -14435,8 +14496,8 @@ class Softphone {
14435
14496
  }
14436
14497
 
14437
14498
  _sendMessage(type , payload = {}) {
14438
- if (!this.iframe) {
14439
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
14499
+ if (!this.iframe || !this.iframeLoaded) {
14500
+ this._pendingMessages.push([type, payload]);
14440
14501
  return;
14441
14502
  }
14442
14503