@wazo/sdk 0.38.0 → 0.38.3

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 +293 -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 +267 -25
  9. package/esm/simple/Auth.js +267 -25
  10. package/esm/simple/Configuration.js +267 -25
  11. package/esm/simple/Phone.js +267 -25
  12. package/esm/simple/Softphone.js +266 -24
  13. package/esm/simple/index.js +267 -25
  14. package/esm/simple/room/LocalParticipant.js +267 -25
  15. package/esm/simple/room/Participant.js +267 -25
  16. package/esm/simple/room/RemoteParticipant.js +267 -25
  17. package/esm/simple/room/Room.js +267 -25
  18. package/esm/simple/room/SipRoom.js +267 -25
  19. package/esm/simple/room/Stream.js +267 -25
  20. package/esm/simple/room/__tests__/RemoteParticipant.test.js +267 -25
  21. package/esm/simple/utils.js +267 -25
  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 +267 -25
  29. package/lib/simple/Auth.js +267 -25
  30. package/lib/simple/Configuration.js +267 -25
  31. package/lib/simple/Phone.js +267 -25
  32. package/lib/simple/Softphone.js +266 -24
  33. package/lib/simple/index.js +267 -25
  34. package/lib/simple/room/LocalParticipant.js +267 -25
  35. package/lib/simple/room/Participant.js +267 -25
  36. package/lib/simple/room/RemoteParticipant.js +267 -25
  37. package/lib/simple/room/Room.js +267 -25
  38. package/lib/simple/room/SipRoom.js +267 -25
  39. package/lib/simple/room/Stream.js +267 -25
  40. package/lib/simple/room/__tests__/RemoteParticipant.test.js +267 -25
  41. package/lib/simple/utils.js +267 -25
  42. package/lib/web-rtc-client.js +1 -1
  43. package/package.json +1 -1
  44. package/src/simple/Softphone.js +264 -24
  45. package/src/web-rtc-client.js +1 -1
@@ -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,40 +13968,159 @@ 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_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13973
+ const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13974
+ const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
13975
+ const BRIDGE_SEARCH_OPTIONS = 'bridge/BRIDGE_SEARCH_OPTIONS';
13976
+ const BRIDGE_DISPLAY_LINKED_OPTION = 'bridge/DISPLAY_LINKED_OPTION';
13977
+ const BRIDGE_UPDATE_FORM_SCHEMA = 'bridge/BRIDGE_UPDATE_FORM_SCHEMA';
13978
+ const BRIDGE_WAZO_CONTACT_SEARCH = 'bridge/BRIDGE_WAZO_CONTACT_SEARCH';
13979
+ const BRIDGE_ON_AGENT_LOGGED_IN = 'bridge/BRIDGE_ON_AGENT_LOGGED_IN';
13980
+ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13981
+ const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13982
+ const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13983
+ const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13984
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
13985
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
13986
+ const BRIDGE_ON_CALL_REMOTELY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_REMOTELY_ACCEPTED';
13987
+ const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13988
+ const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13989
+ const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
13990
+ const BRIDGE_ON_CALL_UN_MUTED = 'bridge/BRIDGE_ON_CALL_UN_MUTED';
13991
+ const BRIDGE_ON_DTMF = 'bridge/BRIDGE_ON_DTMF';
13992
+ const BRIDGE_ON_DIRECT_TRANSFER = 'bridge/BRIDGE_ON_DIRECT_TRANSFER';
13993
+ const BRIDGE_ON_CREATE_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CREATE_INDIRECT_TRANSFER';
13994
+ const BRIDGE_ON_CANCEL_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CANCEL_INDIRECT_TRANSFER';
13995
+ const BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER';
13996
+ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE';
13997
+ const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13998
+ const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13999
+ const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
14000
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
14001
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
14002
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
14003
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
14004
+
14005
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
14006
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
14007
+
13971
14008
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13972
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
14009
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
13973
14010
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13974
14011
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13975
14012
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14013
+ const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13976
14014
 
13977
14015
  class Softphone {
13978
- url = 'https://softphone.wazo.io';
13979
- width = 500;
13980
- height = 600;
13981
- displayed = false;
13982
- iframe = null;
14016
+
14017
+
14018
+
14019
+
14020
+
14021
+
14022
+
14023
+ // Message waiting for the iframe to be loaded
14024
+
13983
14025
 
13984
14026
  onLinkEnabled(link ) {}
14027
+ onIFrameLoaded() {}
13985
14028
 
13986
- onCallMade(call ) {}
14029
+ onCallLocallyAnswered(call ) {}
14030
+ onCallRemotelyAnswered(call ) {}
14031
+ onOutgoingCallMade(call ) {}
13987
14032
  onCallIncoming(call ) {}
14033
+ onCallRejected(call ) {}
13988
14034
  onCallEnded(call , card , direction , fromExtension ) {}
14035
+
14036
+ onCardSaved(card ) {}
14037
+ onCardCanceled() {}
13989
14038
  onAuthenticated(session ) {}
14039
+ onLoggedOut() {}
14040
+
14041
+ onSearchOptions(fieldId , query ) {
14042
+ this.onOptionsResults(fieldId, []);
14043
+ }
14044
+
14045
+ onDisplayLinkedOption(optionId ) {}
14046
+ onWazoContactSearch(query ) {}
14047
+ onAgentLoggedIn() {}
14048
+ onAgentLoggedOut() {}
14049
+ onAgentPaused() {}
14050
+ onAgentResumed() {}
14051
+ onLanguageChanged(language ) {}
14052
+ onCallHeld() {}
14053
+ onCallResumed() {}
14054
+ onCallMuted() {}
14055
+ onCallUnMuted() {}
14056
+ onDtmfSent(tone ) {}
14057
+ onDirectTransfer(number ) {}
14058
+ onCreateIndirectTransfer(number ) {}
14059
+ onCancelIndirectTransfer() {}
14060
+ onConfirmIndirectTransfer() {}
14061
+ onIndirectCallMade(call ) {}
14062
+ onIndirectTransferDone(call ) {}
14063
+ onStartRecording() {}
14064
+ onStopRecording() {}
14065
+ onUnHandledEvent(event ) {}
14066
+
14067
+ init({
14068
+ url,
14069
+ width,
14070
+ height,
14071
+ server,
14072
+ port,
14073
+ language,
14074
+ wrapUpDuration,
14075
+ enableAgent = true,
14076
+ tenantId,
14077
+ debug = false,
14078
+ } = {}) {
14079
+ this.url = url || 'https://softphone.wazo.io';
14080
+ this.width = width || 500;
14081
+ this.height = height || 600;
14082
+ this.displayed = false;
14083
+ this.iframeLoaded = false;
14084
+
14085
+ this.iframeLoaded = false;
14086
+ this._pendingMessages = [];
14087
+ window.addEventListener('message', this._onMessage.bind(this), false);
14088
+
14089
+ if (!server) {
14090
+ // eslint-disable-next-line no-param-reassign
14091
+ server = 'stack.dev.wazo.io';
14092
+ }
13990
14093
 
13991
- init(url , width , height ) {
13992
- if (url) {
13993
- this.url = url;
14094
+ const config = { server };
14095
+ if (language) {
14096
+ config.language = language;
14097
+ }
14098
+ if (port) {
14099
+ config.port = port;
13994
14100
  }
13995
- if (width) {
13996
- this.width = width;
14101
+ if (tenantId) {
14102
+ config.tenantId = tenantId;
13997
14103
  }
13998
- if (height) {
13999
- this.height = height;
14104
+ if (wrapUpDuration) {
14105
+ config.wrapUpDuration = wrapUpDuration;
14000
14106
  }
14001
14107
 
14002
- window.addEventListener('message', this._onMessage.bind(this), false);
14108
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
14003
14109
 
14004
- this._createIframe();
14110
+ if (enableAgent) {
14111
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
14112
+ }
14113
+
14114
+ if (debug) {
14115
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
14116
+ }
14117
+
14118
+ this._createIframe(() => {
14119
+ this.iframeLoaded = true;
14120
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
14121
+
14122
+ this.onIFrameLoaded();
14123
+ });
14005
14124
  }
14006
14125
 
14007
14126
  parseLinks() {
@@ -14017,9 +14136,7 @@ class Softphone {
14017
14136
  makeCall(number ) {
14018
14137
  this.displaySoftphone();
14019
14138
 
14020
- if (this.iframe) {
14021
- this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
14022
- }
14139
+ this._sendMessage(SDK_CLICK_TO_CALL, { number });
14023
14140
  }
14024
14141
 
14025
14142
  toggleSoftphoneDisplay() {
@@ -14028,8 +14145,6 @@ class Softphone {
14028
14145
  } else {
14029
14146
  this.displaySoftphone();
14030
14147
  }
14031
-
14032
- this.displayed = !this.displayed;
14033
14148
  }
14034
14149
 
14035
14150
  displaySoftphone() {
@@ -14040,15 +14155,42 @@ class Softphone {
14040
14155
  if (this.iframe) {
14041
14156
  this.iframe.style.display = 'block';
14042
14157
  }
14158
+
14159
+ this.displayed = true;
14043
14160
  }
14044
14161
 
14045
14162
  hideSoftphone() {
14046
14163
  if (this.iframe) {
14047
14164
  this.iframe.style.display = 'none';
14048
14165
  }
14166
+ this.displayed = false;
14167
+ }
14168
+
14169
+ optionsFetched(fieldId , options ) {
14170
+ this._sendMessage(BRIDGE_OPTIONS_FETCHED, { fieldId, options });
14171
+ }
14172
+
14173
+ onOptionsResults(fieldId , options ) {
14174
+ this._sendMessage(BRIDGE_OPTIONS_FOUND, { fieldId, options });
14175
+ }
14176
+
14177
+ setFormSchema(schema , uiSchema ) {
14178
+ this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14179
+ }
14180
+
14181
+ setCardValue(field , value ) {
14182
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
14183
+ }
14184
+
14185
+ injectCss(css ) {
14186
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
14049
14187
  }
14050
14188
 
14051
- _createIframe() {
14189
+ customizeAppearance(themes , translations , assets ) {
14190
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
14191
+ }
14192
+
14193
+ _createIframe(cb = () => {}) {
14052
14194
  this.iframe = document.createElement('iframe');
14053
14195
  // $FlowFixMe
14054
14196
  this.iframe.width = this.width;
@@ -14060,10 +14202,13 @@ class Softphone {
14060
14202
  this.iframe.style.left = '0';
14061
14203
  this.iframe.style.bottom = '0';
14062
14204
  this.iframe.style.border = '1px solid #aaa';
14205
+ this.iframe.style.backgroundColor = 'white';
14063
14206
  this.iframe.src = this.url;
14064
14207
  this.iframe.style.display = 'none';
14065
14208
  this.iframe.id = 'wazo-softphone';
14066
14209
 
14210
+ this.iframe.onload = cb;
14211
+
14067
14212
  // $FlowFixMe
14068
14213
  document.body.appendChild(this.iframe);
14069
14214
  }
@@ -14090,8 +14235,8 @@ class Softphone {
14090
14235
  }
14091
14236
 
14092
14237
  switch (event.data.type) {
14093
- case SDK_ON_CALL_MADE:
14094
- this.onCallMade(event.data.callSession);
14238
+ case SDK_ON_OUTGOING_CALL_MADE:
14239
+ this.onOutgoingCallMade(event.data.callSession);
14095
14240
  break;
14096
14241
  case SDK_CALL_ENDED: {
14097
14242
  const { callSession, content, direction, userExtension } = event.data;
@@ -14106,8 +14251,105 @@ class Softphone {
14106
14251
  this._onAuthenticated(event.data.session);
14107
14252
  this.onAuthenticated(event.data.session);
14108
14253
  break;
14254
+ case SDK_LOGGED_OUT:
14255
+ this.onLoggedOut();
14256
+ break;
14257
+ case BRIDGE_CREATE_OR_UPDATE_CARD: {
14258
+ const { content } = event.data;
14259
+ this.onCardSaved(content);
14260
+ break;
14261
+ }
14262
+ case BRIDGE_SEARCH_OPTIONS: {
14263
+ const { fieldId, query } = event.data;
14264
+ this.onSearchOptions(fieldId, query);
14265
+ break;
14266
+ }
14267
+ case BRIDGE_DISPLAY_LINKED_OPTION:
14268
+ this.onDisplayLinkedOption(event.data.linkedOptionId);
14269
+ break;
14270
+ case BRIDGE_WAZO_CONTACT_SEARCH:
14271
+ this.onWazoContactSearch(event.data.query);
14272
+ break;
14273
+ case BRIDGE_ON_AGENT_LOGGED_IN:
14274
+ this.onAgentLoggedIn();
14275
+ break;
14276
+ case BRIDGE_ON_AGENT_LOGGED_OUT:
14277
+ this.onAgentLoggedOut();
14278
+ break;
14279
+ case BRIDGE_ON_AGENT_PAUSED:
14280
+ this.onAgentPaused();
14281
+ break;
14282
+ case BRIDGE_ON_AGENT_RESUMED:
14283
+ this.onAgentResumed();
14284
+ break;
14285
+ case BRIDGE_ON_LANGUAGE_CHANGED:
14286
+ this.onLanguageChanged(event.data.language);
14287
+ break;
14288
+ case BRIDGE_ON_CALL_HELD:
14289
+ this.onCallHeld();
14290
+ break;
14291
+ case BRIDGE_ON_CALL_RESUMED:
14292
+ this.onCallResumed();
14293
+ break;
14294
+ case BRIDGE_ON_CALL_MUTED:
14295
+ this.onCallMuted();
14296
+ break;
14297
+ case BRIDGE_ON_CALL_UN_MUTED:
14298
+ this.onCallUnMuted();
14299
+ break;
14300
+ case BRIDGE_ON_DTMF:
14301
+ this.onDtmfSent(event.data.tone);
14302
+ break;
14303
+ case BRIDGE_ON_DIRECT_TRANSFER:
14304
+ this.onDirectTransfer(event.data.number);
14305
+ break;
14306
+ case BRIDGE_ON_CREATE_INDIRECT_TRANSFER:
14307
+ this.onCreateIndirectTransfer(event.data.number);
14308
+ break;
14309
+ case BRIDGE_ON_CANCEL_INDIRECT_TRANSFER:
14310
+ this.onCancelIndirectTransfer();
14311
+ break;
14312
+ case BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER:
14313
+ this.onConfirmIndirectTransfer();
14314
+ break;
14315
+ case BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE:
14316
+ this.onIndirectCallMade(event.data.call);
14317
+ break;
14318
+ case BRIDGE_ON_INDIRECT_TRANSFER_DONE:
14319
+ this.onIndirectTransferDone(event.data.call);
14320
+ break;
14321
+ case BRIDGE_ON_START_RECORDING:
14322
+ this.onStartRecording();
14323
+ break;
14324
+ case BRIDGE_ON_STOP_RECORDING:
14325
+ this.onStopRecording();
14326
+ break;
14327
+ case BRIDGE_ON_CARD_CANCELED:
14328
+ this.onCardCanceled();
14329
+ break;
14330
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
14331
+ this.onCallLocallyAnswered(event.data.call);
14332
+ break;
14333
+ case BRIDGE_ON_CALL_REJECTED:
14334
+ this.onCallRejected(event.data.call);
14335
+ break;
14336
+ case BRIDGE_ON_CALL_REMOTELY_ACCEPTED:
14337
+ this.onCallRemotelyAnswered(event.data.call);
14338
+ break;
14339
+ default:
14340
+ this.onUnHandledEvent(event);
14341
+ break;
14109
14342
  }
14110
14343
  }
14344
+
14345
+ _sendMessage(type , payload = {}) {
14346
+ if (!this.iframe || !this.iframeLoaded) {
14347
+ this._pendingMessages.push([type, payload]);
14348
+ return;
14349
+ }
14350
+
14351
+ this.iframe.contentWindow.postMessage({ type, ...payload }, '*');
14352
+ }
14111
14353
  }
14112
14354
 
14113
14355
  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.3",
4
4
  "description": "Wazo's JavaScript Software Development Kit.",
5
5
  "main": "dist/wazo-sdk.js",
6
6
  "author": "Wazo (http://wazo.io)",