@wazo/sdk 0.38.1 → 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.
@@ -4,8 +4,6 @@
4
4
  /* eslint-disable no-unused-vars */
5
5
  /* global window, document */
6
6
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
7
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
8
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
9
7
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
10
8
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
11
9
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -18,6 +16,7 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
18
16
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
19
17
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
20
18
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
19
+ const BRIDGE_ON_CALL_ANSWERED = 'bridge/BRIDGE_ON_CALL_ANSWERED';
21
20
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
22
21
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
23
22
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -31,6 +30,12 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
31
30
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
32
31
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
33
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
+
37
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
38
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
34
39
 
35
40
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
36
41
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
@@ -40,22 +45,32 @@ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
40
45
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
41
46
 
42
47
  class Softphone {
43
- url = 'https://softphone.wazo.io';
44
- width = 500;
45
- height = 600;
46
- displayed = false;
47
- iframe = null;
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+ // Message waiting for the iframe to be loaded
56
+
48
57
 
49
58
  onLinkEnabled(link ) {}
50
59
  onIFrameLoaded() {}
51
60
 
61
+ onCallAnswered() {}
52
62
  onCallMade(call ) {}
53
63
  onCallIncoming(call ) {}
54
64
  onCallEnded(call , card , direction , fromExtension ) {}
55
65
  onCardSaved(card ) {}
66
+ onCardCanceled() {}
56
67
  onAuthenticated(session ) {}
57
68
  onLoggedOut() {}
58
- onSearchOptions(fieldId , query ) {}
69
+
70
+ onSearchOptions(fieldId , query ) {
71
+ this.onOptionsResults(fieldId, []);
72
+ }
73
+
59
74
  onDisplayLinkedOption(optionId ) {}
60
75
  onWazoContactSearch(query ) {}
61
76
  onAgentLoggedIn() {}
@@ -78,18 +93,15 @@ class Softphone {
78
93
  onStopRecording() {}
79
94
  onUnHandledEvent(event ) {}
80
95
 
81
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
82
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
83
- if (url) {
84
- this.url = url;
85
- }
86
- if (width) {
87
- this.width = width;
88
- }
89
- if (height) {
90
- this.height = height;
91
- }
96
+ init({ url, width, height, server, port, language, wrapUpDuration, enableAgent = true } = {}) {
97
+ this.url = url || 'https://softphone.wazo.io';
98
+ this.width = width || 500;
99
+ this.height = height || 600;
100
+ this.displayed = false;
101
+ this.iframeLoaded = false;
92
102
 
103
+ this.iframeLoaded = false;
104
+ this._pendingMessages = [];
93
105
  window.addEventListener('message', this._onMessage.bind(this), false);
94
106
 
95
107
  if (!server) {
@@ -97,25 +109,26 @@ class Softphone {
97
109
  server = 'stack.dev.wazo.io';
98
110
  }
99
111
 
100
- this._createIframe(() => {
101
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
102
- config: {
103
- server,
104
- port,
105
- language,
106
- wrapUpDuration,
107
- shouldDisplayLinkedEntities,
108
- allowContactCreation,
109
- },
110
- });
111
-
112
- if (withCard) {
113
- this._sendMessage(BRIDGE_ENABLE_CARD);
114
- }
112
+ const config = { server };
113
+ if (language) {
114
+ config.language = language;
115
+ }
116
+ if (port) {
117
+ config.port = port;
118
+ }
119
+ if (wrapUpDuration) {
120
+ config.wrapUpDuration = wrapUpDuration;
121
+ }
115
122
 
116
- if (subscriptionType) {
117
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
118
- }
123
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
124
+
125
+ if (enableAgent) {
126
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
127
+ }
128
+
129
+ this._createIframe(() => {
130
+ this.iframeLoaded = true;
131
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
119
132
 
120
133
  this.onIFrameLoaded();
121
134
  });
@@ -176,6 +189,18 @@ class Softphone {
176
189
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
177
190
  }
178
191
 
192
+ setCardValue(field , value ) {
193
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
194
+ }
195
+
196
+ injectCss(css ) {
197
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
198
+ }
199
+
200
+ customizeAppearance(themes , translations , assets ) {
201
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
202
+ }
203
+
179
204
  _createIframe(cb = () => {}) {
180
205
  this.iframe = document.createElement('iframe');
181
206
  // $FlowFixMe
@@ -310,6 +335,12 @@ class Softphone {
310
335
  case BRIDGE_ON_STOP_RECORDING:
311
336
  this.onStopRecording();
312
337
  break;
338
+ case BRIDGE_ON_CARD_CANCELED:
339
+ this.onCardCanceled();
340
+ break;
341
+ case BRIDGE_ON_CALL_ANSWERED:
342
+ this.onCallAnswered();
343
+ break;
313
344
  default:
314
345
  this.onUnHandledEvent(event);
315
346
  break;
@@ -317,8 +348,8 @@ class Softphone {
317
348
  }
318
349
 
319
350
  _sendMessage(type , payload = {}) {
320
- if (!this.iframe) {
321
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
351
+ if (!this.iframe || !this.iframeLoaded) {
352
+ this._pendingMessages.push([type, payload]);
322
353
  return;
323
354
  }
324
355
 
@@ -13983,8 +13983,6 @@ class Checker {
13983
13983
  /* eslint-disable no-unused-vars */
13984
13984
  /* global window, document */
13985
13985
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13986
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13987
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13988
13986
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13989
13987
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13990
13988
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -13997,6 +13995,7 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13997
13995
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13998
13996
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13999
13997
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13998
+ const BRIDGE_ON_CALL_ANSWERED = 'bridge/BRIDGE_ON_CALL_ANSWERED';
14000
13999
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
14001
14000
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
14002
14001
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -14010,6 +14009,12 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
14010
14009
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
14011
14010
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
14012
14011
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
14012
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
14013
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
14014
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
14015
+
14016
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
14017
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
14013
14018
 
14014
14019
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
14015
14020
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
@@ -14019,22 +14024,32 @@ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14019
14024
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
14020
14025
 
14021
14026
  class Softphone {
14022
- url = 'https://softphone.wazo.io';
14023
- width = 500;
14024
- height = 600;
14025
- displayed = false;
14026
- iframe = null;
14027
+
14028
+
14029
+
14030
+
14031
+
14032
+
14033
+
14034
+ // Message waiting for the iframe to be loaded
14035
+
14027
14036
 
14028
14037
  onLinkEnabled(link ) {}
14029
14038
  onIFrameLoaded() {}
14030
14039
 
14040
+ onCallAnswered() {}
14031
14041
  onCallMade(call ) {}
14032
14042
  onCallIncoming(call ) {}
14033
14043
  onCallEnded(call , card , direction , fromExtension ) {}
14034
14044
  onCardSaved(card ) {}
14045
+ onCardCanceled() {}
14035
14046
  onAuthenticated(session ) {}
14036
14047
  onLoggedOut() {}
14037
- onSearchOptions(fieldId , query ) {}
14048
+
14049
+ onSearchOptions(fieldId , query ) {
14050
+ this.onOptionsResults(fieldId, []);
14051
+ }
14052
+
14038
14053
  onDisplayLinkedOption(optionId ) {}
14039
14054
  onWazoContactSearch(query ) {}
14040
14055
  onAgentLoggedIn() {}
@@ -14057,18 +14072,15 @@ class Softphone {
14057
14072
  onStopRecording() {}
14058
14073
  onUnHandledEvent(event ) {}
14059
14074
 
14060
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
14061
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
14062
- if (url) {
14063
- this.url = url;
14064
- }
14065
- if (width) {
14066
- this.width = width;
14067
- }
14068
- if (height) {
14069
- this.height = height;
14070
- }
14075
+ init({ url, width, height, server, port, language, wrapUpDuration, enableAgent = true } = {}) {
14076
+ this.url = url || 'https://softphone.wazo.io';
14077
+ this.width = width || 500;
14078
+ this.height = height || 600;
14079
+ this.displayed = false;
14080
+ this.iframeLoaded = false;
14071
14081
 
14082
+ this.iframeLoaded = false;
14083
+ this._pendingMessages = [];
14072
14084
  window.addEventListener('message', this._onMessage.bind(this), false);
14073
14085
 
14074
14086
  if (!server) {
@@ -14076,25 +14088,26 @@ class Softphone {
14076
14088
  server = 'stack.dev.wazo.io';
14077
14089
  }
14078
14090
 
14079
- this._createIframe(() => {
14080
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
14081
- config: {
14082
- server,
14083
- port,
14084
- language,
14085
- wrapUpDuration,
14086
- shouldDisplayLinkedEntities,
14087
- allowContactCreation,
14088
- },
14089
- });
14091
+ const config = { server };
14092
+ if (language) {
14093
+ config.language = language;
14094
+ }
14095
+ if (port) {
14096
+ config.port = port;
14097
+ }
14098
+ if (wrapUpDuration) {
14099
+ config.wrapUpDuration = wrapUpDuration;
14100
+ }
14090
14101
 
14091
- if (withCard) {
14092
- this._sendMessage(BRIDGE_ENABLE_CARD);
14093
- }
14102
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
14094
14103
 
14095
- if (subscriptionType) {
14096
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
14097
- }
14104
+ if (enableAgent) {
14105
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
14106
+ }
14107
+
14108
+ this._createIframe(() => {
14109
+ this.iframeLoaded = true;
14110
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
14098
14111
 
14099
14112
  this.onIFrameLoaded();
14100
14113
  });
@@ -14155,6 +14168,18 @@ class Softphone {
14155
14168
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14156
14169
  }
14157
14170
 
14171
+ setCardValue(field , value ) {
14172
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
14173
+ }
14174
+
14175
+ injectCss(css ) {
14176
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
14177
+ }
14178
+
14179
+ customizeAppearance(themes , translations , assets ) {
14180
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
14181
+ }
14182
+
14158
14183
  _createIframe(cb = () => {}) {
14159
14184
  this.iframe = document.createElement('iframe');
14160
14185
  // $FlowFixMe
@@ -14289,6 +14314,12 @@ class Softphone {
14289
14314
  case BRIDGE_ON_STOP_RECORDING:
14290
14315
  this.onStopRecording();
14291
14316
  break;
14317
+ case BRIDGE_ON_CARD_CANCELED:
14318
+ this.onCardCanceled();
14319
+ break;
14320
+ case BRIDGE_ON_CALL_ANSWERED:
14321
+ this.onCallAnswered();
14322
+ break;
14292
14323
  default:
14293
14324
  this.onUnHandledEvent(event);
14294
14325
  break;
@@ -14296,8 +14327,8 @@ class Softphone {
14296
14327
  }
14297
14328
 
14298
14329
  _sendMessage(type , payload = {}) {
14299
- if (!this.iframe) {
14300
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
14330
+ if (!this.iframe || !this.iframeLoaded) {
14331
+ this._pendingMessages.push([type, payload]);
14301
14332
  return;
14302
14333
  }
14303
14334
 
@@ -12852,8 +12852,6 @@ class Checker {
12852
12852
  /* eslint-disable no-unused-vars */
12853
12853
  /* global window, document */
12854
12854
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
12855
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
12856
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
12857
12855
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
12858
12856
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
12859
12857
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -12866,6 +12864,7 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
12866
12864
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
12867
12865
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
12868
12866
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
12867
+ const BRIDGE_ON_CALL_ANSWERED = 'bridge/BRIDGE_ON_CALL_ANSWERED';
12869
12868
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
12870
12869
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
12871
12870
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -12879,6 +12878,12 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
12879
12878
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
12880
12879
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
12881
12880
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
12881
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
12882
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
12883
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
12884
+
12885
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
12886
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
12882
12887
 
12883
12888
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
12884
12889
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
@@ -12888,22 +12893,32 @@ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
12888
12893
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
12889
12894
 
12890
12895
  class Softphone {
12891
- url = 'https://softphone.wazo.io';
12892
- width = 500;
12893
- height = 600;
12894
- displayed = false;
12895
- iframe = null;
12896
+
12897
+
12898
+
12899
+
12900
+
12901
+
12902
+
12903
+ // Message waiting for the iframe to be loaded
12904
+
12896
12905
 
12897
12906
  onLinkEnabled(link ) {}
12898
12907
  onIFrameLoaded() {}
12899
12908
 
12909
+ onCallAnswered() {}
12900
12910
  onCallMade(call ) {}
12901
12911
  onCallIncoming(call ) {}
12902
12912
  onCallEnded(call , card , direction , fromExtension ) {}
12903
12913
  onCardSaved(card ) {}
12914
+ onCardCanceled() {}
12904
12915
  onAuthenticated(session ) {}
12905
12916
  onLoggedOut() {}
12906
- onSearchOptions(fieldId , query ) {}
12917
+
12918
+ onSearchOptions(fieldId , query ) {
12919
+ this.onOptionsResults(fieldId, []);
12920
+ }
12921
+
12907
12922
  onDisplayLinkedOption(optionId ) {}
12908
12923
  onWazoContactSearch(query ) {}
12909
12924
  onAgentLoggedIn() {}
@@ -12926,18 +12941,15 @@ class Softphone {
12926
12941
  onStopRecording() {}
12927
12942
  onUnHandledEvent(event ) {}
12928
12943
 
12929
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
12930
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
12931
- if (url) {
12932
- this.url = url;
12933
- }
12934
- if (width) {
12935
- this.width = width;
12936
- }
12937
- if (height) {
12938
- this.height = height;
12939
- }
12944
+ init({ url, width, height, server, port, language, wrapUpDuration, enableAgent = true } = {}) {
12945
+ this.url = url || 'https://softphone.wazo.io';
12946
+ this.width = width || 500;
12947
+ this.height = height || 600;
12948
+ this.displayed = false;
12949
+ this.iframeLoaded = false;
12940
12950
 
12951
+ this.iframeLoaded = false;
12952
+ this._pendingMessages = [];
12941
12953
  window.addEventListener('message', this._onMessage.bind(this), false);
12942
12954
 
12943
12955
  if (!server) {
@@ -12945,25 +12957,26 @@ class Softphone {
12945
12957
  server = 'stack.dev.wazo.io';
12946
12958
  }
12947
12959
 
12948
- this._createIframe(() => {
12949
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
12950
- config: {
12951
- server,
12952
- port,
12953
- language,
12954
- wrapUpDuration,
12955
- shouldDisplayLinkedEntities,
12956
- allowContactCreation,
12957
- },
12958
- });
12960
+ const config = { server };
12961
+ if (language) {
12962
+ config.language = language;
12963
+ }
12964
+ if (port) {
12965
+ config.port = port;
12966
+ }
12967
+ if (wrapUpDuration) {
12968
+ config.wrapUpDuration = wrapUpDuration;
12969
+ }
12959
12970
 
12960
- if (withCard) {
12961
- this._sendMessage(BRIDGE_ENABLE_CARD);
12962
- }
12971
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
12963
12972
 
12964
- if (subscriptionType) {
12965
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
12966
- }
12973
+ if (enableAgent) {
12974
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
12975
+ }
12976
+
12977
+ this._createIframe(() => {
12978
+ this.iframeLoaded = true;
12979
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
12967
12980
 
12968
12981
  this.onIFrameLoaded();
12969
12982
  });
@@ -13024,6 +13037,18 @@ class Softphone {
13024
13037
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13025
13038
  }
13026
13039
 
13040
+ setCardValue(field , value ) {
13041
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
13042
+ }
13043
+
13044
+ injectCss(css ) {
13045
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
13046
+ }
13047
+
13048
+ customizeAppearance(themes , translations , assets ) {
13049
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
13050
+ }
13051
+
13027
13052
  _createIframe(cb = () => {}) {
13028
13053
  this.iframe = document.createElement('iframe');
13029
13054
  // $FlowFixMe
@@ -13158,6 +13183,12 @@ class Softphone {
13158
13183
  case BRIDGE_ON_STOP_RECORDING:
13159
13184
  this.onStopRecording();
13160
13185
  break;
13186
+ case BRIDGE_ON_CARD_CANCELED:
13187
+ this.onCardCanceled();
13188
+ break;
13189
+ case BRIDGE_ON_CALL_ANSWERED:
13190
+ this.onCallAnswered();
13191
+ break;
13161
13192
  default:
13162
13193
  this.onUnHandledEvent(event);
13163
13194
  break;
@@ -13165,8 +13196,8 @@ class Softphone {
13165
13196
  }
13166
13197
 
13167
13198
  _sendMessage(type , payload = {}) {
13168
- if (!this.iframe) {
13169
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
13199
+ if (!this.iframe || !this.iframeLoaded) {
13200
+ this._pendingMessages.push([type, payload]);
13170
13201
  return;
13171
13202
  }
13172
13203