@voicenter-team/events-sdk 0.0.118 → 0.0.119
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.
- package/README.md +337 -337
- package/dist/voicenter-events-sdk.cjs.js +11 -11
- package/dist/voicenter-events-sdk.cjs.js.map +1 -1
- package/dist/voicenter-events-sdk.d.ts +2 -234
- package/dist/voicenter-events-sdk.es.js +472 -468
- package/dist/voicenter-events-sdk.es.js.map +1 -1
- package/dist/voicenter-events-sdk.iife.js +8 -8
- package/dist/voicenter-events-sdk.iife.js.map +1 -1
- package/dist/voicenter-events-sdk.umd.js +8 -8
- package/dist/voicenter-events-sdk.umd.js.map +1 -1
- package/package.json +64 -64
package/README.md
CHANGED
|
@@ -1,338 +1,338 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Voicenter Events SDK
|
|
3
|
-
description: Voicenter Events SDK aims to manage API and socket communication with Voicenter APIs and backends.
|
|
4
|
-
You can use the SDK to send and receive real-time data from and to voicenter servers.
|
|
5
|
-
navigation:
|
|
6
|
-
title: Getting Started
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# Voicenter Events SDK
|
|
10
|
-
|
|
11
|
-

|
|
12
|
-
|
|
13
|
-
The events sdk is a small sdk that handles real time communication with our servers.
|
|
14
|
-
The SDK has automatic server failover and fallback integrated as well as different utilities such as debug mode to easily visualize what's happening in the console.
|
|
15
|
-
The SDK uses websockets to manage real time bi-directional communication with our servers and it's meant to simplify developer work.
|
|
16
|
-
|
|
17
|
-
## Getting Started
|
|
18
|
-
|
|
19
|
-
The Events SDK should be used to communicate with Voicenter servers in order to receive real-time data via sockets. Underneath, the events SDK uses socket.io to send and receive events.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
### Table of contents
|
|
23
|
-
|
|
24
|
-
1. [Instalation](#instalation)
|
|
25
|
-
2. [Usage](#usage)
|
|
26
|
-
3. [Public methods](#use-the-public-methods-to-send-and-receive-events)
|
|
27
|
-
4. [Pass vuex store](#pass-vuex-store)
|
|
28
|
-
5. [Other Methods](#other-methods)
|
|
29
|
-
1. [Set token](#set-token)
|
|
30
|
-
2. [Resync](#resync)
|
|
31
|
-
3. [Set monitor url](#set-monitor-url)
|
|
32
|
-
4. [Login with user](#login-with-user)
|
|
33
|
-
5. [Login with account](#login-with-account)
|
|
34
|
-
6. [Login with code](#login-with-code)
|
|
35
|
-
7. [Disconnect](#disconnect)
|
|
36
|
-
6. [Initializing new instance](#initializing-new-instance)
|
|
37
|
-
7. [Required params](#required-params)
|
|
38
|
-
8. [Initing an instance](#initing-an-instance)
|
|
39
|
-
9. [Events you can subscribe to](#events-you-can-subscribe-to)
|
|
40
|
-
10. [HTML Example](#html-example)
|
|
41
|
-
|
|
42
|
-
## Instalation
|
|
43
|
-
1. Direct Download / CDN:
|
|
44
|
-
|
|
45
|
-
Include voicenter-events-sdk after Vue and it will install itself automatically:
|
|
46
|
-
```html [index.html]
|
|
47
|
-
<script src="https://voicentercdn-voicenterltd.netdna-ssl.com/cdn/events-sdk/voicenter-events-sdk.umd.js"></script>
|
|
48
|
-
```
|
|
49
|
-
2. NPM:
|
|
50
|
-
```sh [Terminal]
|
|
51
|
-
$ npm install voicenter-events-sdk
|
|
52
|
-
```
|
|
53
|
-
3. Yarn:
|
|
54
|
-
```sh [Terminal]
|
|
55
|
-
$ yarn add voicenter-events-sdk
|
|
56
|
-
```
|
|
57
|
-
You don't need to do this when using global script tags.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
## Usage
|
|
61
|
-
You can initialize and use it to send and receive events to and from our servers.
|
|
62
|
-
- Initialize the constructor with a monitorCode
|
|
63
|
-
```js [file.js]
|
|
64
|
-
import EventsSDK from 'voicenter-events-sdk'
|
|
65
|
-
let sdk = new EventsSDK({
|
|
66
|
-
token: this.monitorCode,
|
|
67
|
-
// other options here
|
|
68
|
-
});
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
- Alternatively when loaded directly via CDN
|
|
72
|
-
```js [file.js]
|
|
73
|
-
let sdk = new window.VoicenterEventsSDK({
|
|
74
|
-
token: this.monitorCode,
|
|
75
|
-
// other options here
|
|
76
|
-
});
|
|
77
|
-
```
|
|
78
|
-
- Call the init method to initialize the server connections
|
|
79
|
-
```js [file.js]
|
|
80
|
-
sdk.init().then(() => {}) //sdk is initialized after promise is fulfilled
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
This step is important as we have an algorithm that retrieves multiple servers and has a failover mechanism behind it. Skipping this step, will throw error(s) in the subsequent steps.
|
|
84
|
-
|
|
85
|
-
## Use the public methods to send and receive events
|
|
86
|
-
- Subscribe to all events
|
|
87
|
-
```js [file.js]
|
|
88
|
-
sdk.on('*', data => {
|
|
89
|
-
// handle data here. Data format -> {name: 'event name', data: {}}
|
|
90
|
-
});
|
|
91
|
-
```
|
|
92
|
-
- Subscribe to specific events
|
|
93
|
-
```js [file.js]
|
|
94
|
-
sdk.on('ExtensionEvent', data => {
|
|
95
|
-
// handle ExtensionEvent here
|
|
96
|
-
});
|
|
97
|
-
```
|
|
98
|
-
- Emit events
|
|
99
|
-
```js [file.js]
|
|
100
|
-
sdk.emit('event name', { key: 'value' });
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
## Pass vuex store
|
|
104
|
-
Passing a vuex store will automatically register a vuex module and save extensions in it. This is useful if you use vuex and don't want to handle all the extension events yourself but rather use the sdk vuex module. [Open Vue Devtools](https://chrome.google.com/webstore/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd?hl=en) and see the `sdkExtensions` vuex module and its state/getters.
|
|
105
|
-
|
|
106
|
-
#### Options
|
|
107
|
-
The SDK constructor accepts multiple options when initializing which can be used to configure/tweak the SDK behaviour.
|
|
108
|
-
|
|
109
|
-
| Option | Type | Default | Description |
|
|
110
|
-
|-----------|---------------|---------------|---------------|
|
|
111
|
-
| token | String | Null | Monitor code token to use for login |
|
|
112
|
-
| user | String | Can be used to login with "user" or "account" login type | |
|
|
113
|
-
| password | String | Used for login with "user" or "account" login type. Must be used together with user property | |
|
|
114
|
-
| code | String | Code to be used for login with "code" type. Should be used with "organizationCode" code | |
|
|
115
|
-
| organizationCode | String | Organization code to be used for login with "code" type. Should be used with "organizationCode" code | |
|
|
116
|
-
| debug | Boolean | false | When set to true, it will print debug information to console |
|
|
117
|
-
| reconnectionDelay | Number | 10000 | First reconnection delay in milliseconds. Defaults to 10 seconds and increases with each retry (retryCount * reconnectionDelay) |
|
|
118
|
-
| timeout | Number | 10000 | Login timeout. Will throw an error if no event is sent back based on the emitted login event |
|
|
119
|
-
| protocol | String | https | Protocol to use when connecting via sockets with the server |
|
|
120
|
-
| keepAliveTimeout | Number | 60000 | Timeout after which a keep alive event is sent |
|
|
121
|
-
| idleInterval | Number | 60000 * 5 | Interval after which resync event is sent |
|
|
122
|
-
| transports | Array | ['websocket'] | Available transports. It's desired to leave this setting as it is. |
|
|
123
|
-
| upgrade | Boolean | false | Available transports. It's desired to leave this setting as it is. |
|
|
124
|
-
| serverType | Number | Null | Optional parameter to be passed to API call that retrieves available servers. Can be 1 or 2. 2 should be used for chrome extension. |
|
|
125
|
-
| url | string | https://monitorapi.voicenter.co.il/monitorAPI/getMonitorUrls | Url from which to get monitor urls. |
|
|
126
|
-
| servers | Array | contains 5 default servers | Contains a list of real-time servers with priorities and versions. Please check src/config.js file to see the exact format. |
|
|
127
|
-
| serverFetchStrategy | string | Determines the strategy how monitor servers are initiated. Can be remote (server urls are retrieved from a remote url) or static where server urls are specified directly through config. In case remote call fails, it will fallback to the default list of servers or the ones passed through config. | |
|
|
128
|
-
| store | object | Vuex store to use in order to register an extensions module. This should simplify the end usage of the SDK | |
|
|
129
|
-
| extensionsModuleName | string | Vuex store extension module name. Defaults to `sdkExtensions` | |
|
|
130
|
-
| queuesModuleName | string | Vuex store queue module name. Defaults to `sdkQueues` | |
|
|
131
|
-
|
|
132
|
-
Servers array format
|
|
133
|
-
```js [file.js]
|
|
134
|
-
const servers = [{
|
|
135
|
-
'URLID': 59,
|
|
136
|
-
'Priority': 5,
|
|
137
|
-
'Version': 2,
|
|
138
|
-
'Domain': 'monitor1.voicenter.co'
|
|
139
|
-
}]
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
## Other Methods
|
|
143
|
-
##### `Set token`
|
|
144
|
-
Sets new token to be used. This also triggers a disconnect and reconnect with new token.
|
|
145
|
-
```js [file.js]
|
|
146
|
-
sdk.setToken('some new token here')
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
##### `Resync`
|
|
150
|
-
Emits resync event to resync data.
|
|
151
|
-
```js [file.js]
|
|
152
|
-
sdk.resync()
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
##### `Set monitor url`
|
|
156
|
-
Sets new monitor url. This will trigger an http call to get the socket servers based on the monitor url. Please not that providing an invalid url, will try to revert to the old values. In case that fails, you will have to init the SDK again.
|
|
157
|
-
```js [file.js]
|
|
158
|
-
sdk.setMonitorUrl(newMonitorUrl)
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
##### `Login with user`
|
|
162
|
-
Log in based on user credentials.
|
|
163
|
-
```js [file.js]
|
|
164
|
-
async function initSdk() {
|
|
165
|
-
let sdk = new EventsSDK({
|
|
166
|
-
user: 'my user',
|
|
167
|
-
password: 'my password',
|
|
168
|
-
// other options here
|
|
169
|
-
});
|
|
170
|
-
await sdk.init()
|
|
171
|
-
await sdk.login('user')
|
|
172
|
-
}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
##### `Login with account`
|
|
176
|
-
Log in based on user account credentials.
|
|
177
|
-
```js [file.js]
|
|
178
|
-
async function initSdk() {
|
|
179
|
-
let sdk = new EventsSDK({
|
|
180
|
-
user: 'my user',
|
|
181
|
-
password: 'my password',
|
|
182
|
-
// other options here
|
|
183
|
-
});
|
|
184
|
-
await sdk.init()
|
|
185
|
-
await sdk.login('account')
|
|
186
|
-
}
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
##### `Login with code`
|
|
190
|
-
Log in based on code and organization code.
|
|
191
|
-
```js [file.js]
|
|
192
|
-
async function initSdk() {
|
|
193
|
-
let sdk = new EventsSDK({
|
|
194
|
-
code: 'my code',
|
|
195
|
-
organizationCode: 'my organization code',
|
|
196
|
-
// other options here
|
|
197
|
-
});
|
|
198
|
-
await sdk.init()
|
|
199
|
-
await sdk.login('code')
|
|
200
|
-
}
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
##### `Disconnect`
|
|
204
|
-
Forcefully disconnects from the socket. This should be handled by the sdk most of the times.
|
|
205
|
-
```js [file.js]
|
|
206
|
-
sdk.disconnect()
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
## Initializing new instance
|
|
211
|
-
```js [file.js]
|
|
212
|
-
const sdk = new EventsSDK({
|
|
213
|
-
...options
|
|
214
|
-
});
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
## Required params
|
|
219
|
-
As a required params of an options is loginType property (token/user/account) and authorization data:
|
|
220
|
-
- `User loginType example:`
|
|
221
|
-
```js [file.js]
|
|
222
|
-
const sdk = new EventsSDK({
|
|
223
|
-
loginType: 'user',
|
|
224
|
-
email: email@email.com',
|
|
225
|
-
password: 'password',
|
|
226
|
-
});
|
|
227
|
-
```
|
|
228
|
-
- `Token loginType example:`
|
|
229
|
-
```js [file.js]
|
|
230
|
-
const sdk = new EventsSDK({
|
|
231
|
-
loginType: 'token',
|
|
232
|
-
useLoginApi: true,
|
|
233
|
-
token: 'token',
|
|
234
|
-
});
|
|
235
|
-
```
|
|
236
|
-
- `Account loginType example:`
|
|
237
|
-
```js [file.js]
|
|
238
|
-
const sdk = new EventsSDK({
|
|
239
|
-
loginType: 'account',
|
|
240
|
-
username: 'username',
|
|
241
|
-
password: 'password',
|
|
242
|
-
});
|
|
243
|
-
```
|
|
244
|
-
## Initing an instance
|
|
245
|
-
```js [file.js]
|
|
246
|
-
sdk.init().then(function () {
|
|
247
|
-
//...
|
|
248
|
-
})
|
|
249
|
-
```
|
|
250
|
-
After the instance is init the events subscription can be implemented
|
|
251
|
-
- `Subscription:`
|
|
252
|
-
```js [file.js]
|
|
253
|
-
sdk.on('<EVENT_NAME>', function (response) {
|
|
254
|
-
// response
|
|
255
|
-
})
|
|
256
|
-
```
|
|
257
|
-
- `Or subscribe to all events:`
|
|
258
|
-
```js [file.js]
|
|
259
|
-
sdk.on('*', function (response) {
|
|
260
|
-
// response
|
|
261
|
-
})
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
## Events you can subscribe to
|
|
265
|
-
- `loginStatus`
|
|
266
|
-
- `login`
|
|
267
|
-
- `loginUser`
|
|
268
|
-
- `loginUser`
|
|
269
|
-
- `loginUserCode`
|
|
270
|
-
- `loginAccount`
|
|
271
|
-
- `loginResponse`
|
|
272
|
-
- `QueueEvent`
|
|
273
|
-
- `QueuesUpdated`
|
|
274
|
-
- `QueuesUpdated`
|
|
275
|
-
- `DialersUpdated`
|
|
276
|
-
- `ExtensionEvent`
|
|
277
|
-
- `ExtensionsUpdated`
|
|
278
|
-
- `AllExtensionsStatus`
|
|
279
|
-
- `connect_error`
|
|
280
|
-
- `connect_timeout`
|
|
281
|
-
- `disconnect`
|
|
282
|
-
- `pong`
|
|
283
|
-
- `reconnect`
|
|
284
|
-
- `reconnect_attempt`
|
|
285
|
-
- `resync`
|
|
286
|
-
- `reconnecting`
|
|
287
|
-
- `reconnect_error`
|
|
288
|
-
- `reconnect_failed`
|
|
289
|
-
- `keepalive`
|
|
290
|
-
- `keepaliveResponse`
|
|
291
|
-
- `closeme`
|
|
292
|
-
- `error`
|
|
293
|
-
|
|
294
|
-
## HTML Example
|
|
295
|
-
|
|
296
|
-
In case you have the socket-io client library available in window object EventsSDK library will work in front of that. If not - EventsSDK will include script tag with socket client relevant to ones that is used on server.
|
|
297
|
-
```html [index.html]
|
|
298
|
-
<html>
|
|
299
|
-
<head></head>
|
|
300
|
-
<body>
|
|
301
|
-
Status: <span id="status-txt">Disconnected</span>
|
|
302
|
-
<br/>
|
|
303
|
-
<br/>
|
|
304
|
-
|
|
305
|
-
<div id="response-body"></div>
|
|
306
|
-
</body>
|
|
307
|
-
</html>
|
|
308
|
-
|
|
309
|
-
<!-- Events SDK -->
|
|
310
|
-
<script src="https://voicentercdn-voicenterltd.netdna-ssl.com/cdn/events-sdk/voicenter-events-sdk.umd.js"></script>
|
|
311
|
-
<script>
|
|
312
|
-
let sdk = new EventsSDK({
|
|
313
|
-
loginType: 'user',
|
|
314
|
-
email: 'test@voicenter.com',
|
|
315
|
-
password: '11602082819',
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
sdk.init().then(function () {
|
|
319
|
-
// Success login event
|
|
320
|
-
sdk.on('loginSuccess', function (response) {
|
|
321
|
-
document.getElementById("status-txt").innerHTML = "Connected";
|
|
322
|
-
})
|
|
323
|
-
|
|
324
|
-
// Extension event
|
|
325
|
-
sdk.on('ExtensionEvent', function (response) {
|
|
326
|
-
console.log(response);
|
|
327
|
-
|
|
328
|
-
const cur = document.getElementById("response-body");
|
|
329
|
-
cur.innerHTML = cur.innerHTML + response.data.reason + "<br />";
|
|
330
|
-
})
|
|
331
|
-
|
|
332
|
-
// After logging in, receive all extensions statuses
|
|
333
|
-
sdk.on('AllExtensionsStatus', function (response) {
|
|
334
|
-
console.log(response);
|
|
335
|
-
})
|
|
336
|
-
});
|
|
337
|
-
</script>
|
|
1
|
+
---
|
|
2
|
+
title: Voicenter Events SDK
|
|
3
|
+
description: Voicenter Events SDK aims to manage API and socket communication with Voicenter APIs and backends.
|
|
4
|
+
You can use the SDK to send and receive real-time data from and to voicenter servers.
|
|
5
|
+
navigation:
|
|
6
|
+
title: Getting Started
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Voicenter Events SDK
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
The events sdk is a small sdk that handles real time communication with our servers.
|
|
14
|
+
The SDK has automatic server failover and fallback integrated as well as different utilities such as debug mode to easily visualize what's happening in the console.
|
|
15
|
+
The SDK uses websockets to manage real time bi-directional communication with our servers and it's meant to simplify developer work.
|
|
16
|
+
|
|
17
|
+
## Getting Started
|
|
18
|
+
|
|
19
|
+
The Events SDK should be used to communicate with Voicenter servers in order to receive real-time data via sockets. Underneath, the events SDK uses socket.io to send and receive events.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Table of contents
|
|
23
|
+
|
|
24
|
+
1. [Instalation](#instalation)
|
|
25
|
+
2. [Usage](#usage)
|
|
26
|
+
3. [Public methods](#use-the-public-methods-to-send-and-receive-events)
|
|
27
|
+
4. [Pass vuex store](#pass-vuex-store)
|
|
28
|
+
5. [Other Methods](#other-methods)
|
|
29
|
+
1. [Set token](#set-token)
|
|
30
|
+
2. [Resync](#resync)
|
|
31
|
+
3. [Set monitor url](#set-monitor-url)
|
|
32
|
+
4. [Login with user](#login-with-user)
|
|
33
|
+
5. [Login with account](#login-with-account)
|
|
34
|
+
6. [Login with code](#login-with-code)
|
|
35
|
+
7. [Disconnect](#disconnect)
|
|
36
|
+
6. [Initializing new instance](#initializing-new-instance)
|
|
37
|
+
7. [Required params](#required-params)
|
|
38
|
+
8. [Initing an instance](#initing-an-instance)
|
|
39
|
+
9. [Events you can subscribe to](#events-you-can-subscribe-to)
|
|
40
|
+
10. [HTML Example](#html-example)
|
|
41
|
+
|
|
42
|
+
## Instalation
|
|
43
|
+
1. Direct Download / CDN:
|
|
44
|
+
|
|
45
|
+
Include voicenter-events-sdk after Vue and it will install itself automatically:
|
|
46
|
+
```html [index.html]
|
|
47
|
+
<script src="https://voicentercdn-voicenterltd.netdna-ssl.com/cdn/events-sdk/voicenter-events-sdk.umd.js"></script>
|
|
48
|
+
```
|
|
49
|
+
2. NPM:
|
|
50
|
+
```sh [Terminal]
|
|
51
|
+
$ npm install voicenter-events-sdk
|
|
52
|
+
```
|
|
53
|
+
3. Yarn:
|
|
54
|
+
```sh [Terminal]
|
|
55
|
+
$ yarn add voicenter-events-sdk
|
|
56
|
+
```
|
|
57
|
+
You don't need to do this when using global script tags.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
You can initialize and use it to send and receive events to and from our servers.
|
|
62
|
+
- Initialize the constructor with a monitorCode
|
|
63
|
+
```js [file.js]
|
|
64
|
+
import EventsSDK from 'voicenter-events-sdk'
|
|
65
|
+
let sdk = new EventsSDK({
|
|
66
|
+
token: this.monitorCode,
|
|
67
|
+
// other options here
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
- Alternatively when loaded directly via CDN
|
|
72
|
+
```js [file.js]
|
|
73
|
+
let sdk = new window.VoicenterEventsSDK({
|
|
74
|
+
token: this.monitorCode,
|
|
75
|
+
// other options here
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
- Call the init method to initialize the server connections
|
|
79
|
+
```js [file.js]
|
|
80
|
+
sdk.init().then(() => {}) //sdk is initialized after promise is fulfilled
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
This step is important as we have an algorithm that retrieves multiple servers and has a failover mechanism behind it. Skipping this step, will throw error(s) in the subsequent steps.
|
|
84
|
+
|
|
85
|
+
## Use the public methods to send and receive events
|
|
86
|
+
- Subscribe to all events
|
|
87
|
+
```js [file.js]
|
|
88
|
+
sdk.on('*', data => {
|
|
89
|
+
// handle data here. Data format -> {name: 'event name', data: {}}
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
- Subscribe to specific events
|
|
93
|
+
```js [file.js]
|
|
94
|
+
sdk.on('ExtensionEvent', data => {
|
|
95
|
+
// handle ExtensionEvent here
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
- Emit events
|
|
99
|
+
```js [file.js]
|
|
100
|
+
sdk.emit('event name', { key: 'value' });
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Pass vuex store
|
|
104
|
+
Passing a vuex store will automatically register a vuex module and save extensions in it. This is useful if you use vuex and don't want to handle all the extension events yourself but rather use the sdk vuex module. [Open Vue Devtools](https://chrome.google.com/webstore/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd?hl=en) and see the `sdkExtensions` vuex module and its state/getters.
|
|
105
|
+
|
|
106
|
+
#### Options
|
|
107
|
+
The SDK constructor accepts multiple options when initializing which can be used to configure/tweak the SDK behaviour.
|
|
108
|
+
|
|
109
|
+
| Option | Type | Default | Description |
|
|
110
|
+
|-----------|---------------|---------------|---------------|
|
|
111
|
+
| token | String | Null | Monitor code token to use for login |
|
|
112
|
+
| user | String | Can be used to login with "user" or "account" login type | |
|
|
113
|
+
| password | String | Used for login with "user" or "account" login type. Must be used together with user property | |
|
|
114
|
+
| code | String | Code to be used for login with "code" type. Should be used with "organizationCode" code | |
|
|
115
|
+
| organizationCode | String | Organization code to be used for login with "code" type. Should be used with "organizationCode" code | |
|
|
116
|
+
| debug | Boolean | false | When set to true, it will print debug information to console |
|
|
117
|
+
| reconnectionDelay | Number | 10000 | First reconnection delay in milliseconds. Defaults to 10 seconds and increases with each retry (retryCount * reconnectionDelay) |
|
|
118
|
+
| timeout | Number | 10000 | Login timeout. Will throw an error if no event is sent back based on the emitted login event |
|
|
119
|
+
| protocol | String | https | Protocol to use when connecting via sockets with the server |
|
|
120
|
+
| keepAliveTimeout | Number | 60000 | Timeout after which a keep alive event is sent |
|
|
121
|
+
| idleInterval | Number | 60000 * 5 | Interval after which resync event is sent |
|
|
122
|
+
| transports | Array | ['websocket'] | Available transports. It's desired to leave this setting as it is. |
|
|
123
|
+
| upgrade | Boolean | false | Available transports. It's desired to leave this setting as it is. |
|
|
124
|
+
| serverType | Number | Null | Optional parameter to be passed to API call that retrieves available servers. Can be 1 or 2. 2 should be used for chrome extension. |
|
|
125
|
+
| url | string | https://monitorapi.voicenter.co.il/monitorAPI/getMonitorUrls | Url from which to get monitor urls. |
|
|
126
|
+
| servers | Array | contains 5 default servers | Contains a list of real-time servers with priorities and versions. Please check src/config.js file to see the exact format. |
|
|
127
|
+
| serverFetchStrategy | string | Determines the strategy how monitor servers are initiated. Can be remote (server urls are retrieved from a remote url) or static where server urls are specified directly through config. In case remote call fails, it will fallback to the default list of servers or the ones passed through config. | |
|
|
128
|
+
| store | object | Vuex store to use in order to register an extensions module. This should simplify the end usage of the SDK | |
|
|
129
|
+
| extensionsModuleName | string | Vuex store extension module name. Defaults to `sdkExtensions` | |
|
|
130
|
+
| queuesModuleName | string | Vuex store queue module name. Defaults to `sdkQueues` | |
|
|
131
|
+
|
|
132
|
+
Servers array format
|
|
133
|
+
```js [file.js]
|
|
134
|
+
const servers = [{
|
|
135
|
+
'URLID': 59,
|
|
136
|
+
'Priority': 5,
|
|
137
|
+
'Version': 2,
|
|
138
|
+
'Domain': 'monitor1.voicenter.co'
|
|
139
|
+
}]
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Other Methods
|
|
143
|
+
##### `Set token`
|
|
144
|
+
Sets new token to be used. This also triggers a disconnect and reconnect with new token.
|
|
145
|
+
```js [file.js]
|
|
146
|
+
sdk.setToken('some new token here')
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
##### `Resync`
|
|
150
|
+
Emits resync event to resync data.
|
|
151
|
+
```js [file.js]
|
|
152
|
+
sdk.resync()
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
##### `Set monitor url`
|
|
156
|
+
Sets new monitor url. This will trigger an http call to get the socket servers based on the monitor url. Please not that providing an invalid url, will try to revert to the old values. In case that fails, you will have to init the SDK again.
|
|
157
|
+
```js [file.js]
|
|
158
|
+
sdk.setMonitorUrl(newMonitorUrl)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
##### `Login with user`
|
|
162
|
+
Log in based on user credentials.
|
|
163
|
+
```js [file.js]
|
|
164
|
+
async function initSdk() {
|
|
165
|
+
let sdk = new EventsSDK({
|
|
166
|
+
user: 'my user',
|
|
167
|
+
password: 'my password',
|
|
168
|
+
// other options here
|
|
169
|
+
});
|
|
170
|
+
await sdk.init()
|
|
171
|
+
await sdk.login('user')
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
##### `Login with account`
|
|
176
|
+
Log in based on user account credentials.
|
|
177
|
+
```js [file.js]
|
|
178
|
+
async function initSdk() {
|
|
179
|
+
let sdk = new EventsSDK({
|
|
180
|
+
user: 'my user',
|
|
181
|
+
password: 'my password',
|
|
182
|
+
// other options here
|
|
183
|
+
});
|
|
184
|
+
await sdk.init()
|
|
185
|
+
await sdk.login('account')
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
##### `Login with code`
|
|
190
|
+
Log in based on code and organization code.
|
|
191
|
+
```js [file.js]
|
|
192
|
+
async function initSdk() {
|
|
193
|
+
let sdk = new EventsSDK({
|
|
194
|
+
code: 'my code',
|
|
195
|
+
organizationCode: 'my organization code',
|
|
196
|
+
// other options here
|
|
197
|
+
});
|
|
198
|
+
await sdk.init()
|
|
199
|
+
await sdk.login('code')
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
##### `Disconnect`
|
|
204
|
+
Forcefully disconnects from the socket. This should be handled by the sdk most of the times.
|
|
205
|
+
```js [file.js]
|
|
206
|
+
sdk.disconnect()
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
## Initializing new instance
|
|
211
|
+
```js [file.js]
|
|
212
|
+
const sdk = new EventsSDK({
|
|
213
|
+
...options
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
## Required params
|
|
219
|
+
As a required params of an options is loginType property (token/user/account) and authorization data:
|
|
220
|
+
- `User loginType example:`
|
|
221
|
+
```js [file.js]
|
|
222
|
+
const sdk = new EventsSDK({
|
|
223
|
+
loginType: 'user',
|
|
224
|
+
email: email@email.com',
|
|
225
|
+
password: 'password',
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
- `Token loginType example:`
|
|
229
|
+
```js [file.js]
|
|
230
|
+
const sdk = new EventsSDK({
|
|
231
|
+
loginType: 'token',
|
|
232
|
+
useLoginApi: true,
|
|
233
|
+
token: 'token',
|
|
234
|
+
});
|
|
235
|
+
```
|
|
236
|
+
- `Account loginType example:`
|
|
237
|
+
```js [file.js]
|
|
238
|
+
const sdk = new EventsSDK({
|
|
239
|
+
loginType: 'account',
|
|
240
|
+
username: 'username',
|
|
241
|
+
password: 'password',
|
|
242
|
+
});
|
|
243
|
+
```
|
|
244
|
+
## Initing an instance
|
|
245
|
+
```js [file.js]
|
|
246
|
+
sdk.init().then(function () {
|
|
247
|
+
//...
|
|
248
|
+
})
|
|
249
|
+
```
|
|
250
|
+
After the instance is init the events subscription can be implemented
|
|
251
|
+
- `Subscription:`
|
|
252
|
+
```js [file.js]
|
|
253
|
+
sdk.on('<EVENT_NAME>', function (response) {
|
|
254
|
+
// response
|
|
255
|
+
})
|
|
256
|
+
```
|
|
257
|
+
- `Or subscribe to all events:`
|
|
258
|
+
```js [file.js]
|
|
259
|
+
sdk.on('*', function (response) {
|
|
260
|
+
// response
|
|
261
|
+
})
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Events you can subscribe to
|
|
265
|
+
- `loginStatus`
|
|
266
|
+
- `login`
|
|
267
|
+
- `loginUser`
|
|
268
|
+
- `loginUser`
|
|
269
|
+
- `loginUserCode`
|
|
270
|
+
- `loginAccount`
|
|
271
|
+
- `loginResponse`
|
|
272
|
+
- `QueueEvent`
|
|
273
|
+
- `QueuesUpdated`
|
|
274
|
+
- `QueuesUpdated`
|
|
275
|
+
- `DialersUpdated`
|
|
276
|
+
- `ExtensionEvent`
|
|
277
|
+
- `ExtensionsUpdated`
|
|
278
|
+
- `AllExtensionsStatus`
|
|
279
|
+
- `connect_error`
|
|
280
|
+
- `connect_timeout`
|
|
281
|
+
- `disconnect`
|
|
282
|
+
- `pong`
|
|
283
|
+
- `reconnect`
|
|
284
|
+
- `reconnect_attempt`
|
|
285
|
+
- `resync`
|
|
286
|
+
- `reconnecting`
|
|
287
|
+
- `reconnect_error`
|
|
288
|
+
- `reconnect_failed`
|
|
289
|
+
- `keepalive`
|
|
290
|
+
- `keepaliveResponse`
|
|
291
|
+
- `closeme`
|
|
292
|
+
- `error`
|
|
293
|
+
|
|
294
|
+
## HTML Example
|
|
295
|
+
|
|
296
|
+
In case you have the socket-io client library available in window object EventsSDK library will work in front of that. If not - EventsSDK will include script tag with socket client relevant to ones that is used on server.
|
|
297
|
+
```html [index.html]
|
|
298
|
+
<html>
|
|
299
|
+
<head></head>
|
|
300
|
+
<body>
|
|
301
|
+
Status: <span id="status-txt">Disconnected</span>
|
|
302
|
+
<br/>
|
|
303
|
+
<br/>
|
|
304
|
+
|
|
305
|
+
<div id="response-body"></div>
|
|
306
|
+
</body>
|
|
307
|
+
</html>
|
|
308
|
+
|
|
309
|
+
<!-- Events SDK -->
|
|
310
|
+
<script src="https://voicentercdn-voicenterltd.netdna-ssl.com/cdn/events-sdk/voicenter-events-sdk.umd.js"></script>
|
|
311
|
+
<script>
|
|
312
|
+
let sdk = new EventsSDK({
|
|
313
|
+
loginType: 'user',
|
|
314
|
+
email: 'test@voicenter.com',
|
|
315
|
+
password: '11602082819',
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
sdk.init().then(function () {
|
|
319
|
+
// Success login event
|
|
320
|
+
sdk.on('loginSuccess', function (response) {
|
|
321
|
+
document.getElementById("status-txt").innerHTML = "Connected";
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
// Extension event
|
|
325
|
+
sdk.on('ExtensionEvent', function (response) {
|
|
326
|
+
console.log(response);
|
|
327
|
+
|
|
328
|
+
const cur = document.getElementById("response-body");
|
|
329
|
+
cur.innerHTML = cur.innerHTML + response.data.reason + "<br />";
|
|
330
|
+
})
|
|
331
|
+
|
|
332
|
+
// After logging in, receive all extensions statuses
|
|
333
|
+
sdk.on('AllExtensionsStatus', function (response) {
|
|
334
|
+
console.log(response);
|
|
335
|
+
})
|
|
336
|
+
});
|
|
337
|
+
</script>
|
|
338
338
|
```
|