@wazo/sdk 0.37.43 → 0.38.2

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 (46) hide show
  1. package/README.md +246 -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 +361 -1
  9. package/esm/simple/Auth.js +361 -1
  10. package/esm/simple/Configuration.js +361 -1
  11. package/esm/simple/Phone.js +361 -1
  12. package/esm/simple/Softphone.js +360 -0
  13. package/esm/simple/index.js +361 -1
  14. package/esm/simple/room/LocalParticipant.js +361 -1
  15. package/esm/simple/room/Participant.js +361 -1
  16. package/esm/simple/room/RemoteParticipant.js +361 -1
  17. package/esm/simple/room/Room.js +361 -1
  18. package/esm/simple/room/SipRoom.js +361 -1
  19. package/esm/simple/room/Stream.js +361 -1
  20. package/esm/simple/room/__tests__/RemoteParticipant.test.js +361 -1
  21. package/esm/simple/utils.js +361 -1
  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 +361 -1
  29. package/lib/simple/Auth.js +361 -1
  30. package/lib/simple/Configuration.js +361 -1
  31. package/lib/simple/Phone.js +361 -1
  32. package/lib/simple/Softphone.js +362 -0
  33. package/lib/simple/index.js +361 -1
  34. package/lib/simple/room/LocalParticipant.js +361 -1
  35. package/lib/simple/room/Participant.js +361 -1
  36. package/lib/simple/room/RemoteParticipant.js +361 -1
  37. package/lib/simple/room/Room.js +361 -1
  38. package/lib/simple/room/SipRoom.js +361 -1
  39. package/lib/simple/room/Stream.js +361 -1
  40. package/lib/simple/room/__tests__/RemoteParticipant.test.js +361 -1
  41. package/lib/simple/utils.js +361 -1
  42. package/lib/web-rtc-client.js +1 -1
  43. package/package.json +1 -1
  44. package/src/simple/Softphone.js +358 -0
  45. package/src/simple/index.js +2 -0
  46. package/src/web-rtc-client.js +1 -1
package/lib/index.js CHANGED
@@ -7858,7 +7858,7 @@ class WebRTCClient extends Emitter {
7858
7858
  }
7859
7859
 
7860
7860
  async _onHeartbeatTimeout() {
7861
- logger$9.info('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
7861
+ logger$9.warn('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
7862
7862
 
7863
7863
  if (this.heartbeatTimeoutCb) {
7864
7864
  this.heartbeatTimeoutCb();
@@ -14118,6 +14118,365 @@ const createLocalVideoStream = async (options ) => createLocalStream('vid
14118
14118
 
14119
14119
  const createLocalAudioStream = async (options ) => createLocalStream('audio', options);
14120
14120
 
14121
+ //
14122
+ /* eslint-disable no-unused-vars */
14123
+ /* global window, document */
14124
+ const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
14125
+ const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
14126
+ const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
14127
+ const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
14128
+ const BRIDGE_SEARCH_OPTIONS = 'bridge/BRIDGE_SEARCH_OPTIONS';
14129
+ const BRIDGE_DISPLAY_LINKED_OPTION = 'bridge/DISPLAY_LINKED_OPTION';
14130
+ const BRIDGE_UPDATE_FORM_SCHEMA = 'bridge/BRIDGE_UPDATE_FORM_SCHEMA';
14131
+ const BRIDGE_WAZO_CONTACT_SEARCH = 'bridge/BRIDGE_WAZO_CONTACT_SEARCH';
14132
+ const BRIDGE_ON_AGENT_LOGGED_IN = 'bridge/BRIDGE_ON_AGENT_LOGGED_IN';
14133
+ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
14134
+ const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
14135
+ const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
14136
+ const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
14137
+ const BRIDGE_ON_CALL_ANSWERED = 'bridge/BRIDGE_ON_CALL_ANSWERED';
14138
+ const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
14139
+ const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
14140
+ const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
14141
+ const BRIDGE_ON_CALL_UN_MUTED = 'bridge/BRIDGE_ON_CALL_UN_MUTED';
14142
+ const BRIDGE_ON_DTMF = 'bridge/BRIDGE_ON_DTMF';
14143
+ const BRIDGE_ON_DIRECT_TRANSFER = 'bridge/BRIDGE_ON_DIRECT_TRANSFER';
14144
+ const BRIDGE_ON_CREATE_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CREATE_INDIRECT_TRANSFER';
14145
+ const BRIDGE_ON_CANCEL_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CANCEL_INDIRECT_TRANSFER';
14146
+ const BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER';
14147
+ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE';
14148
+ const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
14149
+ const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
14150
+ const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
14151
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
14152
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
14153
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
14154
+
14155
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
14156
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
14157
+
14158
+ const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
14159
+ const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
14160
+ const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
14161
+ const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
14162
+ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14163
+ const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
14164
+
14165
+ class Softphone {
14166
+
14167
+
14168
+
14169
+
14170
+
14171
+
14172
+
14173
+ // Message waiting for the iframe to be loaded
14174
+
14175
+
14176
+ onLinkEnabled(link ) {}
14177
+ onIFrameLoaded() {}
14178
+
14179
+ onCallAnswered() {}
14180
+ onCallMade(call ) {}
14181
+ onCallIncoming(call ) {}
14182
+ onCallEnded(call , card , direction , fromExtension ) {}
14183
+ onCardSaved(card ) {}
14184
+ onCardCanceled() {}
14185
+ onAuthenticated(session ) {}
14186
+ onLoggedOut() {}
14187
+
14188
+ onSearchOptions(fieldId , query ) {
14189
+ this.onOptionsResults(fieldId, []);
14190
+ }
14191
+
14192
+ onDisplayLinkedOption(optionId ) {}
14193
+ onWazoContactSearch(query ) {}
14194
+ onAgentLoggedIn() {}
14195
+ onAgentLoggedOut() {}
14196
+ onAgentPaused() {}
14197
+ onAgentResumed() {}
14198
+ onLanguageChanged(language ) {}
14199
+ onCallHeld() {}
14200
+ onCallResumed() {}
14201
+ onCallMuted() {}
14202
+ onCallUnMuted() {}
14203
+ onDtmfSent(tone ) {}
14204
+ onDirectTransfer(number ) {}
14205
+ onCreateIndirectTransfer(number ) {}
14206
+ onCancelIndirectTransfer() {}
14207
+ onConfirmIndirectTransfer() {}
14208
+ onIndirectCallMade(call ) {}
14209
+ onIndirectTransferDone(call ) {}
14210
+ onStartRecording() {}
14211
+ onStopRecording() {}
14212
+ onUnHandledEvent(event ) {}
14213
+
14214
+ init({ url, width, height, server, port, language, wrapUpDuration, enableAgent = true } = {}) {
14215
+ this.url = url || 'https://softphone.wazo.io';
14216
+ this.width = width || 500;
14217
+ this.height = height || 600;
14218
+ this.displayed = false;
14219
+ this.iframeLoaded = false;
14220
+
14221
+ this.iframeLoaded = false;
14222
+ this._pendingMessages = [];
14223
+ window.addEventListener('message', this._onMessage.bind(this), false);
14224
+
14225
+ if (!server) {
14226
+ // eslint-disable-next-line no-param-reassign
14227
+ server = 'stack.dev.wazo.io';
14228
+ }
14229
+
14230
+ const config = { server };
14231
+ if (language) {
14232
+ config.language = language;
14233
+ }
14234
+ if (port) {
14235
+ config.port = port;
14236
+ }
14237
+ if (wrapUpDuration) {
14238
+ config.wrapUpDuration = wrapUpDuration;
14239
+ }
14240
+
14241
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
14242
+
14243
+ if (enableAgent) {
14244
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
14245
+ }
14246
+
14247
+ this._createIframe(() => {
14248
+ this.iframeLoaded = true;
14249
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
14250
+
14251
+ this.onIFrameLoaded();
14252
+ });
14253
+ }
14254
+
14255
+ parseLinks() {
14256
+ const links = this._getLinks();
14257
+
14258
+ links.forEach(link => {
14259
+ link.setAttribute('data-wazo-parsed', true);
14260
+ link.addEventListener('click', this._onLinkClick.bind(this));
14261
+ this.onLinkEnabled(link);
14262
+ });
14263
+ }
14264
+
14265
+ makeCall(number ) {
14266
+ this.displaySoftphone();
14267
+
14268
+ this._sendMessage(SDK_CLICK_TO_CALL, { number });
14269
+ }
14270
+
14271
+ toggleSoftphoneDisplay() {
14272
+ if (this.displayed) {
14273
+ this.hideSoftphone();
14274
+ } else {
14275
+ this.displaySoftphone();
14276
+ }
14277
+ }
14278
+
14279
+ displaySoftphone() {
14280
+ if (!this.iframe) {
14281
+ this._createIframe();
14282
+ }
14283
+
14284
+ if (this.iframe) {
14285
+ this.iframe.style.display = 'block';
14286
+ }
14287
+
14288
+ this.displayed = true;
14289
+ }
14290
+
14291
+ hideSoftphone() {
14292
+ if (this.iframe) {
14293
+ this.iframe.style.display = 'none';
14294
+ }
14295
+ this.displayed = false;
14296
+ }
14297
+
14298
+ optionsFetched(fieldId , options ) {
14299
+ this._sendMessage(BRIDGE_OPTIONS_FETCHED, { fieldId, options });
14300
+ }
14301
+
14302
+ onOptionsResults(fieldId , options ) {
14303
+ this._sendMessage(BRIDGE_OPTIONS_FOUND, { fieldId, options });
14304
+ }
14305
+
14306
+ setFormSchema(schema , uiSchema ) {
14307
+ this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14308
+ }
14309
+
14310
+ setCardValue(field , value ) {
14311
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
14312
+ }
14313
+
14314
+ injectCss(css ) {
14315
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
14316
+ }
14317
+
14318
+ customizeAppearance(themes , translations , assets ) {
14319
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
14320
+ }
14321
+
14322
+ _createIframe(cb = () => {}) {
14323
+ this.iframe = document.createElement('iframe');
14324
+ // $FlowFixMe
14325
+ this.iframe.width = this.width;
14326
+ // $FlowFixMe
14327
+ this.iframe.height = this.height;
14328
+ // $FlowFixMe
14329
+ this.iframe.allow = 'camera *; microphone *; autoplay *; display-capture *';
14330
+ this.iframe.style.position = 'absolute';
14331
+ this.iframe.style.left = '0';
14332
+ this.iframe.style.bottom = '0';
14333
+ this.iframe.style.border = '1px solid #aaa';
14334
+ this.iframe.style.backgroundColor = 'white';
14335
+ this.iframe.src = this.url;
14336
+ this.iframe.style.display = 'none';
14337
+ this.iframe.id = 'wazo-softphone';
14338
+
14339
+ this.iframe.onload = cb;
14340
+
14341
+ // $FlowFixMe
14342
+ document.body.appendChild(this.iframe);
14343
+ }
14344
+
14345
+ _getLinks() {
14346
+ return [].slice.call(document.querySelectorAll('a:not([data-wazo-parsed])'), 0)
14347
+ .filter(link => link.href.indexOf('tel:') === 0 || link.href.indexOf('callto:') === 0);
14348
+ }
14349
+
14350
+ _onLinkClick(e ) {
14351
+ e.preventDefault();
14352
+ const number = e.target.href.split(':')[1];
14353
+
14354
+ this.makeCall(number);
14355
+ }
14356
+
14357
+ _onAuthenticated() {
14358
+ this.parseLinks();
14359
+ }
14360
+
14361
+ _onMessage(event ) {
14362
+ if (!event.data) {
14363
+ return;
14364
+ }
14365
+
14366
+ switch (event.data.type) {
14367
+ case SDK_ON_CALL_MADE:
14368
+ this.onCallMade(event.data.callSession);
14369
+ break;
14370
+ case SDK_CALL_ENDED: {
14371
+ const { callSession, content, direction, userExtension } = event.data;
14372
+ this.onCallEnded(callSession, content, direction, userExtension);
14373
+ break;
14374
+ }
14375
+ case SDK_CALL_INCOMING:
14376
+ this.onCallIncoming(event.data.callSession);
14377
+ break;
14378
+ case SDK_AUTHENTICATED:
14379
+ // $FlowFixMe
14380
+ this._onAuthenticated(event.data.session);
14381
+ this.onAuthenticated(event.data.session);
14382
+ break;
14383
+ case SDK_LOGGED_OUT:
14384
+ this.onLoggedOut();
14385
+ break;
14386
+ case BRIDGE_CREATE_OR_UPDATE_CARD: {
14387
+ const { content } = event.data;
14388
+ this.onCardSaved(content);
14389
+ break;
14390
+ }
14391
+ case BRIDGE_SEARCH_OPTIONS: {
14392
+ const { fieldId, query } = event.data;
14393
+ this.onSearchOptions(fieldId, query);
14394
+ break;
14395
+ }
14396
+ case BRIDGE_DISPLAY_LINKED_OPTION:
14397
+ this.onDisplayLinkedOption(event.data.linkedOptionId);
14398
+ break;
14399
+ case BRIDGE_WAZO_CONTACT_SEARCH:
14400
+ this.onWazoContactSearch(event.data.query);
14401
+ break;
14402
+ case BRIDGE_ON_AGENT_LOGGED_IN:
14403
+ this.onAgentLoggedIn();
14404
+ break;
14405
+ case BRIDGE_ON_AGENT_LOGGED_OUT:
14406
+ this.onAgentLoggedOut();
14407
+ break;
14408
+ case BRIDGE_ON_AGENT_PAUSED:
14409
+ this.onAgentPaused();
14410
+ break;
14411
+ case BRIDGE_ON_AGENT_RESUMED:
14412
+ this.onAgentResumed();
14413
+ break;
14414
+ case BRIDGE_ON_LANGUAGE_CHANGED:
14415
+ this.onLanguageChanged(event.data.language);
14416
+ break;
14417
+ case BRIDGE_ON_CALL_HELD:
14418
+ this.onCallHeld();
14419
+ break;
14420
+ case BRIDGE_ON_CALL_RESUMED:
14421
+ this.onCallResumed();
14422
+ break;
14423
+ case BRIDGE_ON_CALL_MUTED:
14424
+ this.onCallMuted();
14425
+ break;
14426
+ case BRIDGE_ON_CALL_UN_MUTED:
14427
+ this.onCallUnMuted();
14428
+ break;
14429
+ case BRIDGE_ON_DTMF:
14430
+ this.onDtmfSent(event.data.tone);
14431
+ break;
14432
+ case BRIDGE_ON_DIRECT_TRANSFER:
14433
+ this.onDirectTransfer(event.data.number);
14434
+ break;
14435
+ case BRIDGE_ON_CREATE_INDIRECT_TRANSFER:
14436
+ this.onCreateIndirectTransfer(event.data.number);
14437
+ break;
14438
+ case BRIDGE_ON_CANCEL_INDIRECT_TRANSFER:
14439
+ this.onCancelIndirectTransfer();
14440
+ break;
14441
+ case BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER:
14442
+ this.onConfirmIndirectTransfer();
14443
+ break;
14444
+ case BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE:
14445
+ this.onIndirectCallMade(event.data.call);
14446
+ break;
14447
+ case BRIDGE_ON_INDIRECT_TRANSFER_DONE:
14448
+ this.onIndirectTransferDone(event.data.call);
14449
+ break;
14450
+ case BRIDGE_ON_START_RECORDING:
14451
+ this.onStartRecording();
14452
+ break;
14453
+ case BRIDGE_ON_STOP_RECORDING:
14454
+ this.onStopRecording();
14455
+ break;
14456
+ case BRIDGE_ON_CARD_CANCELED:
14457
+ this.onCardCanceled();
14458
+ break;
14459
+ case BRIDGE_ON_CALL_ANSWERED:
14460
+ this.onCallAnswered();
14461
+ break;
14462
+ default:
14463
+ this.onUnHandledEvent(event);
14464
+ break;
14465
+ }
14466
+ }
14467
+
14468
+ _sendMessage(type , payload = {}) {
14469
+ if (!this.iframe || !this.iframeLoaded) {
14470
+ this._pendingMessages.push([type, payload]);
14471
+ return;
14472
+ }
14473
+
14474
+ this.iframe.contentWindow.postMessage({ type, ...payload }, '*');
14475
+ }
14476
+ }
14477
+
14478
+ var Softphone$1 = new Softphone();
14479
+
14121
14480
  /* global window */
14122
14481
 
14123
14482
  const Wazo = {
@@ -14138,6 +14497,7 @@ const Wazo = {
14138
14497
  loggerFor: IssueReporter$1.loggerFor.bind(IssueReporter$1),
14139
14498
  Features: Features$1,
14140
14499
  Checker,
14500
+ Softphone: Softphone$1,
14141
14501
 
14142
14502
  // Domain
14143
14503
  domain: {