@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.
@@ -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,9 @@ 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_LOCALLY_ACCEPTED = 'bridge/BRIDGE_ON_CALL_LOCALLY_ACCEPTED';
13985
+ const BRIDGE_ON_CALL_REJECTED = 'bridge/BRIDGE_ON_CALL_REJECTED';
13986
+ const BRIDGE_ON_CALL_ESTABLISHED = 'bridge/BRIDGE_ON_CALL_ESTABLISHED';
13986
13987
  const BRIDGE_ON_CALL_HELD = 'bridge/BRIDGE_ON_CALL_HELD';
13987
13988
  const BRIDGE_ON_CALL_RESUMED = 'bridge/BRIDGE_ON_CALL_RESUMED';
13988
13989
  const BRIDGE_ON_CALL_MUTED = 'bridge/BRIDGE_ON_CALL_MUTED';
@@ -13996,31 +13997,51 @@ const BRIDGE_ON_INDIRECT_TRANSFER_CALL_MADE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFE
13996
13997
  const BRIDGE_ON_INDIRECT_TRANSFER_DONE = 'bridge/BRIDGE_ON_INDIRECT_TRANSFER_DONE';
13997
13998
  const BRIDGE_ON_START_RECORDING = 'bridge/BRIDGE_ON_START_RECORDING';
13998
13999
  const BRIDGE_ON_STOP_RECORDING = 'bridge/BRIDGE_ON_STOP_RECORDING';
14000
+ const BRIDGE_ON_CARD_CANCELED = 'bridge/BRIDGE_ON_CARD_CANCELED';
14001
+ const BRIDGE_ENABLE_AGENT = 'bridge/BRIDGE_ENABLE_AGENT';
14002
+ const BRIDGE_SET_CARD_CONTENT = 'bridge/BRIDGE_SET_CARD_CONTENT';
14003
+ const BRIDGE_ENABLE_DEBUG = 'bridge/BRIDGE_ENABLE_DEBUG';
14004
+
14005
+ const BRIDGE_INJECT_CSS = 'bridge/BRIDGE_INJECT_CSS';
14006
+ const BRIDGE_CUSTOMIZE_APPEARANCE = 'bridge/BRIDGE_CUSTOMIZE_APPEARANCE';
13999
14007
 
14000
14008
  const SDK_CLICK_TO_CALL = 'sdk/CLICK_TO_CALL';
14001
- const SDK_ON_CALL_MADE = 'sdk/SDK_ON_CALL_MADE';
14009
+ const SDK_ON_OUTGOING_CALL_MADE = 'sdk/SDK_ON_OUTGOING_CALL_MADE';
14002
14010
  const SDK_CALL_ENDED = 'sdk/ON_CALL_ENDED';
14003
14011
  const SDK_CALL_INCOMING = 'sdk/SDK_CALL_INCOMING';
14004
14012
  const SDK_AUTHENTICATED = 'sdk/SDK_AUTHENTICATED';
14005
14013
  const SDK_LOGGED_OUT = 'sdk/SDK_LOGGED_OUT';
14006
14014
 
14007
14015
  class Softphone {
14008
- url = 'https://softphone.wazo.io';
14009
- width = 500;
14010
- height = 600;
14011
- displayed = false;
14012
- iframe = null;
14016
+
14017
+
14018
+
14019
+
14020
+
14021
+
14022
+
14023
+ // Message waiting for the iframe to be loaded
14024
+
14013
14025
 
14014
14026
  onLinkEnabled(link ) {}
14015
14027
  onIFrameLoaded() {}
14016
14028
 
14017
- onCallMade(call ) {}
14029
+ onCallLocallyAnswered(call ) {}
14030
+ onCallEstablished(call ) {}
14031
+ onOutgoingCallMade(call ) {}
14018
14032
  onCallIncoming(call ) {}
14033
+ onCallRejected(call ) {}
14019
14034
  onCallEnded(call , card , direction , fromExtension ) {}
14035
+
14020
14036
  onCardSaved(card ) {}
14037
+ onCardCanceled() {}
14021
14038
  onAuthenticated(session ) {}
14022
14039
  onLoggedOut() {}
14023
- onSearchOptions(fieldId , query ) {}
14040
+
14041
+ onSearchOptions(fieldId , query ) {
14042
+ this.onOptionsResults(fieldId, []);
14043
+ }
14044
+
14024
14045
  onDisplayLinkedOption(optionId ) {}
14025
14046
  onWazoContactSearch(query ) {}
14026
14047
  onAgentLoggedIn() {}
@@ -14043,18 +14064,26 @@ class Softphone {
14043
14064
  onStopRecording() {}
14044
14065
  onUnHandledEvent(event ) {}
14045
14066
 
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
- }
14067
+ init({
14068
+ url,
14069
+ width,
14070
+ height,
14071
+ server,
14072
+ port,
14073
+ language,
14074
+ wrapUpDuration,
14075
+ enableAgent = true,
14076
+ tenantId,
14077
+ debug = false,
14078
+ } = {}) {
14079
+ this.url = url || 'https://softphone.wazo.io';
14080
+ this.width = width || 500;
14081
+ this.height = height || 600;
14082
+ this.displayed = false;
14083
+ this.iframeLoaded = false;
14057
14084
 
14085
+ this.iframeLoaded = false;
14086
+ this._pendingMessages = [];
14058
14087
  window.addEventListener('message', this._onMessage.bind(this), false);
14059
14088
 
14060
14089
  if (!server) {
@@ -14062,25 +14091,33 @@ class Softphone {
14062
14091
  server = 'stack.dev.wazo.io';
14063
14092
  }
14064
14093
 
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
- });
14094
+ const config = { server };
14095
+ if (language) {
14096
+ config.language = language;
14097
+ }
14098
+ if (port) {
14099
+ config.port = port;
14100
+ }
14101
+ if (tenantId) {
14102
+ config.tenantId = tenantId;
14103
+ }
14104
+ if (wrapUpDuration) {
14105
+ config.wrapUpDuration = wrapUpDuration;
14106
+ }
14076
14107
 
14077
- if (withCard) {
14078
- this._sendMessage(BRIDGE_ENABLE_CARD);
14079
- }
14108
+ this._sendMessage(BRIDGE_CONFIG_RETRIEVED, { config });
14080
14109
 
14081
- if (subscriptionType) {
14082
- this._sendMessage(BRIDGE_CHANGE_REQUIRED_SUBSCRIPTION_TYPE, { subscriptionType });
14083
- }
14110
+ if (enableAgent) {
14111
+ this._sendMessage(BRIDGE_ENABLE_AGENT);
14112
+ }
14113
+
14114
+ if (debug) {
14115
+ this._sendMessage(BRIDGE_ENABLE_DEBUG);
14116
+ }
14117
+
14118
+ this._createIframe(() => {
14119
+ this.iframeLoaded = true;
14120
+ this._pendingMessages.forEach(([type, payload]) => this._sendMessage(type, payload));
14084
14121
 
14085
14122
  this.onIFrameLoaded();
14086
14123
  });
@@ -14141,6 +14178,18 @@ class Softphone {
14141
14178
  this._sendMessage(BRIDGE_UPDATE_FORM_SCHEMA, { schema, uiSchema });
14142
14179
  }
14143
14180
 
14181
+ setCardValue(field , value ) {
14182
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
14183
+ }
14184
+
14185
+ injectCss(css ) {
14186
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
14187
+ }
14188
+
14189
+ customizeAppearance(themes , translations , assets ) {
14190
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
14191
+ }
14192
+
14144
14193
  _createIframe(cb = () => {}) {
14145
14194
  this.iframe = document.createElement('iframe');
14146
14195
  // $FlowFixMe
@@ -14186,8 +14235,8 @@ class Softphone {
14186
14235
  }
14187
14236
 
14188
14237
  switch (event.data.type) {
14189
- case SDK_ON_CALL_MADE:
14190
- this.onCallMade(event.data.callSession);
14238
+ case SDK_ON_OUTGOING_CALL_MADE:
14239
+ this.onOutgoingCallMade(event.data.callSession);
14191
14240
  break;
14192
14241
  case SDK_CALL_ENDED: {
14193
14242
  const { callSession, content, direction, userExtension } = event.data;
@@ -14275,6 +14324,18 @@ class Softphone {
14275
14324
  case BRIDGE_ON_STOP_RECORDING:
14276
14325
  this.onStopRecording();
14277
14326
  break;
14327
+ case BRIDGE_ON_CARD_CANCELED:
14328
+ this.onCardCanceled();
14329
+ break;
14330
+ case BRIDGE_ON_CALL_LOCALLY_ACCEPTED:
14331
+ this.onCallLocallyAnswered(event.data.call);
14332
+ break;
14333
+ case BRIDGE_ON_CALL_REJECTED:
14334
+ this.onCallRejected(event.data.call);
14335
+ break;
14336
+ case BRIDGE_ON_CALL_ESTABLISHED:
14337
+ this.onCallEstablished(event.data.call);
14338
+ break;
14278
14339
  default:
14279
14340
  this.onUnHandledEvent(event);
14280
14341
  break;
@@ -14282,8 +14343,8 @@ class Softphone {
14282
14343
  }
14283
14344
 
14284
14345
  _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`);
14346
+ if (!this.iframe || !this.iframeLoaded) {
14347
+ this._pendingMessages.push([type, payload]);
14287
14348
  return;
14288
14349
  }
14289
14350
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wazo/sdk",
3
- "version": "0.38.1",
3
+ "version": "0.38.4",
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,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: string = 'https://softphone.wazo.io';
42
- width: number = 500;
43
- height: number = 600;
44
- displayed: boolean = false;
45
- iframe: ?Object = null;
49
+ url: string;
50
+ width: number;
51
+ height: number;
52
+ displayed: boolean;
53
+ iframe: ?Object;
54
+ iframeLoaded: boolean;
55
+
56
+ // Message waiting for the iframe to be loaded
57
+ _pendingMessages: Object[];
46
58
 
47
59
  onLinkEnabled(link: Object) {}
48
60
  onIFrameLoaded() {}
49
61
 
50
- onCallMade(call: Object) {}
62
+ onCallLocallyAnswered(call: Object) {}
63
+ onCallEstablished(call: Object) {}
64
+ onOutgoingCallMade(call: Object) {}
51
65
  onCallIncoming(call: Object) {}
66
+ onCallRejected(call: Object) {}
52
67
  onCallEnded(call: Object, card: Object, direction: string, fromExtension: string) {}
68
+
53
69
  onCardSaved(card: Object) {}
70
+ onCardCanceled() {}
54
71
  onAuthenticated(session: Object) {}
55
72
  onLoggedOut() {}
56
- onSearchOptions(fieldId: string, query: string) {}
73
+
74
+ onSearchOptions(fieldId: string, query: string) {
75
+ this.onOptionsResults(fieldId, []);
76
+ }
77
+
57
78
  onDisplayLinkedOption(optionId: string) {}
58
79
  onWazoContactSearch(query: string) {}
59
80
  onAgentLoggedIn() {}
@@ -76,18 +97,26 @@ class Softphone {
76
97
  onStopRecording() {}
77
98
  onUnHandledEvent(event: Object) {}
78
99
 
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
- }
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
+ }: Object = {}) {
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: Object = { 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: string, value: any) {
215
+ this._sendMessage(BRIDGE_SET_CARD_CONTENT, { field, value });
216
+ }
217
+
218
+ injectCss(css: string) {
219
+ this._sendMessage(BRIDGE_INJECT_CSS, { css });
220
+ }
221
+
222
+ customizeAppearance(themes: Object, translations: Object, assets: Object) {
223
+ this._sendMessage(BRIDGE_CUSTOMIZE_APPEARANCE, { themes, translations, assets });
224
+ }
225
+
177
226
  _createIframe(cb: Function = () => {}) {
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: 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`);
379
+ if (!this.iframe || !this.iframeLoaded) {
380
+ this._pendingMessages.push([type, payload]);
320
381
  return;
321
382
  }
322
383