@voicenter-team/events-sdk 0.0.18 → 0.0.20
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/dist/voicenter-events-sdk.cjs.js +14 -14
- package/dist/voicenter-events-sdk.cjs.js.map +1 -1
- package/dist/voicenter-events-sdk.d.ts +14 -11
- package/dist/voicenter-events-sdk.es.js +1512 -1494
- package/dist/voicenter-events-sdk.es.js.map +1 -1
- package/dist/voicenter-events-sdk.iife.js +15 -15
- package/dist/voicenter-events-sdk.iife.js.map +1 -1
- package/dist/voicenter-events-sdk.umd.js +15 -15
- package/dist/voicenter-events-sdk.umd.js.map +1 -1
- package/docs/src/.vuepress/components/Demo.vue +127 -5
- package/package.json +1 -1
- package/src/classes/auth/auth.class.ts +10 -2
- package/src/classes/events-sdk/events-sdk-default-options.ts +1 -1
- package/src/classes/events-sdk/events-sdk.class.ts +119 -103
- package/src/classes/events-sdk/events-sdk.test.ts +11 -3
- package/src/classes/events-sdk/events-sdk.types.ts +3 -4
- package/src/classes/socket-io/socket-io.class.ts +21 -7
- package/src/enum/events.enum.ts +1 -0
- package/src/types/events.d.ts +1 -0
- package/swagger/generated/Swagger.json +0 -1
- package/swagger/index.js +0 -60
- package/swagger/package.json +0 -21
- package/swagger/scripts/update-swagger-json.js +0 -53
- package/swagger/yarn.lock +0 -2100
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div>
|
|
3
|
-
<
|
|
3
|
+
<Transition name="fade">
|
|
4
|
+
<div v-if="isOnline && showSuccessNotification" class="message message--success" key="success">
|
|
5
|
+
Connection established!
|
|
6
|
+
</div>
|
|
7
|
+
</Transition>
|
|
8
|
+
|
|
9
|
+
<Transition name="fade">
|
|
10
|
+
<p v-if="!isOnline" class="message message--error" key="error">
|
|
11
|
+
No connection
|
|
12
|
+
<div class="message-container">
|
|
13
|
+
<Transition name="attempt-to-connect" mode="out-in">
|
|
14
|
+
<span v-if="attemptToConnect" :key="attemptToConnect" class="message">
|
|
15
|
+
Trying to connect to {{ attemptToConnect }}
|
|
16
|
+
</span>
|
|
17
|
+
</Transition>
|
|
18
|
+
</div>
|
|
19
|
+
</p>
|
|
20
|
+
</Transition>
|
|
21
|
+
|
|
22
|
+
<p v-if="loading && isOnline">
|
|
4
23
|
Loading...
|
|
5
24
|
</p>
|
|
6
25
|
|
|
@@ -28,6 +47,9 @@ import {EventTypeData} from '@/types/events'
|
|
|
28
47
|
import {LoginType} from "@/enum/auth.enum";
|
|
29
48
|
|
|
30
49
|
/* Data */
|
|
50
|
+
const showSuccessNotification = ref(false)
|
|
51
|
+
const isOnline = ref(true)
|
|
52
|
+
const attemptToConnect = ref<string | undefined>(undefined)
|
|
31
53
|
const token = ref('')
|
|
32
54
|
const loading = ref(false)
|
|
33
55
|
const loggedId = ref(false)
|
|
@@ -42,12 +64,24 @@ async function login() {
|
|
|
42
64
|
loading.value = true
|
|
43
65
|
|
|
44
66
|
const sdk = new EventsSdkClass({
|
|
45
|
-
loginUrl: "https://
|
|
46
|
-
refreshTokenUrl: "https://
|
|
67
|
+
loginUrl: "https://loginapi.voicenter.co.il/monitorAPI/Login",
|
|
68
|
+
refreshTokenUrl: "https://loginapi.voicenter.co.il/monitorAPI/RefreshIdentityToken",
|
|
47
69
|
loginType: LoginType.TOKEN, // <=== "User" or "Token"
|
|
48
70
|
token: 'QMSVU9dwNYC9Le9VCBqx24AB9TYyWj9Xn5aCPV0GFHIWoShQqfPtnAPmnw24xpJIUSsDDtlac2OPpjx0t3MSkxH3AhiQGHCeGZ8e',
|
|
49
|
-
|
|
50
|
-
|
|
71
|
+
servers: [
|
|
72
|
+
{
|
|
73
|
+
URLID: 1,
|
|
74
|
+
Priority: 1,
|
|
75
|
+
Version: "1.3.7",
|
|
76
|
+
Domain: "monitor5.voicenter.co.il"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
URLID: 2,
|
|
80
|
+
Priority: 2,
|
|
81
|
+
Version: "1.3.7",
|
|
82
|
+
Domain: "monitor6.voicenter.co.il"
|
|
83
|
+
}
|
|
84
|
+
],
|
|
51
85
|
})
|
|
52
86
|
|
|
53
87
|
await sdk.init()
|
|
@@ -137,6 +171,22 @@ async function login() {
|
|
|
137
171
|
}
|
|
138
172
|
)
|
|
139
173
|
|
|
174
|
+
sdk.on(
|
|
175
|
+
EventsEnum.ONLINE_STATUS_EVENT,
|
|
176
|
+
({ data }) => {
|
|
177
|
+
isOnline.value = data.isSocketConnected
|
|
178
|
+
attemptToConnect.value = data.attemptToConnect
|
|
179
|
+
|
|
180
|
+
if (data.isSocketConnected) {
|
|
181
|
+
showSuccessNotification.value = true
|
|
182
|
+
|
|
183
|
+
setTimeout(() => {
|
|
184
|
+
showSuccessNotification.value = false
|
|
185
|
+
}, 3000)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
)
|
|
189
|
+
|
|
140
190
|
sdk.on(
|
|
141
191
|
'*',
|
|
142
192
|
(data) => {
|
|
@@ -183,3 +233,75 @@ async function login() {
|
|
|
183
233
|
)
|
|
184
234
|
}
|
|
185
235
|
</script>
|
|
236
|
+
|
|
237
|
+
<style>
|
|
238
|
+
.fade-enter-active,
|
|
239
|
+
.fade-leave-active {
|
|
240
|
+
transition: opacity 0.5s ease;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.fade-enter-from,
|
|
244
|
+
.fade-leave-to {
|
|
245
|
+
opacity: 0;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
.message-container {
|
|
250
|
+
position: relative;
|
|
251
|
+
min-height: 50px; /* Adjust based on your content's typical size */
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/* Enhanced transition handling for attempt-to-connect */
|
|
255
|
+
.attempt-to-connect-enter-active, .attempt-to-connect-leave-active {
|
|
256
|
+
transition: opacity 0.5s, transform 0.5s;
|
|
257
|
+
position: absolute;
|
|
258
|
+
width: 100%;
|
|
259
|
+
top: 0;
|
|
260
|
+
left: 0;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.attempt-to-connect-enter {
|
|
264
|
+
opacity: 0;
|
|
265
|
+
transform: translateY(20px);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.attempt-to-connect-leave-active {
|
|
269
|
+
opacity: 1;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.attempt-to-connect-leave-to {
|
|
273
|
+
opacity: 0;
|
|
274
|
+
transform: translateY(-20px);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
.attempt-to-connect-enter-to, .attempt-to-connect-leave {
|
|
278
|
+
opacity: 1;
|
|
279
|
+
transform: translateY(0);
|
|
280
|
+
position: relative;
|
|
281
|
+
}
|
|
282
|
+
</style>
|
|
283
|
+
|
|
284
|
+
<style lang="scss" scoped>
|
|
285
|
+
.message {
|
|
286
|
+
border-radius: 24px;
|
|
287
|
+
font-size: 24px;
|
|
288
|
+
text-align: center;
|
|
289
|
+
padding: 8px 0;
|
|
290
|
+
|
|
291
|
+
&--error {
|
|
292
|
+
background-color: #a31c1c;
|
|
293
|
+
color: white;
|
|
294
|
+
|
|
295
|
+
span {
|
|
296
|
+
font-size: 16px;
|
|
297
|
+
margin-top: 16px;
|
|
298
|
+
display: block;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
&--success {
|
|
303
|
+
background-color: #1ca31c;
|
|
304
|
+
color: white;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
</style>
|
package/package.json
CHANGED
|
@@ -44,6 +44,8 @@ class AuthClass{
|
|
|
44
44
|
const isLoggedIn = await this.checkLoginStatus(this.storageKey)
|
|
45
45
|
|
|
46
46
|
if (!isLoggedIn) {
|
|
47
|
+
StorageClass.clearSessionStorage()
|
|
48
|
+
|
|
47
49
|
await this.userLoginFunction(payload, this.storageKey, options.loginType)
|
|
48
50
|
}
|
|
49
51
|
}
|
|
@@ -118,17 +120,23 @@ class AuthClass{
|
|
|
118
120
|
(prev.Priority > current.Priority) ? prev : current
|
|
119
121
|
)
|
|
120
122
|
}
|
|
123
|
+
if (!this.eventsSdkClass.options.isNewStack && !this.eventsSdkClass.servers.length && loginSessionData.URLList) {
|
|
124
|
+
this.eventsSdkClass.URLList = loginSessionData.URLList
|
|
125
|
+
}
|
|
121
126
|
if (this.eventsSdkClass.server) {
|
|
122
127
|
this.eventsSdkClass.socketIoClass.getSocketIoFunction(`v=${this.eventsSdkClass.server.Version}`)
|
|
123
128
|
this.eventsSdkClass.loggerClass.init()
|
|
124
129
|
}
|
|
130
|
+
if (!this.eventsSdkClass.server && this.eventsSdkClass.URLList.length) {
|
|
131
|
+
this.eventsSdkClass.socketIoClass.getSocketIoFunction(`v=${loginSessionData.Client}`)
|
|
132
|
+
}
|
|
125
133
|
if (loginSessionData.IdentityCode) {
|
|
126
134
|
this.token = loginSessionData.IdentityCode
|
|
127
|
-
this.eventsSdkClass.connect(ServerParameter.
|
|
135
|
+
this.eventsSdkClass.connect(ServerParameter.MAIN)
|
|
128
136
|
}
|
|
129
137
|
if (loginSessionData.Token) {
|
|
130
138
|
this.token = loginSessionData.Token
|
|
131
|
-
this.eventsSdkClass.connect(ServerParameter.
|
|
139
|
+
this.eventsSdkClass.connect(ServerParameter.MAIN)
|
|
132
140
|
}
|
|
133
141
|
if (loginSessionData.RefreshToken && loginSessionData.IdentityCodeExpiry && this.eventsSdkClass.options.loginType === LoginType.USER) {
|
|
134
142
|
this.eventsSdkClass.options.refreshToken = loginSessionData.RefreshToken
|
|
@@ -26,7 +26,7 @@ export const eventsSdkDefaultOptions: Partial<EventsSdkOptions> = {
|
|
|
26
26
|
reconnection: true,
|
|
27
27
|
reconnectionDelay: 5000,
|
|
28
28
|
reconnectionAttempts: 10,
|
|
29
|
-
perMessageDeflate:
|
|
29
|
+
perMessageDeflate: undefined,
|
|
30
30
|
upgrade: false,
|
|
31
31
|
transports: [ 'websocket' ],
|
|
32
32
|
debug: false
|
|
@@ -5,53 +5,34 @@ import { SocketIoClass } from '@/classes/socket-io/socket-io.class'
|
|
|
5
5
|
import { EventsSdkOptions, ReconnectOptions, Server, ServerParameter } from '@/classes/events-sdk/events-sdk.types'
|
|
6
6
|
import { SocketTyped } from '@/types/socket'
|
|
7
7
|
import {
|
|
8
|
-
GenericEventWrapper,
|
|
9
|
-
EventSpecificCallback,
|
|
10
8
|
EventCallbackListenersMap,
|
|
9
|
+
EventSpecificCallback,
|
|
11
10
|
EventTypeData,
|
|
12
11
|
EventTypeNames,
|
|
12
|
+
GenericEventWrapper,
|
|
13
13
|
} from '@/types/events'
|
|
14
14
|
import { EventsEnum } from '@/enum/events.enum'
|
|
15
15
|
import { LoggerClass } from '@/classes/logger/logger.class'
|
|
16
16
|
|
|
17
17
|
class EventsSdkClass{
|
|
18
|
-
constructor (options: EventsSdkOptions) {
|
|
19
|
-
this.options = {
|
|
20
|
-
...eventsSdkDefaultOptions,
|
|
21
|
-
...options
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
this.server = this.options.fallbackServer
|
|
25
|
-
|
|
26
|
-
this.argumentOptions = {
|
|
27
|
-
...options
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
18
|
private argumentOptions: EventsSdkOptions
|
|
32
|
-
public readonly options: EventsSdkOptions
|
|
33
|
-
...eventsSdkDefaultOptions
|
|
34
|
-
}
|
|
19
|
+
public readonly options: EventsSdkOptions
|
|
35
20
|
public servers: Server[] = []
|
|
21
|
+
public URLList: string[] = []
|
|
36
22
|
public server: Server
|
|
23
|
+
public URL: string | undefined
|
|
37
24
|
public socket: SocketTyped | undefined
|
|
25
|
+
private mainServer: Server | undefined
|
|
26
|
+
|
|
27
|
+
private alreadyAttemptedOtherServers: Array<number | string> = []
|
|
38
28
|
|
|
39
29
|
public authClass = new AuthClass(this)
|
|
40
30
|
public socketIoClass = new SocketIoClass(this)
|
|
41
31
|
public loggerClass = new LoggerClass(this)
|
|
42
32
|
|
|
43
|
-
public reconnectOptions: ReconnectOptions
|
|
44
|
-
retryCount: 1,
|
|
45
|
-
maxReconnectAttempts: this.options.maxReconnectAttempts,
|
|
46
|
-
reconnectionDelay: this.options.reconnectionDelay, // 10 seconds. After each re-connection attempt this number will increase (minReconnectionDelay * attempts) => 10, 20, 30, 40 seconds ... up to 5min
|
|
47
|
-
minReconnectionDelay: this.options.reconnectionDelay, // 10 seconds
|
|
48
|
-
maxReconnectionDelay: 60000 * 5 // 5 minutes
|
|
49
|
-
}
|
|
33
|
+
public reconnectOptions: ReconnectOptions
|
|
50
34
|
|
|
51
|
-
public retryConnection
|
|
52
|
-
leading: true,
|
|
53
|
-
trailing: false
|
|
54
|
-
})
|
|
35
|
+
public retryConnection
|
|
55
36
|
|
|
56
37
|
private listeners: EventCallbackListenersMap = {
|
|
57
38
|
[EventsEnum.ALL_EXTENSION_STATUS]: [],
|
|
@@ -67,6 +48,32 @@ class EventsSdkClass{
|
|
|
67
48
|
}
|
|
68
49
|
private allListeners: Array<(data: GenericEventWrapper) => void> = []
|
|
69
50
|
|
|
51
|
+
constructor (options: EventsSdkOptions) {
|
|
52
|
+
this.options = {
|
|
53
|
+
...eventsSdkDefaultOptions,
|
|
54
|
+
...options
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this.reconnectOptions = {
|
|
58
|
+
retryCount: 1,
|
|
59
|
+
maxReconnectAttempts: this.options.maxReconnectAttempts,
|
|
60
|
+
reconnectionDelay: this.options.reconnectionDelay, // 10 seconds. After each re-connection attempt this number will increase (minReconnectionDelay * attempts) => 10, 20, 30, 40 seconds ... up to 5min
|
|
61
|
+
minReconnectionDelay: this.options.reconnectionDelay, // 10 seconds
|
|
62
|
+
maxReconnectionDelay: 60000 * 5 // 5 minutes
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
this.server = this.options.fallbackServer
|
|
66
|
+
|
|
67
|
+
this.retryConnection = debounce(this.connect.bind(this), this.reconnectOptions.reconnectionDelay, {
|
|
68
|
+
leading: true,
|
|
69
|
+
trailing: false
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
this.argumentOptions = {
|
|
73
|
+
...options
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
70
77
|
public on<T extends EventTypeNames> (event: T, callback: EventSpecificCallback<T>): void
|
|
71
78
|
public on (event: '*', callback: (data: GenericEventWrapper) => void): void
|
|
72
79
|
public on (event: unknown, callback: unknown) {
|
|
@@ -110,23 +117,25 @@ class EventsSdkClass{
|
|
|
110
117
|
this.allListeners.forEach((callback) => callback(allEventData))
|
|
111
118
|
}
|
|
112
119
|
|
|
113
|
-
public connect (
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
120
|
+
public connect (serverParameter: ServerParameter) {
|
|
121
|
+
// if (server === ServerParameter.DEFAULT) {
|
|
122
|
+
// serverToConnect = this.findCurrentServer()
|
|
123
|
+
// }
|
|
124
|
+
//
|
|
125
|
+
// if (server === ServerParameter.NEXT) {
|
|
126
|
+
// serverToConnect = this.findNextAvailableServer()
|
|
127
|
+
// }
|
|
128
|
+
//
|
|
129
|
+
// if (server === ServerParameter.PREVIOUS) {
|
|
130
|
+
// serverToConnect = this.findMaxPriorityServer()
|
|
131
|
+
// }
|
|
132
|
+
|
|
133
|
+
if (serverParameter === ServerParameter.MAIN) {
|
|
134
|
+
this.findMainServer()
|
|
126
135
|
}
|
|
127
136
|
|
|
128
|
-
if (
|
|
129
|
-
this.
|
|
137
|
+
if (serverParameter === ServerParameter.NEXT) {
|
|
138
|
+
this.findNextServer()
|
|
130
139
|
}
|
|
131
140
|
|
|
132
141
|
this.socketIoClass.doReconnect = true
|
|
@@ -136,11 +145,6 @@ class EventsSdkClass{
|
|
|
136
145
|
this.socketIoClass.initSocketEvents()
|
|
137
146
|
|
|
138
147
|
this.socketIoClass.initKeepAlive()
|
|
139
|
-
|
|
140
|
-
// TODO: check if it is needed here
|
|
141
|
-
if (skipLogin) {
|
|
142
|
-
return
|
|
143
|
-
}
|
|
144
148
|
}
|
|
145
149
|
|
|
146
150
|
public disconnect () {
|
|
@@ -152,66 +156,78 @@ class EventsSdkClass{
|
|
|
152
156
|
this.socketIoClass.clearKeepAliveInterval()
|
|
153
157
|
}
|
|
154
158
|
|
|
155
|
-
private
|
|
159
|
+
private findMainServer () {
|
|
156
160
|
if (this.servers.length) {
|
|
157
|
-
this.
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
this.server = this.options.fallbackServer
|
|
161
|
-
}
|
|
162
|
-
return this.server
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
private findNextAvailableServer (): Server {
|
|
166
|
-
// this.log(INFO, 'Failover -> Trying to find another server');
|
|
167
|
-
|
|
168
|
-
const currentServerPriority = this.server.Priority
|
|
169
|
-
|
|
170
|
-
const nextServerPriority = currentServerPriority + 1
|
|
171
|
-
|
|
172
|
-
const nextServer = this.servers.find(server => server.Priority === nextServerPriority) || this.findMinPriorityServer()
|
|
173
|
-
|
|
174
|
-
this.server = { ...nextServer }
|
|
175
|
-
|
|
176
|
-
// this.log(INFO, 'Failover -> Found new server. Connecting to it...', this.server);
|
|
177
|
-
|
|
178
|
-
return this.server
|
|
179
|
-
}
|
|
161
|
+
this.mainServer = this.servers.reduce((prev, cur) => {
|
|
162
|
+
return cur.Priority > prev.Priority ? cur : prev
|
|
163
|
+
})
|
|
180
164
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (!this.server) {
|
|
187
|
-
this.server = maxPriorityServer
|
|
188
|
-
|
|
189
|
-
return this.server
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (this.server && maxPriorityServer.Domain !== this.server.Domain) {
|
|
193
|
-
this.server = maxPriorityServer
|
|
194
|
-
|
|
195
|
-
// this.log(INFO, 'Fallback -> Trying to find previous server');
|
|
196
|
-
|
|
197
|
-
return this.server
|
|
165
|
+
this.server = this.mainServer
|
|
166
|
+
} else {
|
|
167
|
+
if (this.URLList.length) {
|
|
168
|
+
this.URL = this.URLList[0]
|
|
169
|
+
}
|
|
198
170
|
}
|
|
199
|
-
|
|
200
|
-
return this.server
|
|
201
171
|
}
|
|
202
172
|
|
|
203
|
-
private
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
173
|
+
private findNextServer () {
|
|
174
|
+
if (this.servers.length) {
|
|
175
|
+
if (this.server.Priority === this.mainServer!.Priority) {
|
|
176
|
+
let filteredServers = this.servers.filter(
|
|
177
|
+
server =>
|
|
178
|
+
server.Priority !== this.mainServer!.Priority &&
|
|
179
|
+
this.alreadyAttemptedOtherServers.indexOf(server.Priority) + 1 === 0
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
if (!filteredServers.length) {
|
|
183
|
+
this.alreadyAttemptedOtherServers = []
|
|
184
|
+
|
|
185
|
+
filteredServers = this.servers.filter(
|
|
186
|
+
server =>
|
|
187
|
+
server.Priority !== this.mainServer!.Priority &&
|
|
188
|
+
this.alreadyAttemptedOtherServers.indexOf(server.Priority) + 1 === 0
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (filteredServers.length) {
|
|
193
|
+
this.server = filteredServers.reduce((prev, cur) => {
|
|
194
|
+
return cur.Priority > prev.Priority ? cur : prev
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
this.alreadyAttemptedOtherServers.push(this.server.Priority)
|
|
198
|
+
}
|
|
199
|
+
} else {
|
|
200
|
+
this.server = this.mainServer!
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
if (this.URLList.length) {
|
|
204
|
+
if (this.URL === this.URLList[0]) {
|
|
205
|
+
let filteredServers = this.URLList.filter(
|
|
206
|
+
url =>
|
|
207
|
+
url !== this.URLList[0] &&
|
|
208
|
+
this.alreadyAttemptedOtherServers.indexOf(url) + 1 === 0
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
if (!filteredServers.length) {
|
|
212
|
+
this.alreadyAttemptedOtherServers = []
|
|
213
|
+
|
|
214
|
+
filteredServers = this.URLList.filter(
|
|
215
|
+
url =>
|
|
216
|
+
url !== this.URLList[0] &&
|
|
217
|
+
this.alreadyAttemptedOtherServers.indexOf(url) + 1 === 0
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (filteredServers.length) {
|
|
222
|
+
this.URL = filteredServers[0]
|
|
223
|
+
|
|
224
|
+
this.alreadyAttemptedOtherServers.push(this.URL)
|
|
225
|
+
}
|
|
226
|
+
} else {
|
|
227
|
+
this.URL = this.URLList[0]
|
|
228
|
+
}
|
|
229
|
+
}
|
|
212
230
|
}
|
|
213
|
-
|
|
214
|
-
return this.server
|
|
215
231
|
}
|
|
216
232
|
|
|
217
233
|
public getServerWithHighestPriority (servers: Server[]): Server {
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import EventsSdkClass from '@/classes/events-sdk/events-sdk.class'
|
|
2
|
-
import {
|
|
2
|
+
import { LoginType } from '@/enum/auth.enum'
|
|
3
3
|
|
|
4
4
|
describe('EventsSdkClass', () => {
|
|
5
5
|
it('should be true', () => {
|
|
6
|
-
const eventsSdkClass = new EventsSdkClass(
|
|
6
|
+
const eventsSdkClass = new EventsSdkClass({
|
|
7
|
+
loginUrl: 'https://loginapidev.voicenter.co.il/Auth/Login/Voicenter/Monitor',
|
|
8
|
+
refreshTokenUrl: 'https://loginapidev.voicenter.co.il/Auth/RefreshToken',
|
|
9
|
+
loginType: LoginType.TOKEN, // <=== "User" or "Token"
|
|
10
|
+
token: 'QMSVU9dwNYC9Le9VCBqx24AB9TYyWj9Xn5aCPV0GFHIWoShQqfPtnAPmnw24xpJIUSsDDtlac2OPpjx0t3MSkxH3AhiQGHCeGZ8e',
|
|
11
|
+
getSettingsUrl: 'https://loginapidev.voicenter.co.il/Application/GetSettings',
|
|
12
|
+
isNewStack: true,
|
|
13
|
+
})
|
|
14
|
+
|
|
7
15
|
expect(eventsSdkClass.init()).toBe(true)
|
|
8
16
|
})
|
|
9
|
-
})
|
|
17
|
+
})
|
|
@@ -4,7 +4,7 @@ import { LoginType } from '@/enum/auth.enum'
|
|
|
4
4
|
|
|
5
5
|
export interface EventsSdkOptions {
|
|
6
6
|
isNewStack?: boolean,
|
|
7
|
-
servers
|
|
7
|
+
servers?: Server[],
|
|
8
8
|
loginUrl: string,
|
|
9
9
|
getSettingsUrl?: string
|
|
10
10
|
fallbackServer: Server,
|
|
@@ -70,7 +70,6 @@ export interface ReconnectOptions {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
export enum ServerParameter {
|
|
73
|
-
|
|
74
|
-
NEXT = 'next'
|
|
75
|
-
PREVIOUS = 'previous'
|
|
73
|
+
MAIN = 'main',
|
|
74
|
+
NEXT = 'next'
|
|
76
75
|
}
|
|
@@ -39,9 +39,9 @@ export class SocketIoClass{
|
|
|
39
39
|
const server = this.eventsSdkClass.server
|
|
40
40
|
|
|
41
41
|
try {
|
|
42
|
-
const domain = server.Domain
|
|
42
|
+
const domain = server ? server.Domain : this.eventsSdkClass.URL
|
|
43
43
|
|
|
44
|
-
const url = `${protocol}://${domain}`
|
|
44
|
+
const url = server ? `${protocol}://${domain}` : this.eventsSdkClass.URL
|
|
45
45
|
|
|
46
46
|
// this.eventsSdkClass.loggerClass.log(
|
|
47
47
|
// LoggerTypeEnum.INFO,
|
|
@@ -50,6 +50,14 @@ export class SocketIoClass{
|
|
|
50
50
|
// url
|
|
51
51
|
// )
|
|
52
52
|
|
|
53
|
+
this.eventsSdkClass.emit(
|
|
54
|
+
EventsEnum.ONLINE_STATUS_EVENT,
|
|
55
|
+
{
|
|
56
|
+
isSocketConnected: false,
|
|
57
|
+
attemptToConnect: url
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
|
|
53
61
|
const options: Partial<ManagerOptions & SocketOptions> = {
|
|
54
62
|
reconnection: false,
|
|
55
63
|
upgrade: false,
|
|
@@ -66,8 +74,10 @@ export class SocketIoClass{
|
|
|
66
74
|
}
|
|
67
75
|
}
|
|
68
76
|
|
|
69
|
-
if (this.ioFunction) {
|
|
77
|
+
if (this.ioFunction && url) {
|
|
70
78
|
this.io = this.ioFunction(url, options)
|
|
79
|
+
} else {
|
|
80
|
+
throw new Error('Socket server url no defined')
|
|
71
81
|
}
|
|
72
82
|
} catch (e) {
|
|
73
83
|
// this.log(ERROR, e);
|
|
@@ -87,6 +97,12 @@ export class SocketIoClass{
|
|
|
87
97
|
.on(EventsEnum.KEEP_ALIVE_RESPONSE, (data) => this.onKeepAliveResponse(data))
|
|
88
98
|
.on(EventsEnum.CONNECT, () => this.onConnect())
|
|
89
99
|
.on(EventsEnum.DISCONNECT, () => this.onDisconnect())
|
|
100
|
+
.on(EventsEnum.CONNECT_ERROR_EVENT, () => {
|
|
101
|
+
this.eventsSdkClass.emit(EventsEnum.ONLINE_STATUS_EVENT, { isSocketConnected: false })
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
this.eventsSdkClass.connect(ServerParameter.NEXT)
|
|
104
|
+
},this.eventsSdkClass.options.reconnectionDelay)
|
|
105
|
+
})
|
|
90
106
|
}
|
|
91
107
|
}
|
|
92
108
|
|
|
@@ -170,9 +186,7 @@ export class SocketIoClass{
|
|
|
170
186
|
return
|
|
171
187
|
}
|
|
172
188
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
this.eventsSdkClass.connect(ServerParameter.NEXT, true)
|
|
176
|
-
}, 15000)
|
|
189
|
+
console.log('attempt to connect...')
|
|
190
|
+
this.eventsSdkClass.connect(ServerParameter.NEXT)
|
|
177
191
|
}
|
|
178
192
|
}
|
package/src/enum/events.enum.ts
CHANGED
|
@@ -7,6 +7,7 @@ export enum EventsEnum {
|
|
|
7
7
|
ALL_USERS_STATUS = 'AllUsersStatus',
|
|
8
8
|
CONNECT = 'connect',
|
|
9
9
|
DISCONNECT = 'disconnect',
|
|
10
|
+
CONNECT_ERROR_EVENT = 'connect_error',
|
|
10
11
|
EXTENSION_EVENT = 'ExtensionEvent',
|
|
11
12
|
KEEP_ALIVE = 'keepalive',
|
|
12
13
|
KEEP_ALIVE_RESPONSE = 'keepaliveResponse',
|
package/src/types/events.d.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"host":"localhost:3000","info":{"title":"admin-api","contact":{},"version":"0.01","description":"irst Alpha - Hope it will wok for yall :-)","termsOfService":""},"paths":{"/Account/List/":{"post":{"tags":["Account"],"security":[{"AdminAuthentication":["Admin"]}],"responses":{"200":{"schema":{"$ref":"#/definitions/AccountListResponse"},"description":"Status 200"},"400":{"schema":{"$ref":"#/definitions/Error"},"description":"Error Response"}},"parameters":[{"in":"body","name":"RequestBody","schema":{"$ref":"#/definitions/AccountListRequest"},"description":"Searching for Account that meets the query. multiple values are support. multiple selections in same feild will be treated as OR, multiple feilds will be searched with OR between them."}],"x-AuthType":["Admin"],"operationId":"AccountList","x-serviceID":3,"x-methodName":"List","x-serviceName":"Account"}},"/Account/Update/":{"post":{"tags":["Account"],"security":[{"AdminAuthentication":["Admin"]}],"responses":{"200":{"schema":{"$ref":"#/definitions/Response"},"description":"Status 200"},"400":{"schema":{"$ref":"#/definitions/Error"},"description":"Error Response"}},"parameters":[],"x-AuthType":["Admin"],"operationId":"AccountUpdate","x-serviceID":3,"x-methodName":"Update","x-serviceName":"Account"}}},"schemes":["https"],"swagger":"2.0","basePath":"/v1","consumes":["application/json"],"produces":["application/json"],"definitions":{"Error":{"type":"object","required":["Description","Status"],"properties":{"Status":{"type":"integer","example":400,"description":"Code of the Error"},"Description":{"type":"string","example":"Not found","description":"Textual description of the error"},"ReasonPhrase":{"type":"string","example":"ID not valid","description":"Specific reason for the error"}}},"Response":{"type":"object","required":["Description","ReasonPhrase","Status"],"properties":{"Status":{"type":"integer","example":200,"description":"Code of response"},"Description":{"type":"string","example":"OK","description":"Description of response"},"ReasonPhrase":{"type":"string","description":"Data of response"}}},"AccountAdd":{"type":"object","properties":{}},"ProviderAdd":{"type":"object","properties":{}},"ProviderDisable":{"type":"object","properties":{}},"ProvidersAddList":{"type":"object","properties":{}},"ProviderPrefixAdd":{"type":"object","properties":{}},"AccountListRequest":{"type":"object","properties":{}},"AccountListResponse":{"type":"object","properties":{}},"ProviderListResponse":{"type":"object","properties":{}},"ProviderPrefixUpdate":{"type":"object","properties":{}},"ProvidersDisableList":{"type":"object","properties":{}},"ProviderPrefixAddList":{"type":"object","properties":{}},"ProviderPrefixUpdateList":{"type":"object","properties":{}},"ProviderPrefixBulkRequest":{"type":"object","properties":{}},"ProviderPrefixBulkResponse":{"type":"object","properties":{}},"ProviderPrefixListResponse":{"type":"object","properties":{}},"ProviderPrefixUpdateResponse":{"type":"object","properties":{}}},"securityDefinitions":{}}
|