@wazo/sdk 0.38.1 → 0.38.4

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,9 @@ 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_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
13579
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
13580
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
13580
13581
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13581
13582
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13582
13583
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -13590,31 +13591,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
13590
13591
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13591
13592
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13592
13593
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13594
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
13595
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
13596
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
13597
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
13598
+
13599
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
13600
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
13593
13601
 
13594
13602
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
13595
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
13603
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
13596
13604
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
13597
13605
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
13598
13606
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
13599
13607
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
13600
13608
 
13601
13609
  class Softphone {
13602
- url = 'https://softphone.wazo.io';
13603
- width = 500;
13604
- height = 600;
13605
- displayed = false;
13606
- iframe = null;
13610
+
13611
+
13612
+
13613
+
13614
+
13615
+
13616
+
13617
+ // Message waiting for the iframe to be loaded
13618
+
13607
13619
 
13608
13620
  onLinkEnabled(link ) {}
13609
13621
  onIFrameLoaded() {}
13610
13622
 
13611
- onCallMade(call ) {}
13623
+ onCallLocallyAnswered(call ) {}
13624
+ onCallEstablished(call ) {}
13625
+ onOutgoingCallMade(call ) {}
13612
13626
  onCallIncoming(call ) {}
13627
+ onCallRejected(call ) {}
13613
13628
  onCallEnded(call , card , direction , fromExtension ) {}
13629
+
13614
13630
  onCardSaved(card ) {}
13631
+ onCardCanceled() {}
13615
13632
  onAuthenticated(session ) {}
13616
13633
  onLoggedOut() {}
13617
- onSearchOptions(fieldId , query ) {}
13634
+
13635
+ onSearchOptions(fieldId , query ) {
13636
+ this.onOptionsResults(fieldId, []);
13637
+ }
13638
+
13618
13639
  onDisplayLinkedOption(optionId ) {}
13619
13640
  onWazoContactSearch(query ) {}
13620
13641
  onAgentLoggedIn() {}
@@ -13637,18 +13658,26 @@ class Softphone {
13637
13658
  onStopRecording() {}
13638
13659
  onUnHandledEvent(event ) {}
13639
13660
 
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
- }
13661
+ init({
13662
+ url,
13663
+ width,
13664
+ height,
13665
+ server,
13666
+ port,
13667
+ language,
13668
+ wrapUpDuration,
13669
+ enableAgent = true,
13670
+ tenantId,
13671
+ debug = false,
13672
+ } = {}) {
13673
+ this.url = url || 'https://softphone.wazo.io';
13674
+ this.width = width || 500;
13675
+ this.height = height || 600;
13676
+ this.displayed = false;
13677
+ this.iframeLoaded = false;
13651
13678
 
13679
+ this.iframeLoaded = false;
13680
+ this._pendingMessages = [];
13652
13681
  window.addEventListener('message', this._onMessage.bind(this), false);
13653
13682
 
13654
13683
  if (!server) {
@@ -13656,25 +13685,33 @@ class Softphone {
13656
13685
  server = 'stack.dev.wazo.io';
13657
13686
  }
13658
13687
 
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
- });
13688
+ const config = { server };
13689
+ if (language) {
13690
+ config.language = language;
13691
+ }
13692
+ if (port) {
13693
+ config.port = port;
13694
+ }
13695
+ if (tenantId) {
13696
+ config.tenantId = tenantId;
13697
+ }
13698
+ if (wrapUpDuration) {
13699
+ config.wrapUpDuration = wrapUpDuration;
13700
+ }
13670
13701
 
13671
- if (withCard) {
13672
- this._sendMessage(BRIDGE_ENABLE_CARD);
13673
- }
13702
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
13674
13703
 
13675
- if (subscriptionType) {
13676
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
13677
- }
13704
+ if (enableAgent) {
13705
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
13706
+ }
13707
+
13708
+ if (debug) {
13709
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
13710
+ }
13711
+
13712
+ this._createIframe(() => {
13713
+ this.iframeLoaded = true;
13714
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
13678
13715
 
13679
13716
  this.onIFrameLoaded();
13680
13717
  });
@@ -13735,6 +13772,18 @@ class Softphone {
13735
13772
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
13736
13773
  }
13737
13774
 
13775
+ setCardValue(field , value ) {
13776
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
13777
+ }
13778
+
13779
+ injectCss(css ) {
13780
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
13781
+ }
13782
+
13783
+ customizeAppearance(themes , translations , assets ) {
13784
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
13785
+ }
13786
+
13738
13787
  _createIframe(cb = () => {}) {
13739
13788
  this.iframe = document.createElement('iframe');
13740
13789
  // $FlowFixMe
@@ -13780,8 +13829,8 @@ class Softphone {
13780
13829
  }
13781
13830
 
13782
13831
  switch (event.data.type) {
13783
- case SDK_ON_CALL_MADE:
13784
- this.onCallMade(event.data.callSession);
13832
+ case SDK_ON_OUTGOING_CALL_MADE:
13833
+ this.onOutgoingCallMade(event.data.callSession);
13785
13834
  break;
13786
13835
  case SDK_CALL_ENDED: {
13787
13836
  const { callSession, content, direction, userExtension } = event.data;
@@ -13869,6 +13918,18 @@ class Softphone {
13869
13918
  case BRIDGE_ON_STOP_RECORDING:
13870
13919
  this.onStopRecording();
13871
13920
  break;
13921
+ case BRIDGE_ON_CARD_CANCELED:
13922
+ this.onCardCanceled();
13923
+ break;
13924
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
13925
+ this.onCallLocallyAnswered(event.data.call);
13926
+ break;
13927
+ case BRIDGE_ON_CALL_REJECTED:
13928
+ this.onCallRejected(event.data.call);
13929
+ break;
13930
+ case BRIDGE_ON_CALL_ESTABLISHED:
13931
+ this.onCallEstablished(event.data.call);
13932
+ break;
13872
13933
  default:
13873
13934
  this.onUnHandledEvent(event);
13874
13935
  break;
@@ -13876,8 +13937,8 @@ class Softphone {
13876
13937
  }
13877
13938
 
13878
13939
  _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`);
13940
+ if (!this.iframe || !this.iframeLoaded) {
13941
+ this._pendingMessages.push([type, payload]);
13881
13942
  return;
13882
13943
  }
13883
13944
 
@@ -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,9 @@ 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_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
18
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
19
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
19
20
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
20
21
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
21
22
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -29,31 +30,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
29
30
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
30
31
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
31
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';
32
40
 
33
41
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
34
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
42
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
35
43
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
36
44
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
37
45
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
38
46
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
39
47
 
40
48
  class Softphone {
41
- url = 'https://softphone.wazo.io';
42
- width = 500;
43
- height = 600;
44
- displayed = false;
45
- iframe = null;
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+ // Message waiting for the iframe to be loaded
57
+
46
58
 
47
59
  onLinkEnabled(link ) {}
48
60
  onIFrameLoaded() {}
49
61
 
50
- onCallMade(call ) {}
62
+ onCallLocallyAnswered(call ) {}
63
+ onCallEstablished(call ) {}
64
+ onOutgoingCallMade(call ) {}
51
65
  onCallIncoming(call ) {}
66
+ onCallRejected(call ) {}
52
67
  onCallEnded(call , card , direction , fromExtension ) {}
68
+
53
69
  onCardSaved(card ) {}
70
+ onCardCanceled() {}
54
71
  onAuthenticated(session ) {}
55
72
  onLoggedOut() {}
56
- onSearchOptions(fieldId , query ) {}
73
+
74
+ onSearchOptions(fieldId , query ) {
75
+ this.onOptionsResults(fieldId, []);
76
+ }
77
+
57
78
  onDisplayLinkedOption(optionId ) {}
58
79
  onWazoContactSearch(query ) {}
59
80
  onAgentLoggedIn() {}
@@ -76,18 +97,26 @@ class Softphone {
76
97
  onStopRecording() {}
77
98
  onUnHandledEvent(event ) {}
78
99
 
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
- }
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
+ } = {}) {
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;
90
117
 
118
+ this.iframeLoaded = false;
119
+ this._pendingMessages = [];
91
120
  window.addEventListener('message', this._onMessage.bind(this), false);
92
121
 
93
122
  if (!server) {
@@ -95,25 +124,33 @@ class Softphone {
95
124
  server = 'stack.dev.wazo.io';
96
125
  }
97
126
 
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
- }
127
+ const config = { server };
128
+ if (language) {
129
+ config.language = language;
130
+ }
131
+ if (port) {
132
+ config.port = port;
133
+ }
134
+ if (tenantId) {
135
+ config.tenantId = tenantId;
136
+ }
137
+ if (wrapUpDuration) {
138
+ config.wrapUpDuration = wrapUpDuration;
139
+ }
113
140
 
114
- if (subscriptionType) {
115
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
116
- }
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
+ }
150
+
151
+ this._createIframe(() => {
152
+ this.iframeLoaded = true;
153
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
117
154
 
118
155
  this.onIFrameLoaded();
119
156
  });
@@ -174,6 +211,18 @@ class Softphone {
174
211
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
175
212
  }
176
213
 
214
+ setCardValue(field , value ) {
215
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
216
+ }
217
+
218
+ injectCss(css ) {
219
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
220
+ }
221
+
222
+ customizeAppearance(themes , translations , assets ) {
223
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
224
+ }
225
+
177
226
  _createIframe(cb = () => {}) {
178
227
  this.iframe = document.createElement('iframe');
179
228
  // $FlowFixMe
@@ -219,8 +268,8 @@ class Softphone {
219
268
  }
220
269
 
221
270
  switch (event.data.type) {
222
- case SDK_ON_CALL_MADE:
223
- this.onCallMade(event.data.callSession);
271
+ case SDK_ON_OUTGOING_CALL_MADE:
272
+ this.onOutgoingCallMade(event.data.callSession);
224
273
  break;
225
274
  case SDK_CALL_ENDED: {
226
275
  const { callSession, content, direction, userExtension } = event.data;
@@ -308,6 +357,18 @@ class Softphone {
308
357
  case BRIDGE_ON_STOP_RECORDING:
309
358
  this.onStopRecording();
310
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_ESTABLISHED:
370
+ this.onCallEstablished(event.data.call);
371
+ break;
311
372
  default:
312
373
  this.onUnHandledEvent(event);
313
374
  break;
@@ -315,8 +376,8 @@ class Softphone {
315
376
  }
316
377
 
317
378
  _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`);
379
+ if (!this.iframe || !this.iframeLoaded) {
380
+ this._pendingMessages.push([type, payload]);
320
381
  return;
321
382
  }
322
383
 
@@ -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,9 @@ 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_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
13989
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
13990
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
13990
13991
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13991
13992
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13992
13993
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -14000,31 +14001,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
14000
14001
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
14001
14002
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
14002
14003
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
14004
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
14005
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
14006
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
14007
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
14008
+
14009
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
14010
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
14003
14011
 
14004
14012
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
14005
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
14013
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
14006
14014
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
14007
14015
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
14008
14016
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14009
14017
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
14010
14018
 
14011
14019
  class Softphone {
14012
- url = 'https://softphone.wazo.io';
14013
- width = 500;
14014
- height = 600;
14015
- displayed = false;
14016
- iframe = null;
14020
+
14021
+
14022
+
14023
+
14024
+
14025
+
14026
+
14027
+ // Message waiting for the iframe to be loaded
14028
+
14017
14029
 
14018
14030
  onLinkEnabled(link ) {}
14019
14031
  onIFrameLoaded() {}
14020
14032
 
14021
- onCallMade(call ) {}
14033
+ onCallLocallyAnswered(call ) {}
14034
+ onCallEstablished(call ) {}
14035
+ onOutgoingCallMade(call ) {}
14022
14036
  onCallIncoming(call ) {}
14037
+ onCallRejected(call ) {}
14023
14038
  onCallEnded(call , card , direction , fromExtension ) {}
14039
+
14024
14040
  onCardSaved(card ) {}
14041
+ onCardCanceled() {}
14025
14042
  onAuthenticated(session ) {}
14026
14043
  onLoggedOut() {}
14027
- onSearchOptions(fieldId , query ) {}
14044
+
14045
+ onSearchOptions(fieldId , query ) {
14046
+ this.onOptionsResults(fieldId, []);
14047
+ }
14048
+
14028
14049
  onDisplayLinkedOption(optionId ) {}
14029
14050
  onWazoContactSearch(query ) {}
14030
14051
  onAgentLoggedIn() {}
@@ -14047,18 +14068,26 @@ class Softphone {
14047
14068
  onStopRecording() {}
14048
14069
  onUnHandledEvent(event ) {}
14049
14070
 
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
- }
14071
+ init({
14072
+ url,
14073
+ width,
14074
+ height,
14075
+ server,
14076
+ port,
14077
+ language,
14078
+ wrapUpDuration,
14079
+ enableAgent = true,
14080
+ tenantId,
14081
+ debug = false,
14082
+ } = {}) {
14083
+ this.url = url || 'https://softphone.wazo.io';
14084
+ this.width = width || 500;
14085
+ this.height = height || 600;
14086
+ this.displayed = false;
14087
+ this.iframeLoaded = false;
14061
14088
 
14089
+ this.iframeLoaded = false;
14090
+ this._pendingMessages = [];
14062
14091
  window.addEventListener('message', this._onMessage.bind(this), false);
14063
14092
 
14064
14093
  if (!server) {
@@ -14066,25 +14095,33 @@ class Softphone {
14066
14095
  server = 'stack.dev.wazo.io';
14067
14096
  }
14068
14097
 
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
- });
14098
+ const config = { server };
14099
+ if (language) {
14100
+ config.language = language;
14101
+ }
14102
+ if (port) {
14103
+ config.port = port;
14104
+ }
14105
+ if (tenantId) {
14106
+ config.tenantId = tenantId;
14107
+ }
14108
+ if (wrapUpDuration) {
14109
+ config.wrapUpDuration = wrapUpDuration;
14110
+ }
14080
14111
 
14081
- if (withCard) {
14082
- this._sendMessage(BRIDGE_ENABLE_CARD);
14083
- }
14112
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
14084
14113
 
14085
- if (subscriptionType) {
14086
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
14087
- }
14114
+ if (enableAgent) {
14115
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
14116
+ }
14117
+
14118
+ if (debug) {
14119
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
14120
+ }
14121
+
14122
+ this._createIframe(() => {
14123
+ this.iframeLoaded = true;
14124
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
14088
14125
 
14089
14126
  this.onIFrameLoaded();
14090
14127
  });
@@ -14145,6 +14182,18 @@ class Softphone {
14145
14182
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14146
14183
  }
14147
14184
 
14185
+ setCardValue(field , value ) {
14186
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
14187
+ }
14188
+
14189
+ injectCss(css ) {
14190
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
14191
+ }
14192
+
14193
+ customizeAppearance(themes , translations , assets ) {
14194
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
14195
+ }
14196
+
14148
14197
  _createIframe(cb = () => {}) {
14149
14198
  this.iframe = document.createElement('iframe');
14150
14199
  // $FlowFixMe
@@ -14190,8 +14239,8 @@ class Softphone {
14190
14239
  }
14191
14240
 
14192
14241
  switch (event.data.type) {
14193
- case SDK_ON_CALL_MADE:
14194
- this.onCallMade(event.data.callSession);
14242
+ case SDK_ON_OUTGOING_CALL_MADE:
14243
+ this.onOutgoingCallMade(event.data.callSession);
14195
14244
  break;
14196
14245
  case SDK_CALL_ENDED: {
14197
14246
  const { callSession, content, direction, userExtension } = event.data;
@@ -14279,6 +14328,18 @@ class Softphone {
14279
14328
  case BRIDGE_ON_STOP_RECORDING:
14280
14329
  this.onStopRecording();
14281
14330
  break;
14331
+ case BRIDGE_ON_CARD_CANCELED:
14332
+ this.onCardCanceled();
14333
+ break;
14334
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
14335
+ this.onCallLocallyAnswered(event.data.call);
14336
+ break;
14337
+ case BRIDGE_ON_CALL_REJECTED:
14338
+ this.onCallRejected(event.data.call);
14339
+ break;
14340
+ case BRIDGE_ON_CALL_ESTABLISHED:
14341
+ this.onCallEstablished(event.data.call);
14342
+ break;
14282
14343
  default:
14283
14344
  this.onUnHandledEvent(event);
14284
14345
  break;
@@ -14286,8 +14347,8 @@ class Softphone {
14286
14347
  }
14287
14348
 
14288
14349
  _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`);
14350
+ if (!this.iframe || !this.iframeLoaded) {
14351
+ this._pendingMessages.push([type, payload]);
14291
14352
  return;
14292
14353
  }
14293
14354