@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
@@ -1,11 +1,41 @@
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_ENABLE_CARD = 'bridge/ENABLE_CARD';
6
+ const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
7
+ const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
8
+ const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
9
+ const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
10
+ const BRIDGE_SEARCH_OPTIONS = 'bridge/BRIDGE_SEARCH_OPTIONS';
11
+ const BRIDGE_DISPLAY_LINKED_OPTION = 'bridge/DISPLAY_LINKED_OPTION';
12
+ const BRIDGE_UPDATE_FORM_SCHEMA = 'bridge/BRIDGE_UPDATE_FORM_SCHEMA';
13
+ const BRIDGE_WAZO_CONTACT_SEARCH = 'bridge/BRIDGE_WAZO_CONTACT_SEARCH';
14
+ const BRIDGE_ON_AGENT_LOGGED_IN = 'bridge/BRIDGE_ON_AGENT_LOGGED_IN';
15
+ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
16
+ const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
17
+ const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
18
+ const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
19
+ const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
20
+ const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
21
+ const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
22
+ const BRIDGE_ON_CALL_UN_MUTED = 'bridge/BRIDGE_ON_CALL_UN_MUTED';
23
+ const BRIDGE_ON_DTMF = 'bridge/BRIDGE_ON_DTMF';
24
+ const BRIDGE_ON_DIRECT_TRANSFER = 'bridge/BRIDGE_ON_DIRECT_TRANSFER';
25
+ const BRIDGE_ON_CREATE_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CREATE_INDIRECT_TRANSFER';
26
+ const BRIDGE_ON_CANCEL_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CANCEL_INDIRECT_TRANSFER';
27
+ const BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER';
28
+ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE';
29
+ const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
30
+ const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
31
+ const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
32
+
4
33
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
5
34
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
6
35
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
7
36
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
8
37
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
38
+ const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
9
39
 
10
40
  class Softphone {
11
41
  url: string = 'https://softphone.wazo.io';
@@ -15,13 +45,39 @@ class Softphone {
15
45
  iframe: ?Object = null;
16
46
 
17
47
  onLinkEnabled(link: Object) {}
48
+ onIFrameLoaded() {}
18
49
 
19
50
  onCallMade(call: Object) {}
20
51
  onCallIncoming(call: Object) {}
21
52
  onCallEnded(call: Object, card: Object, direction: string, fromExtension: string) {}
53
+ onCardSaved(card: Object) {}
22
54
  onAuthenticated(session: Object) {}
55
+ onLoggedOut() {}
56
+ onSearchOptions(fieldId: string, query: string) {}
57
+ onDisplayLinkedOption(optionId: string) {}
58
+ onWazoContactSearch(query: string) {}
59
+ onAgentLoggedIn() {}
60
+ onAgentLoggedOut() {}
61
+ onAgentPaused() {}
62
+ onAgentResumed() {}
63
+ onLanguageChanged(language: string) {}
64
+ onCallHeld() {}
65
+ onCallResumed() {}
66
+ onCallMuted() {}
67
+ onCallUnMuted() {}
68
+ onDtmfSent(tone: string) {}
69
+ onDirectTransfer(number: string) {}
70
+ onCreateIndirectTransfer(number: string) {}
71
+ onCancelIndirectTransfer() {}
72
+ onConfirmIndirectTransfer() {}
73
+ onIndirectCallMade(call: Object) {}
74
+ onIndirectTransferDone(call: Object) {}
75
+ onStartRecording() {}
76
+ onStopRecording() {}
77
+ onUnHandledEvent(event: Object) {}
23
78
 
24
- init(url: string, width: number, height: number) {
79
+ init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
80
+ allowContactCreation, withCard, subscriptionType, enableAgent }: Object = {}) {
25
81
  if (url) {
26
82
  this.url = url;
27
83
  }
@@ -34,7 +90,33 @@ class Softphone {
34
90
 
35
91
  window.addEventListener('message', this._onMessage.bind(this), false);
36
92
 
37
- this._createIframe();
93
+ if (!server) {
94
+ // eslint-disable-next-line no-param-reassign
95
+ server = 'stack.dev.wazo.io';
96
+ }
97
+
98
+ this._createIframe(() => {
99
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
100
+ config: {
101
+ server,
102
+ port,
103
+ language,
104
+ wrapUpDuration,
105
+ shouldDisplayLinkedEntities,
106
+ allowContactCreation,
107
+ },
108
+ });
109
+
110
+ if (withCard) {
111
+ this._sendMessage(BRIDGE_ENABLE_CARD);
112
+ }
113
+
114
+ if (subscriptionType) {
115
+ this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
116
+ }
117
+
118
+ this.onIFrameLoaded();
119
+ });
38
120
  }
39
121
 
40
122
  parseLinks() {
@@ -50,9 +132,7 @@ class Softphone {
50
132
  makeCall(number: string) {
51
133
  this.displaySoftphone();
52
134
 
53
- if (this.iframe) {
54
- this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
55
- }
135
+ this._sendMessage(SDK_CLICK_TO_CALL, { number });
56
136
  }
57
137
 
58
138
  toggleSoftphoneDisplay() {
@@ -61,8 +141,6 @@ class Softphone {
61
141
  } else {
62
142
  this.displaySoftphone();
63
143
  }
64
-
65
- this.displayed = !this.displayed;
66
144
  }
67
145
 
68
146
  displaySoftphone() {
@@ -73,15 +151,30 @@ class Softphone {
73
151
  if (this.iframe) {
74
152
  this.iframe.style.display = 'block';
75
153
  }
154
+
155
+ this.displayed = true;
76
156
  }
77
157
 
78
158
  hideSoftphone() {
79
159
  if (this.iframe) {
80
160
  this.iframe.style.display = 'none';
81
161
  }
162
+ this.displayed = false;
82
163
  }
83
164
 
84
- _createIframe() {
165
+ optionsFetched(fieldId: string, options: any[]) {
166
+ this._sendMessage(BRIDGE_OPTIONS_FETCHED, { fieldId, options });
167
+ }
168
+
169
+ onOptionsResults(fieldId: string, options: any[]) {
170
+ this._sendMessage(BRIDGE_OPTIONS_FOUND, { fieldId, options });
171
+ }
172
+
173
+ setFormSchema(schema: Object, uiSchema: Object) {
174
+ this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
175
+ }
176
+
177
+ _createIframe(cb: Function = () => {}) {
85
178
  this.iframe = document.createElement('iframe');
86
179
  // $FlowFixMe
87
180
  this.iframe.width = this.width;
@@ -93,10 +186,13 @@ class Softphone {
93
186
  this.iframe.style.left = '0';
94
187
  this.iframe.style.bottom = '0';
95
188
  this.iframe.style.border = '1px solid #aaa';
189
+ this.iframe.style.backgroundColor = 'white';
96
190
  this.iframe.src = this.url;
97
191
  this.iframe.style.display = 'none';
98
192
  this.iframe.id = 'wazo-softphone';
99
193
 
194
+ this.iframe.onload = cb;
195
+
100
196
  // $FlowFixMe
101
197
  document.body.appendChild(this.iframe);
102
198
  }
@@ -139,10 +235,93 @@ class Softphone {
139
235
  this._onAuthenticated(event.data.session);
140
236
  this.onAuthenticated(event.data.session);
141
237
  break;
238
+ case SDK_LOGGED_OUT:
239
+ this.onLoggedOut();
240
+ break;
241
+ case BRIDGE_CREATE_OR_UPDATE_CARD: {
242
+ const { content } = event.data;
243
+ this.onCardSaved(content);
244
+ break;
245
+ }
246
+ case BRIDGE_SEARCH_OPTIONS: {
247
+ const { fieldId, query } = event.data;
248
+ this.onSearchOptions(fieldId, query);
249
+ break;
250
+ }
251
+ case BRIDGE_DISPLAY_LINKED_OPTION:
252
+ this.onDisplayLinkedOption(event.data.linkedOptionId);
253
+ break;
254
+ case BRIDGE_WAZO_CONTACT_SEARCH:
255
+ this.onWazoContactSearch(event.data.query);
256
+ break;
257
+ case BRIDGE_ON_AGENT_LOGGED_IN:
258
+ this.onAgentLoggedIn();
259
+ break;
260
+ case BRIDGE_ON_AGENT_LOGGED_OUT:
261
+ this.onAgentLoggedOut();
262
+ break;
263
+ case BRIDGE_ON_AGENT_PAUSED:
264
+ this.onAgentPaused();
265
+ break;
266
+ case BRIDGE_ON_AGENT_RESUMED:
267
+ this.onAgentResumed();
268
+ break;
269
+ case BRIDGE_ON_LANGUAGE_CHANGED:
270
+ this.onLanguageChanged(event.data.language);
271
+ break;
272
+ case BRIDGE_ON_CALL_HELD:
273
+ this.onCallHeld();
274
+ break;
275
+ case BRIDGE_ON_CALL_RESUMED:
276
+ this.onCallResumed();
277
+ break;
278
+ case BRIDGE_ON_CALL_MUTED:
279
+ this.onCallMuted();
280
+ break;
281
+ case BRIDGE_ON_CALL_UN_MUTED:
282
+ this.onCallUnMuted();
283
+ break;
284
+ case BRIDGE_ON_DTMF:
285
+ this.onDtmfSent(event.data.tone);
286
+ break;
287
+ case BRIDGE_ON_DIRECT_TRANSFER:
288
+ this.onDirectTransfer(event.data.number);
289
+ break;
290
+ case BRIDGE_ON_CREATE_INDIRECT_TRANSFER:
291
+ this.onCreateIndirectTransfer(event.data.number);
292
+ break;
293
+ case BRIDGE_ON_CANCEL_INDIRECT_TRANSFER:
294
+ this.onCancelIndirectTransfer();
295
+ break;
296
+ case BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER:
297
+ this.onConfirmIndirectTransfer();
298
+ break;
299
+ case BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE:
300
+ this.onIndirectCallMade(event.data.call);
301
+ break;
302
+ case BRIDGE_ON_INDIRECT_TRANSFER_DONE:
303
+ this.onIndirectTransferDone(event.data.call);
304
+ break;
305
+ case BRIDGE_ON_START_RECORDING:
306
+ this.onStartRecording();
307
+ break;
308
+ case BRIDGE_ON_STOP_RECORDING:
309
+ this.onStopRecording();
310
+ break;
142
311
  default:
312
+ this.onUnHandledEvent(event);
143
313
  break;
144
314
  }
145
315
  }
316
+
317
+ _sendMessage(type: string, payload: Object = {}) {
318
+ if (!this.iframe) {
319
+ console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
320
+ return;
321
+ }
322
+
323
+ this.iframe.contentWindow.postMessage({ type, ...payload }, '*');
324
+ }
146
325
  }
147
326
 
148
327
  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();