@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.
@@ -13563,8 +13563,6 @@ class Checker {
13563
13563
  /* eslint-disable no-unused-vars */
13564
13564
  /* global window, document */
13565
13565
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13566
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13567
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13568
13566
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13569
13567
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13570
13568
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -13577,6 +13575,7 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13577
13575
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13578
13576
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13579
13577
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13578
+ const BRIDGE_ON_CALL_ANSWERED = 'bridge/BRIDGE_ON_CALL_ANSWERED';
13580
13579
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13581
13580
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13582
13581
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -13590,6 +13589,12 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
13590
13589
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13591
13590
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13592
13591
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13592
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
13593
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
13594
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
13595
+
13596
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
13597
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
13593
13598
 
13594
13599
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13595
13600
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
@@ -13599,22 +13604,32 @@ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13599
13604
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13600
13605
 
13601
13606
  class Softphone {
13602
- url = 'https://softphone.wazo.io';
13603
- width = 500;
13604
- height = 600;
13605
- displayed = false;
13606
- iframe = null;
13607
+
13608
+
13609
+
13610
+
13611
+
13612
+
13613
+
13614
+ // Message waiting for the iframe to be loaded
13615
+
13607
13616
 
13608
13617
  onLinkEnabled(link ) {}
13609
13618
  onIFrameLoaded() {}
13610
13619
 
13620
+ onCallAnswered() {}
13611
13621
  onCallMade(call ) {}
13612
13622
  onCallIncoming(call ) {}
13613
13623
  onCallEnded(call , card , direction , fromExtension ) {}
13614
13624
  onCardSaved(card ) {}
13625
+ onCardCanceled() {}
13615
13626
  onAuthenticated(session ) {}
13616
13627
  onLoggedOut() {}
13617
- onSearchOptions(fieldId , query ) {}
13628
+
13629
+ onSearchOptions(fieldId , query ) {
13630
+ this.onOptionsResults(fieldId, []);
13631
+ }
13632
+
13618
13633
  onDisplayLinkedOption(optionId ) {}
13619
13634
  onWazoContactSearch(query ) {}
13620
13635
  onAgentLoggedIn() {}
@@ -13637,18 +13652,15 @@ class Softphone {
13637
13652
  onStopRecording() {}
13638
13653
  onUnHandledEvent(event ) {}
13639
13654
 
13640
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
13641
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
13642
- if (url) {
13643
- this.url = url;
13644
- }
13645
- if (width) {
13646
- this.width = width;
13647
- }
13648
- if (height) {
13649
- this.height = height;
13650
- }
13655
+ init({ url, width, height, server, port, language, wrapUpDuration, enableAgent = true } = {}) {
13656
+ this.url = url || 'https://softphone.wazo.io';
13657
+ this.width = width || 500;
13658
+ this.height = height || 600;
13659
+ this.displayed = false;
13660
+ this.iframeLoaded = false;
13651
13661
 
13662
+ this.iframeLoaded = false;
13663
+ this._pendingMessages = [];
13652
13664
  window.addEventListener('message', this._onMessage.bind(this), false);
13653
13665
 
13654
13666
  if (!server) {
@@ -13656,25 +13668,26 @@ class Softphone {
13656
13668
  server = 'stack.dev.wazo.io';
13657
13669
  }
13658
13670
 
13659
- this._createIframe(() => {
13660
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
13661
- config: {
13662
- server,
13663
- port,
13664
- language,
13665
- wrapUpDuration,
13666
- shouldDisplayLinkedEntities,
13667
- allowContactCreation,
13668
- },
13669
- });
13671
+ const config = { server };
13672
+ if (language) {
13673
+ config.language = language;
13674
+ }
13675
+ if (port) {
13676
+ config.port = port;
13677
+ }
13678
+ if (wrapUpDuration) {
13679
+ config.wrapUpDuration = wrapUpDuration;
13680
+ }
13670
13681
 
13671
- if (withCard) {
13672
- this._sendMessage(BRIDGE_ENABLE_CARD);
13673
- }
13682
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
13674
13683
 
13675
- if (subscriptionType) {
13676
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
13677
- }
13684
+ if (enableAgent) {
13685
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
13686
+ }
13687
+
13688
+ this._createIframe(() => {
13689
+ this.iframeLoaded = true;
13690
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
13678
13691
 
13679
13692
  this.onIFrameLoaded();
13680
13693
  });
@@ -13735,6 +13748,18 @@ class Softphone {
13735
13748
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13736
13749
  }
13737
13750
 
13751
+ setCardValue(field , value ) {
13752
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
13753
+ }
13754
+
13755
+ injectCss(css ) {
13756
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
13757
+ }
13758
+
13759
+ customizeAppearance(themes , translations , assets ) {
13760
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
13761
+ }
13762
+
13738
13763
  _createIframe(cb = () => {}) {
13739
13764
  this.iframe = document.createElement('iframe');
13740
13765
  // $FlowFixMe
@@ -13869,6 +13894,12 @@ class Softphone {
13869
13894
  case BRIDGE_ON_STOP_RECORDING:
13870
13895
  this.onStopRecording();
13871
13896
  break;
13897
+ case BRIDGE_ON_CARD_CANCELED:
13898
+ this.onCardCanceled();
13899
+ break;
13900
+ case BRIDGE_ON_CALL_ANSWERED:
13901
+ this.onCallAnswered();
13902
+ break;
13872
13903
  default:
13873
13904
  this.onUnHandledEvent(event);
13874
13905
  break;
@@ -13876,8 +13907,8 @@ class Softphone {
13876
13907
  }
13877
13908
 
13878
13909
  _sendMessage(type , payload = {}) {
13879
- if (!this.iframe) {
13880
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
13910
+ if (!this.iframe || !this.iframeLoaded) {
13911
+ this._pendingMessages.push([type, payload]);
13881
13912
  return;
13882
13913
  }
13883
13914
 
@@ -2,8 +2,6 @@
2
2
  /* eslint-disable no-unused-vars */
3
3
  /* global window, document */
4
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
5
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
8
6
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
9
7
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -16,6 +14,7 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
16
14
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
17
15
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
18
16
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
17
+ const BRIDGE_ON_CALL_ANSWERED = 'bridge/BRIDGE_ON_CALL_ANSWERED';
19
18
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
20
19
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
21
20
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -29,6 +28,12 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
29
28
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
30
29
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
31
30
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
31
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
32
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
33
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
34
+
35
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
36
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
32
37
 
33
38
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
34
39
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
@@ -38,22 +43,32 @@ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
38
43
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
39
44
 
40
45
  class Softphone {
41
- url = 'https://softphone.wazo.io';
42
- width = 500;
43
- height = 600;
44
- displayed = false;
45
- iframe = null;
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+ // Message waiting for the iframe to be loaded
54
+
46
55
 
47
56
  onLinkEnabled(link ) {}
48
57
  onIFrameLoaded() {}
49
58
 
59
+ onCallAnswered() {}
50
60
  onCallMade(call ) {}
51
61
  onCallIncoming(call ) {}
52
62
  onCallEnded(call , card , direction , fromExtension ) {}
53
63
  onCardSaved(card ) {}
64
+ onCardCanceled() {}
54
65
  onAuthenticated(session ) {}
55
66
  onLoggedOut() {}
56
- onSearchOptions(fieldId , query ) {}
67
+
68
+ onSearchOptions(fieldId , query ) {
69
+ this.onOptionsResults(fieldId, []);
70
+ }
71
+
57
72
  onDisplayLinkedOption(optionId ) {}
58
73
  onWazoContactSearch(query ) {}
59
74
  onAgentLoggedIn() {}
@@ -76,18 +91,15 @@ class Softphone {
76
91
  onStopRecording() {}
77
92
  onUnHandledEvent(event ) {}
78
93
 
79
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
80
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
81
- if (url) {
82
- this.url = url;
83
- }
84
- if (width) {
85
- this.width = width;
86
- }
87
- if (height) {
88
- this.height = height;
89
- }
94
+ init({ url, width, height, server, port, language, wrapUpDuration, enableAgent = true } = {}) {
95
+ this.url = url || 'https://softphone.wazo.io';
96
+ this.width = width || 500;
97
+ this.height = height || 600;
98
+ this.displayed = false;
99
+ this.iframeLoaded = false;
90
100
 
101
+ this.iframeLoaded = false;
102
+ this._pendingMessages = [];
91
103
  window.addEventListener('message', this._onMessage.bind(this), false);
92
104
 
93
105
  if (!server) {
@@ -95,25 +107,26 @@ class Softphone {
95
107
  server = 'stack.dev.wazo.io';
96
108
  }
97
109
 
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
- }
110
+ const config = { server };
111
+ if (language) {
112
+ config.language = language;
113
+ }
114
+ if (port) {
115
+ config.port = port;
116
+ }
117
+ if (wrapUpDuration) {
118
+ config.wrapUpDuration = wrapUpDuration;
119
+ }
113
120
 
114
- if (subscriptionType) {
115
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
116
- }
121
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
122
+
123
+ if (enableAgent) {
124
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
125
+ }
126
+
127
+ this._createIframe(() => {
128
+ this.iframeLoaded = true;
129
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
117
130
 
118
131
  this.onIFrameLoaded();
119
132
  });
@@ -174,6 +187,18 @@ class Softphone {
174
187
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
175
188
  }
176
189
 
190
+ setCardValue(field , value ) {
191
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
192
+ }
193
+
194
+ injectCss(css ) {
195
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
196
+ }
197
+
198
+ customizeAppearance(themes , translations , assets ) {
199
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
200
+ }
201
+
177
202
  _createIframe(cb = () => {}) {
178
203
  this.iframe = document.createElement('iframe');
179
204
  // $FlowFixMe
@@ -308,6 +333,12 @@ class Softphone {
308
333
  case BRIDGE_ON_STOP_RECORDING:
309
334
  this.onStopRecording();
310
335
  break;
336
+ case BRIDGE_ON_CARD_CANCELED:
337
+ this.onCardCanceled();
338
+ break;
339
+ case BRIDGE_ON_CALL_ANSWERED:
340
+ this.onCallAnswered();
341
+ break;
311
342
  default:
312
343
  this.onUnHandledEvent(event);
313
344
  break;
@@ -315,8 +346,8 @@ class Softphone {
315
346
  }
316
347
 
317
348
  _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`);
349
+ if (!this.iframe || !this.iframeLoaded) {
350
+ this._pendingMessages.push([type, payload]);
320
351
  return;
321
352
  }
322
353
 
@@ -13973,8 +13973,6 @@ class Checker {
13973
13973
  /* eslint-disable no-unused-vars */
13974
13974
  /* global window, document */
13975
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
13976
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13979
13977
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13980
13978
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -13987,6 +13985,7 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13987
13985
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13988
13986
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13989
13987
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13988
+ const BRIDGE_ON_CALL_ANSWERED = 'bridge/BRIDGE_ON_CALL_ANSWERED';
13990
13989
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13991
13990
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13992
13991
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -14000,6 +13999,12 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
14000
13999
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
14001
14000
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
14002
14001
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
14002
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
14003
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
14004
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
14005
+
14006
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
14007
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
14003
14008
 
14004
14009
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
14005
14010
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
@@ -14009,22 +14014,32 @@ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14009
14014
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
14010
14015
 
14011
14016
  class Softphone {
14012
- url = 'https://softphone.wazo.io';
14013
- width = 500;
14014
- height = 600;
14015
- displayed = false;
14016
- iframe = null;
14017
+
14018
+
14019
+
14020
+
14021
+
14022
+
14023
+
14024
+ // Message waiting for the iframe to be loaded
14025
+
14017
14026
 
14018
14027
  onLinkEnabled(link ) {}
14019
14028
  onIFrameLoaded() {}
14020
14029
 
14030
+ onCallAnswered() {}
14021
14031
  onCallMade(call ) {}
14022
14032
  onCallIncoming(call ) {}
14023
14033
  onCallEnded(call , card , direction , fromExtension ) {}
14024
14034
  onCardSaved(card ) {}
14035
+ onCardCanceled() {}
14025
14036
  onAuthenticated(session ) {}
14026
14037
  onLoggedOut() {}
14027
- onSearchOptions(fieldId , query ) {}
14038
+
14039
+ onSearchOptions(fieldId , query ) {
14040
+ this.onOptionsResults(fieldId, []);
14041
+ }
14042
+
14028
14043
  onDisplayLinkedOption(optionId ) {}
14029
14044
  onWazoContactSearch(query ) {}
14030
14045
  onAgentLoggedIn() {}
@@ -14047,18 +14062,15 @@ class Softphone {
14047
14062
  onStopRecording() {}
14048
14063
  onUnHandledEvent(event ) {}
14049
14064
 
14050
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
14051
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
14052
- if (url) {
14053
- this.url = url;
14054
- }
14055
- if (width) {
14056
- this.width = width;
14057
- }
14058
- if (height) {
14059
- this.height = height;
14060
- }
14065
+ init({ url, width, height, server, port, language, wrapUpDuration, enableAgent = true } = {}) {
14066
+ this.url = url || 'https://softphone.wazo.io';
14067
+ this.width = width || 500;
14068
+ this.height = height || 600;
14069
+ this.displayed = false;
14070
+ this.iframeLoaded = false;
14061
14071
 
14072
+ this.iframeLoaded = false;
14073
+ this._pendingMessages = [];
14062
14074
  window.addEventListener('message', this._onMessage.bind(this), false);
14063
14075
 
14064
14076
  if (!server) {
@@ -14066,25 +14078,26 @@ class Softphone {
14066
14078
  server = 'stack.dev.wazo.io';
14067
14079
  }
14068
14080
 
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
- });
14081
+ const config = { server };
14082
+ if (language) {
14083
+ config.language = language;
14084
+ }
14085
+ if (port) {
14086
+ config.port = port;
14087
+ }
14088
+ if (wrapUpDuration) {
14089
+ config.wrapUpDuration = wrapUpDuration;
14090
+ }
14080
14091
 
14081
- if (withCard) {
14082
- this._sendMessage(BRIDGE_ENABLE_CARD);
14083
- }
14092
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
14084
14093
 
14085
- if (subscriptionType) {
14086
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
14087
- }
14094
+ if (enableAgent) {
14095
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
14096
+ }
14097
+
14098
+ this._createIframe(() => {
14099
+ this.iframeLoaded = true;
14100
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
14088
14101
 
14089
14102
  this.onIFrameLoaded();
14090
14103
  });
@@ -14145,6 +14158,18 @@ class Softphone {
14145
14158
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14146
14159
  }
14147
14160
 
14161
+ setCardValue(field , value ) {
14162
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
14163
+ }
14164
+
14165
+ injectCss(css ) {
14166
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
14167
+ }
14168
+
14169
+ customizeAppearance(themes , translations , assets ) {
14170
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
14171
+ }
14172
+
14148
14173
  _createIframe(cb = () => {}) {
14149
14174
  this.iframe = document.createElement('iframe');
14150
14175
  // $FlowFixMe
@@ -14279,6 +14304,12 @@ class Softphone {
14279
14304
  case BRIDGE_ON_STOP_RECORDING:
14280
14305
  this.onStopRecording();
14281
14306
  break;
14307
+ case BRIDGE_ON_CARD_CANCELED:
14308
+ this.onCardCanceled();
14309
+ break;
14310
+ case BRIDGE_ON_CALL_ANSWERED:
14311
+ this.onCallAnswered();
14312
+ break;
14282
14313
  default:
14283
14314
  this.onUnHandledEvent(event);
14284
14315
  break;
@@ -14286,8 +14317,8 @@ class Softphone {
14286
14317
  }
14287
14318
 
14288
14319
  _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`);
14320
+ if (!this.iframe || !this.iframeLoaded) {
14321
+ this._pendingMessages.push([type, payload]);
14291
14322
  return;
14292
14323
  }
14293
14324