@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.
@@ -13969,8 +13969,6 @@ class Checker {
13969
13969
  /* eslint-disable no-unused-vars */
13970
13970
  /* global window, document */
13971
13971
  const BRIDGE_CONFIG_RETRIEVED = 'bridge/CONFIG_RETRIEVED';
13972
- const BRIDGE_ENABLE_CARD = 'bridge/ENABLE_CARD';
13973
- const BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE = 'bridge/CHANGE_REQUIRED_SUBSCRIPTION_TYPE';
13974
13972
  const BRIDGE_CREATE_OR_UPDATE_CARD = 'bridge/BRIDGE_CREATE_OR_UPDATE_CARD';
13975
13973
  const BRIDGE_OPTIONS_FETCHED = 'bridge/BRIDGE_OPTIONS_FETCHED';
13976
13974
  const BRIDGE_OPTIONS_FOUND = 'bridge/BRIDGE_OPTIONS_FOUND';
@@ -13983,6 +13981,7 @@ const BRIDGE_ON_AGENT_LOGGED_OUT = 'bridge/BRIDGE_ON_AGENT_LOGGED_OUT';
13983
13981
  const BRIDGE_ON_AGENT_PAUSED = 'bridge/BRIDGE_ON_AGENT_PAUSED';
13984
13982
  const BRIDGE_ON_AGENT_RESUMED = 'bridge/BRIDGE_ON_AGENT_RESUMED';
13985
13983
  const BRIDGE_ON_LANGUAGE_CHANGED = 'bridge/BRIDGE_ON_LANGUAGE_CHANGED';
13984
+ const BRIDGE_ON_CALL_ANSWERED = 'bridge/BRIDGE_ON_CALL_ANSWERED';
13986
13985
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13987
13986
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13988
13987
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -13996,6 +13995,12 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
13996
13995
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13997
13996
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13998
13997
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
13998
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
13999
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
14000
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
14001
+
14002
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
14003
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
13999
14004
 
14000
14005
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
14001
14006
  const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
@@ -14005,22 +14010,32 @@ const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14005
14010
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
14006
14011
 
14007
14012
  class Softphone {
14008
- url = 'https://softphone.wazo.io';
14009
- width = 500;
14010
- height = 600;
14011
- displayed = false;
14012
- iframe = null;
14013
+
14014
+
14015
+
14016
+
14017
+
14018
+
14019
+
14020
+ // Message waiting for the iframe to be loaded
14021
+
14013
14022
 
14014
14023
  onLinkEnabled(link ) {}
14015
14024
  onIFrameLoaded() {}
14016
14025
 
14026
+ onCallAnswered() {}
14017
14027
  onCallMade(call ) {}
14018
14028
  onCallIncoming(call ) {}
14019
14029
  onCallEnded(call , card , direction , fromExtension ) {}
14020
14030
  onCardSaved(card ) {}
14031
+ onCardCanceled() {}
14021
14032
  onAuthenticated(session ) {}
14022
14033
  onLoggedOut() {}
14023
- onSearchOptions(fieldId , query ) {}
14034
+
14035
+ onSearchOptions(fieldId , query ) {
14036
+ this.onOptionsResults(fieldId, []);
14037
+ }
14038
+
14024
14039
  onDisplayLinkedOption(optionId ) {}
14025
14040
  onWazoContactSearch(query ) {}
14026
14041
  onAgentLoggedIn() {}
@@ -14043,18 +14058,15 @@ class Softphone {
14043
14058
  onStopRecording() {}
14044
14059
  onUnHandledEvent(event ) {}
14045
14060
 
14046
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
14047
- allowContactCreation, withCard, subscriptionType, enableAgent } = {}) {
14048
- if (url) {
14049
- this.url = url;
14050
- }
14051
- if (width) {
14052
- this.width = width;
14053
- }
14054
- if (height) {
14055
- this.height = height;
14056
- }
14061
+ init({ url, width, height, server, port, language, wrapUpDuration, enableAgent = true } = {}) {
14062
+ this.url = url || 'https://softphone.wazo.io';
14063
+ this.width = width || 500;
14064
+ this.height = height || 600;
14065
+ this.displayed = false;
14066
+ this.iframeLoaded = false;
14057
14067
 
14068
+ this.iframeLoaded = false;
14069
+ this._pendingMessages = [];
14058
14070
  window.addEventListener('message', this._onMessage.bind(this), false);
14059
14071
 
14060
14072
  if (!server) {
@@ -14062,25 +14074,26 @@ class Softphone {
14062
14074
  server = 'stack.dev.wazo.io';
14063
14075
  }
14064
14076
 
14065
- this._createIframe(() => {
14066
- this._sendMessage(BRIDGE_CONFIG_RETRIEVED, {
14067
- config: {
14068
- server,
14069
- port,
14070
- language,
14071
- wrapUpDuration,
14072
- shouldDisplayLinkedEntities,
14073
- allowContactCreation,
14074
- },
14075
- });
14077
+ const config = { server };
14078
+ if (language) {
14079
+ config.language = language;
14080
+ }
14081
+ if (port) {
14082
+ config.port = port;
14083
+ }
14084
+ if (wrapUpDuration) {
14085
+ config.wrapUpDuration = wrapUpDuration;
14086
+ }
14076
14087
 
14077
- if (withCard) {
14078
- this._sendMessage(BRIDGE_ENABLE_CARD);
14079
- }
14088
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
14080
14089
 
14081
- if (subscriptionType) {
14082
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
14083
- }
14090
+ if (enableAgent) {
14091
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
14092
+ }
14093
+
14094
+ this._createIframe(() => {
14095
+ this.iframeLoaded = true;
14096
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
14084
14097
 
14085
14098
  this.onIFrameLoaded();
14086
14099
  });
@@ -14141,6 +14154,18 @@ class Softphone {
14141
14154
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14142
14155
  }
14143
14156
 
14157
+ setCardValue(field , value ) {
14158
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
14159
+ }
14160
+
14161
+ injectCss(css ) {
14162
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
14163
+ }
14164
+
14165
+ customizeAppearance(themes , translations , assets ) {
14166
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
14167
+ }
14168
+
14144
14169
  _createIframe(cb = () => {}) {
14145
14170
  this.iframe = document.createElement('iframe');
14146
14171
  // $FlowFixMe
@@ -14275,6 +14300,12 @@ class Softphone {
14275
14300
  case BRIDGE_ON_STOP_RECORDING:
14276
14301
  this.onStopRecording();
14277
14302
  break;
14303
+ case BRIDGE_ON_CARD_CANCELED:
14304
+ this.onCardCanceled();
14305
+ break;
14306
+ case BRIDGE_ON_CALL_ANSWERED:
14307
+ this.onCallAnswered();
14308
+ break;
14278
14309
  default:
14279
14310
  this.onUnHandledEvent(event);
14280
14311
  break;
@@ -14282,8 +14313,8 @@ class Softphone {
14282
14313
  }
14283
14314
 
14284
14315
  _sendMessage(type , payload = {}) {
14285
- if (!this.iframe) {
14286
- console.warn(`Could not send message of type ${type} to the Wazo Softphone, iframe not created yet`);
14316
+ if (!this.iframe || !this.iframeLoaded) {
14317
+ this._pendingMessages.push([type, payload]);
14287
14318
  return;
14288
14319
  }
14289
14320
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wazo/sdk",
3
- "version": "0.38.1",
3
+ "version": "0.38.2",
4
4
  "description": "Wazo's JavaScript Software Development Kit.",
5
5
  "main": "dist/wazo-sdk.js",
6
6
  "author": "Wazo (http://wazo.io)",
@@ -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: string = 'https://softphone.wazo.io';
42
- width: number = 500;
43
- height: number = 600;
44
- displayed: boolean = false;
45
- iframe: ?Object = null;
46
+ url: string;
47
+ width: number;
48
+ height: number;
49
+ displayed: boolean;
50
+ iframe: ?Object;
51
+ iframeLoaded: boolean;
52
+
53
+ // Message waiting for the iframe to be loaded
54
+ _pendingMessages: Object[];
46
55
 
47
56
  onLinkEnabled(link: Object) {}
48
57
  onIFrameLoaded() {}
49
58
 
59
+ onCallAnswered() {}
50
60
  onCallMade(call: Object) {}
51
61
  onCallIncoming(call: Object) {}
52
62
  onCallEnded(call: Object, card: Object, direction: string, fromExtension: string) {}
53
63
  onCardSaved(card: Object) {}
64
+ onCardCanceled() {}
54
65
  onAuthenticated(session: Object) {}
55
66
  onLoggedOut() {}
56
- onSearchOptions(fieldId: string, query: string) {}
67
+
68
+ onSearchOptions(fieldId: string, query: string) {
69
+ this.onOptionsResults(fieldId, []);
70
+ }
71
+
57
72
  onDisplayLinkedOption(optionId: string) {}
58
73
  onWazoContactSearch(query: string) {}
59
74
  onAgentLoggedIn() {}
@@ -76,18 +91,15 @@ class Softphone {
76
91
  onStopRecording() {}
77
92
  onUnHandledEvent(event: Object) {}
78
93
 
79
- init({ url, width, height, server, port, language, wrapUpDuration, shouldDisplayLinkedEntities,
80
- allowContactCreation, withCard, subscriptionType, enableAgent }: Object = {}) {
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 }: Object = {}) {
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: Object = { 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: string, value: any) {
191
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
192
+ }
193
+
194
+ injectCss(css: string) {
195
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
196
+ }
197
+
198
+ customizeAppearance(themes: Object, translations: Object, assets: Object) {
199
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
200
+ }
201
+
177
202
  _createIframe(cb: Function = () => {}) {
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: 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`);
349
+ if (!this.iframe || !this.iframeLoaded) {
350
+ this._pendingMessages.push([type, payload]);
320
351
  return;
321
352
  }
322
353