@wazo/sdk 0.38.0 → 0.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +218 -0
  2. package/dist/wazo-sdk.js +5 -5
  3. package/esm/__tests__/web-rtc-client.test.js +1 -1
  4. package/esm/checker/Checker.js +1 -1
  5. package/esm/checker/checks/index.js +1 -1
  6. package/esm/checker/checks/webrtc-transport.js +1 -1
  7. package/esm/checker/checks/webrtc.js +1 -1
  8. package/esm/index.js +191 -10
  9. package/esm/simple/Auth.js +191 -10
  10. package/esm/simple/Configuration.js +191 -10
  11. package/esm/simple/Phone.js +191 -10
  12. package/esm/simple/Softphone.js +189 -8
  13. package/esm/simple/index.js +191 -10
  14. package/esm/simple/room/LocalParticipant.js +191 -10
  15. package/esm/simple/room/Participant.js +191 -10
  16. package/esm/simple/room/RemoteParticipant.js +191 -10
  17. package/esm/simple/room/Room.js +191 -10
  18. package/esm/simple/room/SipRoom.js +191 -10
  19. package/esm/simple/room/Stream.js +191 -10
  20. package/esm/simple/room/__tests__/RemoteParticipant.test.js +191 -10
  21. package/esm/simple/utils.js +191 -10
  22. package/esm/web-rtc-client.js +1 -1
  23. package/lib/__tests__/web-rtc-client.test.js +1 -1
  24. package/lib/checker/Checker.js +1 -1
  25. package/lib/checker/checks/index.js +1 -1
  26. package/lib/checker/checks/webrtc-transport.js +1 -1
  27. package/lib/checker/checks/webrtc.js +1 -1
  28. package/lib/index.js +191 -10
  29. package/lib/simple/Auth.js +191 -10
  30. package/lib/simple/Configuration.js +191 -10
  31. package/lib/simple/Phone.js +191 -10
  32. package/lib/simple/Softphone.js +189 -8
  33. package/lib/simple/index.js +191 -10
  34. package/lib/simple/room/LocalParticipant.js +191 -10
  35. package/lib/simple/room/Participant.js +191 -10
  36. package/lib/simple/room/RemoteParticipant.js +191 -10
  37. package/lib/simple/room/Room.js +191 -10
  38. package/lib/simple/room/SipRoom.js +191 -10
  39. package/lib/simple/room/Stream.js +191 -10
  40. package/lib/simple/room/__tests__/RemoteParticipant.test.js +191 -10
  41. package/lib/simple/utils.js +191 -10
  42. package/lib/web-rtc-client.js +1 -1
  43. package/package.json +1 -1
  44. package/src/simple/Softphone.js +187 -8
  45. package/src/web-rtc-client.js +1 -1
@@ -8336,7 +8336,7 @@ class WebRTCClient extends Emitter {
8336
8336
  }
8337
8337
 
8338
8338
  async _onHeartbeatTimeout() {
8339
- logger$8.info('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8339
+ logger$8.warn('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8340
8340
 
8341
8341
  if (this.heartbeatTimeoutCb) {
8342
8342
  this.heartbeatTimeoutCb();
@@ -13982,11 +13982,41 @@ class Checker {
13982
13982
  //
13983
13983
  /* eslint-disable no-unused-vars */
13984
13984
  /* global window, document */
13985
+ const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13986
+ const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13987
+ const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13988
+ const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13989
+ const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13990
+ const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
13991
+ const BRIDGE_SEARCH_OPTIONS = 'bridge/BRIDGE_SEARCH_OPTIONS';
13992
+ const BRIDGE_DISPLAY_LINKED_OPTION = 'bridge/DISPLAY_LINKED_OPTION';
13993
+ const BRIDGE_UPDATE_FORM_SCHEMA = 'bridge/BRIDGE_UPDATE_FORM_SCHEMA';
13994
+ const BRIDGE_WAZO_CONTACT_SEARCH = 'bridge/BRIDGE_WAZO_CONTACT_SEARCH';
13995
+ const BRIDGE_ON_AGENT_LOGGED_IN = 'bridge/BRIDGE_ON_AGENT_LOGGED_IN';
13996
+ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13997
+ const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13998
+ const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13999
+ const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
14000
+ const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
14001
+ const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
14002
+ const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
14003
+ const BRIDGE_ON_CALL_UN_MUTED = 'bridge/BRIDGE_ON_CALL_UN_MUTED';
14004
+ const BRIDGE_ON_DTMF = 'bridge/BRIDGE_ON_DTMF';
14005
+ const BRIDGE_ON_DIRECT_TRANSFER = 'bridge/BRIDGE_ON_DIRECT_TRANSFER';
14006
+ const BRIDGE_ON_CREATE_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CREATE_INDIRECT_TRANSFER';
14007
+ const BRIDGE_ON_CANCEL_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CANCEL_INDIRECT_TRANSFER';
14008
+ const BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER';
14009
+ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE';
14010
+ const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
14011
+ const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
14012
+ const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
14013
+
13985
14014
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13986
14015
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13987
14016
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13988
14017
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13989
14018
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14019
+ const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13990
14020
 
13991
14021
  class Softphone {
13992
14022
  url = 'https://softphone.wazo.io';
@@ -13996,13 +14026,39 @@ class Softphone {
13996
14026
  iframe = null;
13997
14027
 
13998
14028
  onLinkEnabled(link ) {}
14029
+ onIFrameLoaded() {}
13999
14030
 
14000
14031
  onCallMade(call ) {}
14001
14032
  onCallIncoming(call ) {}
14002
14033
  onCallEnded(call , card , direction , fromExtension ) {}
14034
+ onCardSaved(card ) {}
14003
14035
  onAuthenticated(session ) {}
14004
-
14005
- init(url , width , height ) {
14036
+ onLoggedOut() {}
14037
+ onSearchOptions(fieldId , query ) {}
14038
+ onDisplayLinkedOption(optionId ) {}
14039
+ onWazoContactSearch(query ) {}
14040
+ onAgentLoggedIn() {}
14041
+ onAgentLoggedOut() {}
14042
+ onAgentPaused() {}
14043
+ onAgentResumed() {}
14044
+ onLanguageChanged(language ) {}
14045
+ onCallHeld() {}
14046
+ onCallResumed() {}
14047
+ onCallMuted() {}
14048
+ onCallUnMuted() {}
14049
+ onDtmfSent(tone ) {}
14050
+ onDirectTransfer(number ) {}
14051
+ onCreateIndirectTransfer(number ) {}
14052
+ onCancelIndirectTransfer() {}
14053
+ onConfirmIndirectTransfer() {}
14054
+ onIndirectCallMade(call ) {}
14055
+ onIndirectTransferDone(call ) {}
14056
+ onStartRecording() {}
14057
+ onStopRecording() {}
14058
+ onUnHandledEvent(event ) {}
14059
+
14060
+ init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
14061
+ allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
14006
14062
  if (url) {
14007
14063
  this.url = url;
14008
14064
  }
@@ -14015,7 +14071,33 @@ class Softphone {
14015
14071
 
14016
14072
  window.addEventListener('message', this._onMessage.bind(this), false);
14017
14073
 
14018
- this._createIframe();
14074
+ if (!server) {
14075
+ // eslint-disable-next-line no-param-reassign
14076
+ server = 'stack.dev.wazo.io';
14077
+ }
14078
+
14079
+ this._createIframe(() => {
14080
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
14081
+ config: {
14082
+ server,
14083
+ port,
14084
+ language,
14085
+ wrapUpDuration,
14086
+ shouldDisplayLinkedEntities,
14087
+ allowContactCreation,
14088
+ },
14089
+ });
14090
+
14091
+ if (withCard) {
14092
+ this._sendMessage(BRIDGE_ENABLE_CARD);
14093
+ }
14094
+
14095
+ if (subscriptionType) {
14096
+ this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
14097
+ }
14098
+
14099
+ this.onIFrameLoaded();
14100
+ });
14019
14101
  }
14020
14102
 
14021
14103
  parseLinks() {
@@ -14031,9 +14113,7 @@ class Softphone {
14031
14113
  makeCall(number ) {
14032
14114
  this.displaySoftphone();
14033
14115
 
14034
- if (this.iframe) {
14035
- this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
14036
- }
14116
+ this._sendMessage(SDK_CLICK_TO_CALL, { number });
14037
14117
  }
14038
14118
 
14039
14119
  toggleSoftphoneDisplay() {
@@ -14042,8 +14122,6 @@ class Softphone {
14042
14122
  } else {
14043
14123
  this.displaySoftphone();
14044
14124
  }
14045
-
14046
- this.displayed = !this.displayed;
14047
14125
  }
14048
14126
 
14049
14127
  displaySoftphone() {
@@ -14054,15 +14132,30 @@ class Softphone {
14054
14132
  if (this.iframe) {
14055
14133
  this.iframe.style.display = 'block';
14056
14134
  }
14135
+
14136
+ this.displayed = true;
14057
14137
  }
14058
14138
 
14059
14139
  hideSoftphone() {
14060
14140
  if (this.iframe) {
14061
14141
  this.iframe.style.display = 'none';
14062
14142
  }
14143
+ this.displayed = false;
14144
+ }
14145
+
14146
+ optionsFetched(fieldId , options ) {
14147
+ this._sendMessage(BRIDGE_OPTIONS_FETCHED, { fieldId, options });
14148
+ }
14149
+
14150
+ onOptionsResults(fieldId , options ) {
14151
+ this._sendMessage(BRIDGE_OPTIONS_FOUND, { fieldId, options });
14152
+ }
14153
+
14154
+ setFormSchema(schema , uiSchema ) {
14155
+ this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14063
14156
  }
14064
14157
 
14065
- _createIframe() {
14158
+ _createIframe(cb = () => {}) {
14066
14159
  this.iframe = document.createElement('iframe');
14067
14160
  // $FlowFixMe
14068
14161
  this.iframe.width = this.width;
@@ -14074,10 +14167,13 @@ class Softphone {
14074
14167
  this.iframe.style.left = '0';
14075
14168
  this.iframe.style.bottom = '0';
14076
14169
  this.iframe.style.border = '1px solid #aaa';
14170
+ this.iframe.style.backgroundColor = 'white';
14077
14171
  this.iframe.src = this.url;
14078
14172
  this.iframe.style.display = 'none';
14079
14173
  this.iframe.id = 'wazo-softphone';
14080
14174
 
14175
+ this.iframe.onload = cb;
14176
+
14081
14177
  // $FlowFixMe
14082
14178
  document.body.appendChild(this.iframe);
14083
14179
  }
@@ -14120,8 +14216,93 @@ class Softphone {
14120
14216
  this._onAuthenticated(event.data.session);
14121
14217
  this.onAuthenticated(event.data.session);
14122
14218
  break;
14219
+ case SDK_LOGGED_OUT:
14220
+ this.onLoggedOut();
14221
+ break;
14222
+ case BRIDGE_CREATE_OR_UPDATE_CARD: {
14223
+ const { content } = event.data;
14224
+ this.onCardSaved(content);
14225
+ break;
14226
+ }
14227
+ case BRIDGE_SEARCH_OPTIONS: {
14228
+ const { fieldId, query } = event.data;
14229
+ this.onSearchOptions(fieldId, query);
14230
+ break;
14231
+ }
14232
+ case BRIDGE_DISPLAY_LINKED_OPTION:
14233
+ this.onDisplayLinkedOption(event.data.linkedOptionId);
14234
+ break;
14235
+ case BRIDGE_WAZO_CONTACT_SEARCH:
14236
+ this.onWazoContactSearch(event.data.query);
14237
+ break;
14238
+ case BRIDGE_ON_AGENT_LOGGED_IN:
14239
+ this.onAgentLoggedIn();
14240
+ break;
14241
+ case BRIDGE_ON_AGENT_LOGGED_OUT:
14242
+ this.onAgentLoggedOut();
14243
+ break;
14244
+ case BRIDGE_ON_AGENT_PAUSED:
14245
+ this.onAgentPaused();
14246
+ break;
14247
+ case BRIDGE_ON_AGENT_RESUMED:
14248
+ this.onAgentResumed();
14249
+ break;
14250
+ case BRIDGE_ON_LANGUAGE_CHANGED:
14251
+ this.onLanguageChanged(event.data.language);
14252
+ break;
14253
+ case BRIDGE_ON_CALL_HELD:
14254
+ this.onCallHeld();
14255
+ break;
14256
+ case BRIDGE_ON_CALL_RESUMED:
14257
+ this.onCallResumed();
14258
+ break;
14259
+ case BRIDGE_ON_CALL_MUTED:
14260
+ this.onCallMuted();
14261
+ break;
14262
+ case BRIDGE_ON_CALL_UN_MUTED:
14263
+ this.onCallUnMuted();
14264
+ break;
14265
+ case BRIDGE_ON_DTMF:
14266
+ this.onDtmfSent(event.data.tone);
14267
+ break;
14268
+ case BRIDGE_ON_DIRECT_TRANSFER:
14269
+ this.onDirectTransfer(event.data.number);
14270
+ break;
14271
+ case BRIDGE_ON_CREATE_INDIRECT_TRANSFER:
14272
+ this.onCreateIndirectTransfer(event.data.number);
14273
+ break;
14274
+ case BRIDGE_ON_CANCEL_INDIRECT_TRANSFER:
14275
+ this.onCancelIndirectTransfer();
14276
+ break;
14277
+ case BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER:
14278
+ this.onConfirmIndirectTransfer();
14279
+ break;
14280
+ case BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE:
14281
+ this.onIndirectCallMade(event.data.call);
14282
+ break;
14283
+ case BRIDGE_ON_INDIRECT_TRANSFER_DONE:
14284
+ this.onIndirectTransferDone(event.data.call);
14285
+ break;
14286
+ case BRIDGE_ON_START_RECORDING:
14287
+ this.onStartRecording();
14288
+ break;
14289
+ case BRIDGE_ON_STOP_RECORDING:
14290
+ this.onStopRecording();
14291
+ break;
14292
+ default:
14293
+ this.onUnHandledEvent(event);
14294
+ break;
14123
14295
  }
14124
14296
  }
14297
+
14298
+ _sendMessage(type , payload = {}) {
14299
+ if (!this.iframe) {
14300
+ console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
14301
+ return;
14302
+ }
14303
+
14304
+ this.iframe.contentWindow.postMessage({ type, ...payload }, '*');
14305
+ }
14125
14306
  }
14126
14307
 
14127
14308
  var Softphone$1 = new Softphone();
@@ -8338,7 +8338,7 @@ class WebRTCClient extends Emitter {
8338
8338
  }
8339
8339
 
8340
8340
  async _onHeartbeatTimeout() {
8341
- logger$8.info('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8341
+ logger$8.warn('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8342
8342
 
8343
8343
  if (this.heartbeatTimeoutCb) {
8344
8344
  this.heartbeatTimeoutCb();
@@ -13968,11 +13968,41 @@ class Checker {
13968
13968
  //
13969
13969
  /* eslint-disable no-unused-vars */
13970
13970
  /* global window, document */
13971
+ const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13972
+ const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13973
+ const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13974
+ const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13975
+ const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13976
+ const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
13977
+ const BRIDGE_SEARCH_OPTIONS = 'bridge/BRIDGE_SEARCH_OPTIONS';
13978
+ const BRIDGE_DISPLAY_LINKED_OPTION = 'bridge/DISPLAY_LINKED_OPTION';
13979
+ const BRIDGE_UPDATE_FORM_SCHEMA = 'bridge/BRIDGE_UPDATE_FORM_SCHEMA';
13980
+ const BRIDGE_WAZO_CONTACT_SEARCH = 'bridge/BRIDGE_WAZO_CONTACT_SEARCH';
13981
+ const BRIDGE_ON_AGENT_LOGGED_IN = 'bridge/BRIDGE_ON_AGENT_LOGGED_IN';
13982
+ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13983
+ const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13984
+ const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13985
+ const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13986
+ const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13987
+ const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13988
+ const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
13989
+ const BRIDGE_ON_CALL_UN_MUTED = 'bridge/BRIDGE_ON_CALL_UN_MUTED';
13990
+ const BRIDGE_ON_DTMF = 'bridge/BRIDGE_ON_DTMF';
13991
+ const BRIDGE_ON_DIRECT_TRANSFER = 'bridge/BRIDGE_ON_DIRECT_TRANSFER';
13992
+ const BRIDGE_ON_CREATE_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CREATE_INDIRECT_TRANSFER';
13993
+ const BRIDGE_ON_CANCEL_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CANCEL_INDIRECT_TRANSFER';
13994
+ const BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER';
13995
+ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE';
13996
+ const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13997
+ const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13998
+ const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13999
+
13971
14000
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13972
14001
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13973
14002
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13974
14003
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13975
14004
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14005
+ const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13976
14006
 
13977
14007
  class Softphone {
13978
14008
  url = 'https://softphone.wazo.io';
@@ -13982,13 +14012,39 @@ class Softphone {
13982
14012
  iframe = null;
13983
14013
 
13984
14014
  onLinkEnabled(link ) {}
14015
+ onIFrameLoaded() {}
13985
14016
 
13986
14017
  onCallMade(call ) {}
13987
14018
  onCallIncoming(call ) {}
13988
14019
  onCallEnded(call , card , direction , fromExtension ) {}
14020
+ onCardSaved(card ) {}
13989
14021
  onAuthenticated(session ) {}
13990
-
13991
- init(url , width , height ) {
14022
+ onLoggedOut() {}
14023
+ onSearchOptions(fieldId , query ) {}
14024
+ onDisplayLinkedOption(optionId ) {}
14025
+ onWazoContactSearch(query ) {}
14026
+ onAgentLoggedIn() {}
14027
+ onAgentLoggedOut() {}
14028
+ onAgentPaused() {}
14029
+ onAgentResumed() {}
14030
+ onLanguageChanged(language ) {}
14031
+ onCallHeld() {}
14032
+ onCallResumed() {}
14033
+ onCallMuted() {}
14034
+ onCallUnMuted() {}
14035
+ onDtmfSent(tone ) {}
14036
+ onDirectTransfer(number ) {}
14037
+ onCreateIndirectTransfer(number ) {}
14038
+ onCancelIndirectTransfer() {}
14039
+ onConfirmIndirectTransfer() {}
14040
+ onIndirectCallMade(call ) {}
14041
+ onIndirectTransferDone(call ) {}
14042
+ onStartRecording() {}
14043
+ onStopRecording() {}
14044
+ onUnHandledEvent(event ) {}
14045
+
14046
+ init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
14047
+ allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13992
14048
  if (url) {
13993
14049
  this.url = url;
13994
14050
  }
@@ -14001,7 +14057,33 @@ class Softphone {
14001
14057
 
14002
14058
  window.addEventListener('message', this._onMessage.bind(this), false);
14003
14059
 
14004
- this._createIframe();
14060
+ if (!server) {
14061
+ // eslint-disable-next-line no-param-reassign
14062
+ server = 'stack.dev.wazo.io';
14063
+ }
14064
+
14065
+ this._createIframe(() => {
14066
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
14067
+ config: {
14068
+ server,
14069
+ port,
14070
+ language,
14071
+ wrapUpDuration,
14072
+ shouldDisplayLinkedEntities,
14073
+ allowContactCreation,
14074
+ },
14075
+ });
14076
+
14077
+ if (withCard) {
14078
+ this._sendMessage(BRIDGE_ENABLE_CARD);
14079
+ }
14080
+
14081
+ if (subscriptionType) {
14082
+ this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
14083
+ }
14084
+
14085
+ this.onIFrameLoaded();
14086
+ });
14005
14087
  }
14006
14088
 
14007
14089
  parseLinks() {
@@ -14017,9 +14099,7 @@ class Softphone {
14017
14099
  makeCall(number ) {
14018
14100
  this.displaySoftphone();
14019
14101
 
14020
- if (this.iframe) {
14021
- this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
14022
- }
14102
+ this._sendMessage(SDK_CLICK_TO_CALL, { number });
14023
14103
  }
14024
14104
 
14025
14105
  toggleSoftphoneDisplay() {
@@ -14028,8 +14108,6 @@ class Softphone {
14028
14108
  } else {
14029
14109
  this.displaySoftphone();
14030
14110
  }
14031
-
14032
- this.displayed = !this.displayed;
14033
14111
  }
14034
14112
 
14035
14113
  displaySoftphone() {
@@ -14040,15 +14118,30 @@ class Softphone {
14040
14118
  if (this.iframe) {
14041
14119
  this.iframe.style.display = 'block';
14042
14120
  }
14121
+
14122
+ this.displayed = true;
14043
14123
  }
14044
14124
 
14045
14125
  hideSoftphone() {
14046
14126
  if (this.iframe) {
14047
14127
  this.iframe.style.display = 'none';
14048
14128
  }
14129
+ this.displayed = false;
14130
+ }
14131
+
14132
+ optionsFetched(fieldId , options ) {
14133
+ this._sendMessage(BRIDGE_OPTIONS_FETCHED, { fieldId, options });
14134
+ }
14135
+
14136
+ onOptionsResults(fieldId , options ) {
14137
+ this._sendMessage(BRIDGE_OPTIONS_FOUND, { fieldId, options });
14138
+ }
14139
+
14140
+ setFormSchema(schema , uiSchema ) {
14141
+ this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14049
14142
  }
14050
14143
 
14051
- _createIframe() {
14144
+ _createIframe(cb = () => {}) {
14052
14145
  this.iframe = document.createElement('iframe');
14053
14146
  // $FlowFixMe
14054
14147
  this.iframe.width = this.width;
@@ -14060,10 +14153,13 @@ class Softphone {
14060
14153
  this.iframe.style.left = '0';
14061
14154
  this.iframe.style.bottom = '0';
14062
14155
  this.iframe.style.border = '1px solid #aaa';
14156
+ this.iframe.style.backgroundColor = 'white';
14063
14157
  this.iframe.src = this.url;
14064
14158
  this.iframe.style.display = 'none';
14065
14159
  this.iframe.id = 'wazo-softphone';
14066
14160
 
14161
+ this.iframe.onload = cb;
14162
+
14067
14163
  // $FlowFixMe
14068
14164
  document.body.appendChild(this.iframe);
14069
14165
  }
@@ -14106,8 +14202,93 @@ class Softphone {
14106
14202
  this._onAuthenticated(event.data.session);
14107
14203
  this.onAuthenticated(event.data.session);
14108
14204
  break;
14205
+ case SDK_LOGGED_OUT:
14206
+ this.onLoggedOut();
14207
+ break;
14208
+ case BRIDGE_CREATE_OR_UPDATE_CARD: {
14209
+ const { content } = event.data;
14210
+ this.onCardSaved(content);
14211
+ break;
14212
+ }
14213
+ case BRIDGE_SEARCH_OPTIONS: {
14214
+ const { fieldId, query } = event.data;
14215
+ this.onSearchOptions(fieldId, query);
14216
+ break;
14217
+ }
14218
+ case BRIDGE_DISPLAY_LINKED_OPTION:
14219
+ this.onDisplayLinkedOption(event.data.linkedOptionId);
14220
+ break;
14221
+ case BRIDGE_WAZO_CONTACT_SEARCH:
14222
+ this.onWazoContactSearch(event.data.query);
14223
+ break;
14224
+ case BRIDGE_ON_AGENT_LOGGED_IN:
14225
+ this.onAgentLoggedIn();
14226
+ break;
14227
+ case BRIDGE_ON_AGENT_LOGGED_OUT:
14228
+ this.onAgentLoggedOut();
14229
+ break;
14230
+ case BRIDGE_ON_AGENT_PAUSED:
14231
+ this.onAgentPaused();
14232
+ break;
14233
+ case BRIDGE_ON_AGENT_RESUMED:
14234
+ this.onAgentResumed();
14235
+ break;
14236
+ case BRIDGE_ON_LANGUAGE_CHANGED:
14237
+ this.onLanguageChanged(event.data.language);
14238
+ break;
14239
+ case BRIDGE_ON_CALL_HELD:
14240
+ this.onCallHeld();
14241
+ break;
14242
+ case BRIDGE_ON_CALL_RESUMED:
14243
+ this.onCallResumed();
14244
+ break;
14245
+ case BRIDGE_ON_CALL_MUTED:
14246
+ this.onCallMuted();
14247
+ break;
14248
+ case BRIDGE_ON_CALL_UN_MUTED:
14249
+ this.onCallUnMuted();
14250
+ break;
14251
+ case BRIDGE_ON_DTMF:
14252
+ this.onDtmfSent(event.data.tone);
14253
+ break;
14254
+ case BRIDGE_ON_DIRECT_TRANSFER:
14255
+ this.onDirectTransfer(event.data.number);
14256
+ break;
14257
+ case BRIDGE_ON_CREATE_INDIRECT_TRANSFER:
14258
+ this.onCreateIndirectTransfer(event.data.number);
14259
+ break;
14260
+ case BRIDGE_ON_CANCEL_INDIRECT_TRANSFER:
14261
+ this.onCancelIndirectTransfer();
14262
+ break;
14263
+ case BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER:
14264
+ this.onConfirmIndirectTransfer();
14265
+ break;
14266
+ case BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE:
14267
+ this.onIndirectCallMade(event.data.call);
14268
+ break;
14269
+ case BRIDGE_ON_INDIRECT_TRANSFER_DONE:
14270
+ this.onIndirectTransferDone(event.data.call);
14271
+ break;
14272
+ case BRIDGE_ON_START_RECORDING:
14273
+ this.onStartRecording();
14274
+ break;
14275
+ case BRIDGE_ON_STOP_RECORDING:
14276
+ this.onStopRecording();
14277
+ break;
14278
+ default:
14279
+ this.onUnHandledEvent(event);
14280
+ break;
14109
14281
  }
14110
14282
  }
14283
+
14284
+ _sendMessage(type , payload = {}) {
14285
+ if (!this.iframe) {
14286
+ console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
14287
+ return;
14288
+ }
14289
+
14290
+ this.iframe.contentWindow.postMessage({ type, ...payload }, '*');
14291
+ }
14111
14292
  }
14112
14293
 
14113
14294
  var Softphone$1 = new Softphone();
@@ -6967,7 +6967,7 @@ class WebRTCClient extends Emitter {
6967
6967
  }
6968
6968
 
6969
6969
  async _onHeartbeatTimeout() {
6970
- logger.info('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
6970
+ logger.warn('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
6971
6971
 
6972
6972
  if (this.heartbeatTimeoutCb) {
6973
6973
  this.heartbeatTimeoutCb();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wazo/sdk",
3
- "version": "0.38.0",
3
+ "version": "0.38.1",
4
4
  "description": "Wazo's JavaScript Software Development Kit.",
5
5
  "main": "dist/wazo-sdk.js",
6
6
  "author": "Wazo (http://wazo.io)",