@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
  //
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 = 'https://softphone.wazo.io';
@@ -15,13 +45,39 @@ class Softphone {
15
45
  iframe = null;
16
46
 
17
47
  onLinkEnabled(link ) {}
48
+ onIFrameLoaded() {}
18
49
 
19
50
  onCallMade(call ) {}
20
51
  onCallIncoming(call ) {}
21
52
  onCallEnded(call , card , direction , fromExtension ) {}
53
+ onCardSaved(card ) {}
22
54
  onAuthenticated(session ) {}
55
+ onLoggedOut() {}
56
+ onSearchOptions(fieldId , query ) {}
57
+ onDisplayLinkedOption(optionId ) {}
58
+ onWazoContactSearch(query ) {}
59
+ onAgentLoggedIn() {}
60
+ onAgentLoggedOut() {}
61
+ onAgentPaused() {}
62
+ onAgentResumed() {}
63
+ onLanguageChanged(language ) {}
64
+ onCallHeld() {}
65
+ onCallResumed() {}
66
+ onCallMuted() {}
67
+ onCallUnMuted() {}
68
+ onDtmfSent(tone ) {}
69
+ onDirectTransfer(number ) {}
70
+ onCreateIndirectTransfer(number ) {}
71
+ onCancelIndirectTransfer() {}
72
+ onConfirmIndirectTransfer() {}
73
+ onIndirectCallMade(call ) {}
74
+ onIndirectTransferDone(call ) {}
75
+ onStartRecording() {}
76
+ onStopRecording() {}
77
+ onUnHandledEvent(event ) {}
23
78
 
24
- init(url , width , height ) {
79
+ init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
80
+ allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
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 ) {
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 , options ) {
166
+ this._sendMessage(BRIDGE_OPTIONS_FETCHED, { fieldId, options });
167
+ }
168
+
169
+ onOptionsResults(fieldId , options ) {
170
+ this._sendMessage(BRIDGE_OPTIONS_FOUND, { fieldId, options });
171
+ }
172
+
173
+ setFormSchema(schema , uiSchema ) {
174
+ this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
175
+ }
176
+
177
+ _createIframe(cb = () => {}) {
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,8 +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;
311
+ default:
312
+ this.onUnHandledEvent(event);
313
+ break;
142
314
  }
143
315
  }
316
+
317
+ _sendMessage(type , payload = {}) {
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
+ }
144
325
  }
145
326
 
146
327
  var Softphone$1 = new Softphone();
@@ -8326,7 +8326,7 @@ class WebRTCClient extends Emitter {
8326
8326
  }
8327
8327
 
8328
8328
  async _onHeartbeatTimeout() {
8329
- logger$8.info('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8329
+ logger$8.warn('sdk webrtc heartbeat timed out', { userAgent: !!this.userAgent, cb: !!this.heartbeatTimeoutCb });
8330
8330
 
8331
8331
  if (this.heartbeatTimeoutCb) {
8332
8332
  this.heartbeatTimeoutCb();
@@ -13972,11 +13972,41 @@ class Checker {
13972
13972
  //
13973
13973
  /* eslint-disable no-unused-vars */
13974
13974
  /* global window, document */
13975
+ const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13976
+ const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13977
+ const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13978
+ const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13979
+ const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13980
+ const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
13981
+ const BRIDGE_SEARCH_OPTIONS = 'bridge/BRIDGE_SEARCH_OPTIONS';
13982
+ const BRIDGE_DISPLAY_LINKED_OPTION = 'bridge/DISPLAY_LINKED_OPTION';
13983
+ const BRIDGE_UPDATE_FORM_SCHEMA = 'bridge/BRIDGE_UPDATE_FORM_SCHEMA';
13984
+ const BRIDGE_WAZO_CONTACT_SEARCH = 'bridge/BRIDGE_WAZO_CONTACT_SEARCH';
13985
+ const BRIDGE_ON_AGENT_LOGGED_IN = 'bridge/BRIDGE_ON_AGENT_LOGGED_IN';
13986
+ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13987
+ const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13988
+ const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13989
+ const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13990
+ const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13991
+ const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13992
+ const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
13993
+ const BRIDGE_ON_CALL_UN_MUTED = 'bridge/BRIDGE_ON_CALL_UN_MUTED';
13994
+ const BRIDGE_ON_DTMF = 'bridge/BRIDGE_ON_DTMF';
13995
+ const BRIDGE_ON_DIRECT_TRANSFER = 'bridge/BRIDGE_ON_DIRECT_TRANSFER';
13996
+ const BRIDGE_ON_CREATE_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CREATE_INDIRECT_TRANSFER';
13997
+ const BRIDGE_ON_CANCEL_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CANCEL_INDIRECT_TRANSFER';
13998
+ const BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER = 'bridge/BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER';
13999
+ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE';
14000
+ const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
14001
+ const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
14002
+ const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
14003
+
13975
14004
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13976
14005
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13977
14006
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13978
14007
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13979
14008
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14009
+ const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13980
14010
 
13981
14011
  class Softphone {
13982
14012
  url = 'https://softphone.wazo.io';
@@ -13986,13 +14016,39 @@ class Softphone {
13986
14016
  iframe = null;
13987
14017
 
13988
14018
  onLinkEnabled(link ) {}
14019
+ onIFrameLoaded() {}
13989
14020
 
13990
14021
  onCallMade(call ) {}
13991
14022
  onCallIncoming(call ) {}
13992
14023
  onCallEnded(call , card , direction , fromExtension ) {}
14024
+ onCardSaved(card ) {}
13993
14025
  onAuthenticated(session ) {}
13994
-
13995
- init(url , width , height ) {
14026
+ onLoggedOut() {}
14027
+ onSearchOptions(fieldId , query ) {}
14028
+ onDisplayLinkedOption(optionId ) {}
14029
+ onWazoContactSearch(query ) {}
14030
+ onAgentLoggedIn() {}
14031
+ onAgentLoggedOut() {}
14032
+ onAgentPaused() {}
14033
+ onAgentResumed() {}
14034
+ onLanguageChanged(language ) {}
14035
+ onCallHeld() {}
14036
+ onCallResumed() {}
14037
+ onCallMuted() {}
14038
+ onCallUnMuted() {}
14039
+ onDtmfSent(tone ) {}
14040
+ onDirectTransfer(number ) {}
14041
+ onCreateIndirectTransfer(number ) {}
14042
+ onCancelIndirectTransfer() {}
14043
+ onConfirmIndirectTransfer() {}
14044
+ onIndirectCallMade(call ) {}
14045
+ onIndirectTransferDone(call ) {}
14046
+ onStartRecording() {}
14047
+ onStopRecording() {}
14048
+ onUnHandledEvent(event ) {}
14049
+
14050
+ init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
14051
+ allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13996
14052
  if (url) {
13997
14053
  this.url = url;
13998
14054
  }
@@ -14005,7 +14061,33 @@ class Softphone {
14005
14061
 
14006
14062
  window.addEventListener('message', this._onMessage.bind(this), false);
14007
14063
 
14008
- this._createIframe();
14064
+ if (!server) {
14065
+ // eslint-disable-next-line no-param-reassign
14066
+ server = 'stack.dev.wazo.io';
14067
+ }
14068
+
14069
+ this._createIframe(() => {
14070
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
14071
+ config: {
14072
+ server,
14073
+ port,
14074
+ language,
14075
+ wrapUpDuration,
14076
+ shouldDisplayLinkedEntities,
14077
+ allowContactCreation,
14078
+ },
14079
+ });
14080
+
14081
+ if (withCard) {
14082
+ this._sendMessage(BRIDGE_ENABLE_CARD);
14083
+ }
14084
+
14085
+ if (subscriptionType) {
14086
+ this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
14087
+ }
14088
+
14089
+ this.onIFrameLoaded();
14090
+ });
14009
14091
  }
14010
14092
 
14011
14093
  parseLinks() {
@@ -14021,9 +14103,7 @@ class Softphone {
14021
14103
  makeCall(number ) {
14022
14104
  this.displaySoftphone();
14023
14105
 
14024
- if (this.iframe) {
14025
- this.iframe.contentWindow.postMessage({ type: SDK_CLICK_TO_CALL, number }, '*');
14026
- }
14106
+ this._sendMessage(SDK_CLICK_TO_CALL, { number });
14027
14107
  }
14028
14108
 
14029
14109
  toggleSoftphoneDisplay() {
@@ -14032,8 +14112,6 @@ class Softphone {
14032
14112
  } else {
14033
14113
  this.displaySoftphone();
14034
14114
  }
14035
-
14036
- this.displayed = !this.displayed;
14037
14115
  }
14038
14116
 
14039
14117
  displaySoftphone() {
@@ -14044,15 +14122,30 @@ class Softphone {
14044
14122
  if (this.iframe) {
14045
14123
  this.iframe.style.display = 'block';
14046
14124
  }
14125
+
14126
+ this.displayed = true;
14047
14127
  }
14048
14128
 
14049
14129
  hideSoftphone() {
14050
14130
  if (this.iframe) {
14051
14131
  this.iframe.style.display = 'none';
14052
14132
  }
14133
+ this.displayed = false;
14134
+ }
14135
+
14136
+ optionsFetched(fieldId , options ) {
14137
+ this._sendMessage(BRIDGE_OPTIONS_FETCHED, { fieldId, options });
14138
+ }
14139
+
14140
+ onOptionsResults(fieldId , options ) {
14141
+ this._sendMessage(BRIDGE_OPTIONS_FOUND, { fieldId, options });
14142
+ }
14143
+
14144
+ setFormSchema(schema , uiSchema ) {
14145
+ this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14053
14146
  }
14054
14147
 
14055
- _createIframe() {
14148
+ _createIframe(cb = () => {}) {
14056
14149
  this.iframe = document.createElement('iframe');
14057
14150
  // $FlowFixMe
14058
14151
  this.iframe.width = this.width;
@@ -14064,10 +14157,13 @@ class Softphone {
14064
14157
  this.iframe.style.left = '0';
14065
14158
  this.iframe.style.bottom = '0';
14066
14159
  this.iframe.style.border = '1px solid #aaa';
14160
+ this.iframe.style.backgroundColor = 'white';
14067
14161
  this.iframe.src = this.url;
14068
14162
  this.iframe.style.display = 'none';
14069
14163
  this.iframe.id = 'wazo-softphone';
14070
14164
 
14165
+ this.iframe.onload = cb;
14166
+
14071
14167
  // $FlowFixMe
14072
14168
  document.body.appendChild(this.iframe);
14073
14169
  }
@@ -14110,8 +14206,93 @@ class Softphone {
14110
14206
  this._onAuthenticated(event.data.session);
14111
14207
  this.onAuthenticated(event.data.session);
14112
14208
  break;
14209
+ case SDK_LOGGED_OUT:
14210
+ this.onLoggedOut();
14211
+ break;
14212
+ case BRIDGE_CREATE_OR_UPDATE_CARD: {
14213
+ const { content } = event.data;
14214
+ this.onCardSaved(content);
14215
+ break;
14216
+ }
14217
+ case BRIDGE_SEARCH_OPTIONS: {
14218
+ const { fieldId, query } = event.data;
14219
+ this.onSearchOptions(fieldId, query);
14220
+ break;
14221
+ }
14222
+ case BRIDGE_DISPLAY_LINKED_OPTION:
14223
+ this.onDisplayLinkedOption(event.data.linkedOptionId);
14224
+ break;
14225
+ case BRIDGE_WAZO_CONTACT_SEARCH:
14226
+ this.onWazoContactSearch(event.data.query);
14227
+ break;
14228
+ case BRIDGE_ON_AGENT_LOGGED_IN:
14229
+ this.onAgentLoggedIn();
14230
+ break;
14231
+ case BRIDGE_ON_AGENT_LOGGED_OUT:
14232
+ this.onAgentLoggedOut();
14233
+ break;
14234
+ case BRIDGE_ON_AGENT_PAUSED:
14235
+ this.onAgentPaused();
14236
+ break;
14237
+ case BRIDGE_ON_AGENT_RESUMED:
14238
+ this.onAgentResumed();
14239
+ break;
14240
+ case BRIDGE_ON_LANGUAGE_CHANGED:
14241
+ this.onLanguageChanged(event.data.language);
14242
+ break;
14243
+ case BRIDGE_ON_CALL_HELD:
14244
+ this.onCallHeld();
14245
+ break;
14246
+ case BRIDGE_ON_CALL_RESUMED:
14247
+ this.onCallResumed();
14248
+ break;
14249
+ case BRIDGE_ON_CALL_MUTED:
14250
+ this.onCallMuted();
14251
+ break;
14252
+ case BRIDGE_ON_CALL_UN_MUTED:
14253
+ this.onCallUnMuted();
14254
+ break;
14255
+ case BRIDGE_ON_DTMF:
14256
+ this.onDtmfSent(event.data.tone);
14257
+ break;
14258
+ case BRIDGE_ON_DIRECT_TRANSFER:
14259
+ this.onDirectTransfer(event.data.number);
14260
+ break;
14261
+ case BRIDGE_ON_CREATE_INDIRECT_TRANSFER:
14262
+ this.onCreateIndirectTransfer(event.data.number);
14263
+ break;
14264
+ case BRIDGE_ON_CANCEL_INDIRECT_TRANSFER:
14265
+ this.onCancelIndirectTransfer();
14266
+ break;
14267
+ case BRIDGE_ON_CONFIRM_INDIRECT_TRANSFER:
14268
+ this.onConfirmIndirectTransfer();
14269
+ break;
14270
+ case BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE:
14271
+ this.onIndirectCallMade(event.data.call);
14272
+ break;
14273
+ case BRIDGE_ON_INDIRECT_TRANSFER_DONE:
14274
+ this.onIndirectTransferDone(event.data.call);
14275
+ break;
14276
+ case BRIDGE_ON_START_RECORDING:
14277
+ this.onStartRecording();
14278
+ break;
14279
+ case BRIDGE_ON_STOP_RECORDING:
14280
+ this.onStopRecording();
14281
+ break;
14282
+ default:
14283
+ this.onUnHandledEvent(event);
14284
+ break;
14113
14285
  }
14114
14286
  }
14287
+
14288
+ _sendMessage(type , payload = {}) {
14289
+ if (!this.iframe) {
14290
+ console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
14291
+ return;
14292
+ }
14293
+
14294
+ this.iframe.contentWindow.postMessage({ type, ...payload }, '*');
14295
+ }
14115
14296
  }
14116
14297
 
14117
14298
  var Softphone$1 = new Softphone();