Voicenter Events SDK aims to manage API and socket communication with Voicenter APIs and backends.
You can use the SDK to send and receive real-time data from and to voicenter servers.
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.
- Instalation
- Usage
- Public methods
- Pass vuex store
- Other Methods
- Initializing new instance
- Required params
- Initing an instance
- Events you can subscribe to
- HTML Example
-
Direct Download / CDN:
Include voicenter-events-sdk after Vue and it will install itself automatically:
<script src="https://voicentercdn-voicenterltd.netdna-ssl.com/cdn/events-sdk/voicenter-events-sdk.umd.js"></script>
-
NPM:
$ npm install voicenter-events-sdk
-
Yarn:
$ yarn add voicenter-events-sdk
You don't need to do this when using global script tags.
You can initialize and use it to send and receive events to and from our servers.
- Initialize the constructor with a monitorCode
import EventsSDK from 'voicenter-events-sdk'
let sdk = new EventsSDK({
token: this.monitorCode,
// other options here
});
- Alternatively when loaded directly via CDN
let sdk = new window.VoicenterEventsSDK({
token: this.monitorCode,
// other options here
});
- Call the init method to initialize the server connections
sdk.init().then(() => {}) //sdk is initialized after promise is fulfilled
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.
- Subscribe to all events
sdk.on('*', data => {
// handle data here. Data format -> {name: 'event name', data: {}}
});
- Subscribe to specific events
sdk.on('ExtensionEvent', data => {
// handle ExtensionEvent here
});
- Emit events
sdk.emit('event name', { key: 'value' });
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 and see the sdkExtensions
vuex module and its state/getters.
The SDK constructor accepts multiple options when initializing which can be used to configure/tweak the SDK behaviour.
Option | Type | Default | Description |
---|---|---|---|
token | String | Null | Monitor code token to use for login |
user | String | Can be used to login with "user" or "account" login type | |
password | String | Used for login with "user" or "account" login type. Must be used together with user property | |
code | String | Code to be used for login with "code" type. Should be used with "organizationCode" code | |
organizationCode | String | Organization code to be used for login with "code" type. Should be used with "organizationCode" code | |
debug | Boolean | false | When set to true, it will print debug information to console |
reconnectionDelay | Number | 10000 | First reconnection delay in milliseconds. Defaults to 10 seconds and increases with each retry (retryCount * reconnectionDelay) |
timeout | Number | 10000 | Login timeout. Will throw an error if no event is sent back based on the emitted login event |
protocol | String | https | Protocol to use when connecting via sockets with the server |
keepAliveTimeout | Number | 60000 | Timeout after which a keep alive event is sent |
idleInterval | Number | 60000 * 5 | Interval after which resync event is sent |
transports | Array | ['websocket'] | Available transports. It's desired to leave this setting as it is. |
upgrade | Boolean | false | Available transports. It's desired to leave this setting as it is. |
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. |
url | string | https://monitorapi.voicenter.co.il/monitorAPI/getMonitorUrls | Url from which to get monitor urls. |
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. |
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. | |
store | object | Vuex store to use in order to register an extensions module. This should simplify the end usage of the SDK | |
extensionsModuleName | string | Vuex store extension module name. Defaults to sdkExtensions |
|
queuesModuleName | string | Vuex store queue module name. Defaults to sdkQueues |
Servers array format
const servers = [{
'URLID': 59,
'Priority': 5,
'Version': 2,
'Domain': 'monitor1.voicenter.co'
}]
Sets new token to be used. This also triggers a disconnect and reconnect with new token.
sdk.setToken('some new token here')
Emits resync event to resync data.
sdk.resync()
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.
sdk.setMonitorUrl(newMonitorUrl)
Log in based on user credentials.
async function initSdk() {
let sdk = new EventsSDK({
user: 'my user',
password: 'my password',
// other options here
});
await sdk.init()
await sdk.login('user')
}
Log in based on user account credentials.
async function initSdk() {
let sdk = new EventsSDK({
user: 'my user',
password: 'my password',
// other options here
});
await sdk.init()
await sdk.login('account')
}
Log in based on code and organization code.
async function initSdk() {
let sdk = new EventsSDK({
code: 'my code',
organizationCode: 'my organization code',
// other options here
});
await sdk.init()
await sdk.login('code')
}
Forcefully disconnects from the socket. This should be handled by the sdk most of the times.
sdk.disconnect()
const sdk = new EventsSDK({
...options
});
As a required params of an options is loginType property (token/user/account) and authorization data:
User loginType example:
const sdk = new EventsSDK({ loginType: 'user', email: email@email.com', password: 'password', });
Token loginType example:
const sdk = new EventsSDK({ loginType: 'token', useLoginApi: true, token: 'token', });
Account loginType example:
const sdk = new EventsSDK({ loginType: 'account', username: 'username', password: 'password', });
sdk.init().then(function () {
//...
})
After the instance is init the events subscription can be implemented
Subscription:
sdk.on('<EVENT_NAME>', function (response) { // response })
Or subscribe to all events:
sdk.on('*', function (response) { // response })
loginStatus
login
loginUser
loginUser
loginUserCode
loginAccount
loginResponse
QueueEvent
QueuesUpdated
QueuesUpdated
DialersUpdated
ExtensionEvent
ExtensionsUpdated
AllExtensionsStatus
connect_error
connect_timeout
disconnect
pong
reconnect
reconnect_attempt
resync
reconnecting
reconnect_error
reconnect_failed
keepalive
keepaliveResponse
closeme
error
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.
<html>
<head></head>
<body>
Status: <span id="status-txt">Disconnected</span>
<br/>
<br/>
<div id="response-body"></div>
</body>
</html>
<!-- Events SDK -->
<script src="https://voicentercdn-voicenterltd.netdna-ssl.com/cdn/events-sdk/voicenter-events-sdk.umd.js"></script>
<script>
let sdk = new EventsSDK({
loginType: 'user',
email: 'test@voicenter.com',
password: '11602082819',
});
sdk.init().then(function () {
// Success login event
sdk.on('loginSuccess', function (response) {
document.getElementById("status-txt").innerHTML = "Connected";
})
// Extension event
sdk.on('ExtensionEvent', function (response) {
console.log(response);
const cur = document.getElementById("response-body");
cur.innerHTML = cur.innerHTML + response.data.reason + "<br />";
})
// After logging in, receive all extensions statuses
sdk.on('AllExtensionsStatus', function (response) {
console.log(response);
})
});
</script>