@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
@@ -1,40 +1,159 @@
1
1
  // @flow
2
2
  /* eslint-disable no-unused-vars */
3
3
  /* global window, document */
4
+ const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
5
+ const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
6
+ const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
7
+ const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
8
+ const BRIDGE_SEARCH_OPTIONS = 'bridge/BRIDGE_SEARCH_OPTIONS';
9
+ const BRIDGE_DISPLAY_LINKED_OPTION = 'bridge/DISPLAY_LINKED_OPTION';
10
+ const BRIDGE_UPDATE_FORM_SCHEMA = 'bridge/BRIDGE_UPDATE_FORM_SCHEMA';
11
+ const BRIDGE_WAZO_CONTACT_SEARCH = 'bridge/BRIDGE_WAZO_CONTACT_SEARCH';
12
+ const BRIDGE_ON_AGENT_LOGGED_IN = 'bridge/BRIDGE_ON_AGENT_LOGGED_IN';
13
+ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
14
+ const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
15
+ const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
16
+ const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
17
+ const BRIDGE_ON_CALL_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
18
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
19
+ const BRIDGE_ON_CALL_REMOTELY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_REMOTELY_ACCEPTED';
20
+ const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
21
+ const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
22
+ const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
23
+ const BRIDGE_ON_CALL_UN_MUTED = 'bridge/BRIDGE_ON_CALL_UN_MUTED';
24
+ const BRIDGE_ON_DTMF = 'bridge/BRIDGE_ON_DTMF';
25
+ const BRIDGE_ON_DIRECT_TRANSFER = 'bridge/BRIDGE_ON_DIRECT_TRANSFER';
26
+ const BRIDGE_ON_CREATE_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CREATE_INDIRECT_TRANSFER';
27
+ const BRIDGE_ON_CANCEL_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CANCEL_INDIRECT_TRANSFER';
28
+ const BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER';
29
+ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE';
30
+ const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
31
+ const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
32
+ const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
33
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
34
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
35
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
36
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
37
+
38
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
39
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
40
+
4
41
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
5
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
42
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
6
43
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
7
44
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
8
45
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
46
+ const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
9
47
 
10
48
  class Softphone {
11
- url: string = 'https://softphone.wazo.io';
12
- width: number = 500;
13
- height: number = 600;
14
- displayed: boolean = false;
15
- iframe: ?Object = null;
49
+ url: string;
50
+ width: number;
51
+ height: number;
52
+ displayed: boolean;
53
+ iframe: ?Object;
54
+ iframeLoaded: boolean;
55
+
56
+ // Message waiting for the iframe to be loaded
57
+ _pendingMessages: Object[];
16
58
 
17
59
  onLinkEnabled(link: Object) {}
60
+ onIFrameLoaded() {}
18
61
 
19
- onCallMade(call: Object) {}
62
+ onCallLocallyAnswered(call: Object) {}
63
+ onCallRemotelyAnswered(call: Object) {}
64
+ onOutgoingCallMade(call: Object) {}
20
65
  onCallIncoming(call: Object) {}
66
+ onCallRejected(call: Object) {}
21
67
  onCallEnded(call: Object, card: Object, direction: string, fromExtension: string) {}
68
+
69
+ onCardSaved(card: Object) {}
70
+ onCardCanceled() {}
22
71
  onAuthenticated(session: Object) {}
72
+ onLoggedOut() {}
73
+
74
+ onSearchOptions(fieldId: string, query: string) {
75
+ this.onOptionsResults(fieldId, []);
76
+ }
77
+
78
+ onDisplayLinkedOption(optionId: string) {}
79
+ onWazoContactSearch(query: string) {}
80
+ onAgentLoggedIn() {}
81
+ onAgentLoggedOut() {}
82
+ onAgentPaused() {}
83
+ onAgentResumed() {}
84
+ onLanguageChanged(language: string) {}
85
+ onCallHeld() {}
86
+ onCallResumed() {}
87
+ onCallMuted() {}
88
+ onCallUnMuted() {}
89
+ onDtmfSent(tone: string) {}
90
+ onDirectTransfer(number: string) {}
91
+ onCreateIndirectTransfer(number: string) {}
92
+ onCancelIndirectTransfer() {}
93
+ onConfirmIndirectTransfer() {}
94
+ onIndirectCallMade(call: Object) {}
95
+ onIndirectTransferDone(call: Object) {}
96
+ onStartRecording() {}
97
+ onStopRecording() {}
98
+ onUnHandledEvent(event: Object) {}
99
+
100
+ init({
101
+ url,
102
+ width,
103
+ height,
104
+ server,
105
+ port,
106
+ language,
107
+ wrapUpDuration,
108
+ enableAgent = true,
109
+ tenantId,
110
+ debug = false,
111
+ }: Object = {}) {
112
+ this.url = url || 'https://softphone.wazo.io';
113
+ this.width = width || 500;
114
+ this.height = height || 600;
115
+ this.displayed = false;
116
+ this.iframeLoaded = false;
117
+
118
+ this.iframeLoaded = false;
119
+ this._pendingMessages = [];
120
+ window.addEventListener('message', this._onMessage.bind(this), false);
121
+
122
+ if (!server) {
123
+ // eslint-disable-next-line no-param-reassign
124
+ server = 'stack.dev.wazo.io';
125
+ }
23
126
 
24
- init(url: string, width: number, height: number) {
25
- if (url) {
26
- this.url = url;
127
+ const config: Object = { server };
128
+ if (language) {
129
+ config.language = language;
27
130
  }
28
- if (width) {
29
- this.width = width;
131
+ if (port) {
132
+ config.port = port;
30
133
  }
31
- if (height) {
32
- this.height = height;
134
+ if (tenantId) {
135
+ config.tenantId = tenantId;
136
+ }
137
+ if (wrapUpDuration) {
138
+ config.wrapUpDuration = wrapUpDuration;
33
139
  }
34
140
 
35
- window.addEventListener('message', this._onMessage.bind(this), false);
141
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
142
+
143
+ if (enableAgent) {
144
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
145
+ }
146
+
147
+ if (debug) {
148
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
149
+ }
36
150
 
37
- this._createIframe();
151
+ this._createIframe(() => {
152
+ this.iframeLoaded = true;
153
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
154
+
155
+ this.onIFrameLoaded();
156
+ });
38
157
  }
39
158
 
40
159
  parseLinks() {
@@ -50,9 +169,7 @@ class Softphone {
50
169
  makeCall(number: string) {
51
170
  this.displaySoftphone();
52
171
 
53
- if (this.iframe) {
54
- this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
55
- }
172
+ this._sendMessage(SDK_CLICK_TO_CALL, { number });
56
173
  }
57
174
 
58
175
  toggleSoftphoneDisplay() {
@@ -61,8 +178,6 @@ class Softphone {
61
178
  } else {
62
179
  this.displaySoftphone();
63
180
  }
64
-
65
- this.displayed = !this.displayed;
66
181
  }
67
182
 
68
183
  displaySoftphone() {
@@ -73,15 +188,42 @@ class Softphone {
73
188
  if (this.iframe) {
74
189
  this.iframe.style.display = 'block';
75
190
  }
191
+
192
+ this.displayed = true;
76
193
  }
77
194
 
78
195
  hideSoftphone() {
79
196
  if (this.iframe) {
80
197
  this.iframe.style.display = 'none';
81
198
  }
199
+ this.displayed = false;
200
+ }
201
+
202
+ optionsFetched(fieldId: string, options: any[]) {
203
+ this._sendMessage(BRIDGE_OPTIONS_FETCHED, { fieldId, options });
204
+ }
205
+
206
+ onOptionsResults(fieldId: string, options: any[]) {
207
+ this._sendMessage(BRIDGE_OPTIONS_FOUND, { fieldId, options });
208
+ }
209
+
210
+ setFormSchema(schema: Object, uiSchema: Object) {
211
+ this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
212
+ }
213
+
214
+ setCardValue(field: string, value: any) {
215
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
216
+ }
217
+
218
+ injectCss(css: string) {
219
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
220
+ }
221
+
222
+ customizeAppearance(themes: Object, translations: Object, assets: Object) {
223
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
82
224
  }
83
225
 
84
- _createIframe() {
226
+ _createIframe(cb: Function = () => {}) {
85
227
  this.iframe = document.createElement('iframe');
86
228
  // $FlowFixMe
87
229
  this.iframe.width = this.width;
@@ -93,10 +235,13 @@ class Softphone {
93
235
  this.iframe.style.left = '0';
94
236
  this.iframe.style.bottom = '0';
95
237
  this.iframe.style.border = '1px solid #aaa';
238
+ this.iframe.style.backgroundColor = 'white';
96
239
  this.iframe.src = this.url;
97
240
  this.iframe.style.display = 'none';
98
241
  this.iframe.id = 'wazo-softphone';
99
242
 
243
+ this.iframe.onload = cb;
244
+
100
245
  // $FlowFixMe
101
246
  document.body.appendChild(this.iframe);
102
247
  }
@@ -123,8 +268,8 @@ class Softphone {
123
268
  }
124
269
 
125
270
  switch (event.data.type) {
126
- case SDK_ON_CALL_MADE:
127
- this.onCallMade(event.data.callSession);
271
+ case SDK_ON_OUTGOING_CALL_MADE:
272
+ this.onOutgoingCallMade(event.data.callSession);
128
273
  break;
129
274
  case SDK_CALL_ENDED: {
130
275
  const { callSession, content, direction, userExtension } = event.data;
@@ -139,10 +284,105 @@ class Softphone {
139
284
  this._onAuthenticated(event.data.session);
140
285
  this.onAuthenticated(event.data.session);
141
286
  break;
287
+ case SDK_LOGGED_OUT:
288
+ this.onLoggedOut();
289
+ break;
290
+ case BRIDGE_CREATE_OR_UPDATE_CARD: {
291
+ const { content } = event.data;
292
+ this.onCardSaved(content);
293
+ break;
294
+ }
295
+ case BRIDGE_SEARCH_OPTIONS: {
296
+ const { fieldId, query } = event.data;
297
+ this.onSearchOptions(fieldId, query);
298
+ break;
299
+ }
300
+ case BRIDGE_DISPLAY_LINKED_OPTION:
301
+ this.onDisplayLinkedOption(event.data.linkedOptionId);
302
+ break;
303
+ case BRIDGE_WAZO_CONTACT_SEARCH:
304
+ this.onWazoContactSearch(event.data.query);
305
+ break;
306
+ case BRIDGE_ON_AGENT_LOGGED_IN:
307
+ this.onAgentLoggedIn();
308
+ break;
309
+ case BRIDGE_ON_AGENT_LOGGED_OUT:
310
+ this.onAgentLoggedOut();
311
+ break;
312
+ case BRIDGE_ON_AGENT_PAUSED:
313
+ this.onAgentPaused();
314
+ break;
315
+ case BRIDGE_ON_AGENT_RESUMED:
316
+ this.onAgentResumed();
317
+ break;
318
+ case BRIDGE_ON_LANGUAGE_CHANGED:
319
+ this.onLanguageChanged(event.data.language);
320
+ break;
321
+ case BRIDGE_ON_CALL_HELD:
322
+ this.onCallHeld();
323
+ break;
324
+ case BRIDGE_ON_CALL_RESUMED:
325
+ this.onCallResumed();
326
+ break;
327
+ case BRIDGE_ON_CALL_MUTED:
328
+ this.onCallMuted();
329
+ break;
330
+ case BRIDGE_ON_CALL_UN_MUTED:
331
+ this.onCallUnMuted();
332
+ break;
333
+ case BRIDGE_ON_DTMF:
334
+ this.onDtmfSent(event.data.tone);
335
+ break;
336
+ case BRIDGE_ON_DIRECT_TRANSFER:
337
+ this.onDirectTransfer(event.data.number);
338
+ break;
339
+ case BRIDGE_ON_CREATE_INDIRECT_TRANSFER:
340
+ this.onCreateIndirectTransfer(event.data.number);
341
+ break;
342
+ case BRIDGE_ON_CANCEL_INDIRECT_TRANSFER:
343
+ this.onCancelIndirectTransfer();
344
+ break;
345
+ case BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER:
346
+ this.onConfirmIndirectTransfer();
347
+ break;
348
+ case BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE:
349
+ this.onIndirectCallMade(event.data.call);
350
+ break;
351
+ case BRIDGE_ON_INDIRECT_TRANSFER_DONE:
352
+ this.onIndirectTransferDone(event.data.call);
353
+ break;
354
+ case BRIDGE_ON_START_RECORDING:
355
+ this.onStartRecording();
356
+ break;
357
+ case BRIDGE_ON_STOP_RECORDING:
358
+ this.onStopRecording();
359
+ break;
360
+ case BRIDGE_ON_CARD_CANCELED:
361
+ this.onCardCanceled();
362
+ break;
363
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
364
+ this.onCallLocallyAnswered(event.data.call);
365
+ break;
366
+ case BRIDGE_ON_CALL_REJECTED:
367
+ this.onCallRejected(event.data.call);
368
+ break;
369
+ case BRIDGE_ON_CALL_REMOTELY_ACCEPTED:
370
+ this.onCallRemotelyAnswered(event.data.call);
371
+ break;
142
372
  default:
373
+ this.onUnHandledEvent(event);
143
374
  break;
144
375
  }
145
376
  }
377
+
378
+ _sendMessage(type: string, payload: Object = {}) {
379
+ if (!this.iframe || !this.iframeLoaded) {
380
+ this._pendingMessages.push([type, payload]);
381
+ return;
382
+ }
383
+
384
+ this.iframe.contentWindow.postMessage({ type, ...payload }, '*');
385
+ }
146
386
  }
147
387
 
148
388
  export default new Softphone();
@@ -1617,7 +1617,7 @@ export default class WebRTCClient extends Emitter {
1617
1617
  }
1618
1618
 
1619
1619
  async _onHeartbeatTimeout() {
1620
- logger.info('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
1620
+ logger.warn('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
1621
1621
 
1622
1622
  if (this.heartbeatTimeoutCb) {
1623
1623
  this.heartbeatTimeoutCb();