@voicenter-team/events-sdk 0.0.29 → 0.0.30

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.
Files changed (52) hide show
  1. package/dist/voicenter-events-sdk.cjs.js.map +1 -1
  2. package/dist/voicenter-events-sdk.es.js.map +1 -1
  3. package/dist/voicenter-events-sdk.iife.js.map +1 -1
  4. package/dist/voicenter-events-sdk.umd.js.map +1 -1
  5. package/package.json +59 -56
  6. package/.eslintrc.cjs +0 -17
  7. package/.github/workflows/main.yml +0 -16
  8. package/.idea/VoicenterEventsSDK.iml +0 -12
  9. package/.idea/git_toolbox_prj.xml +0 -15
  10. package/.idea/inspectionProfiles/Project_Default.xml +0 -6
  11. package/.idea/jsLibraryMappings.xml +0 -6
  12. package/.idea/jsLinters/eslint.xml +0 -7
  13. package/.idea/modules.xml +0 -8
  14. package/.idea/vcs.xml +0 -6
  15. package/.nvmrc +0 -1
  16. package/TODELETE_TEMP/events.json +0 -69122
  17. package/TODELETE_TEMP/temphelper.cjs +0 -101
  18. package/docs/package-lock.json +0 -3827
  19. package/docs/package.json +0 -26
  20. package/docs/src/.vuepress/client.js +0 -8
  21. package/docs/src/.vuepress/components/Demo.vue +0 -303
  22. package/docs/src/.vuepress/config.js +0 -60
  23. package/docs/src/.vuepress/public/favicon.ico +0 -0
  24. package/docs/src/.vuepress/public/images/logo.png +0 -0
  25. package/docs/src/.vuepress/styles/index.scss +0 -0
  26. package/docs/src/.vuepress/styles/index.styl +0 -8
  27. package/docs/src/.vuepress/styles/palette.styl +0 -10
  28. package/docs/src/demo.md +0 -7
  29. package/docs/src/index.md +0 -4
  30. package/jest.config.js +0 -11
  31. package/src/classes/auth/auth.class.ts +0 -355
  32. package/src/classes/event-emitter/event-emitter.class.ts +0 -73
  33. package/src/classes/events-sdk/events-sdk-default-options.ts +0 -34
  34. package/src/classes/events-sdk/events-sdk.class.ts +0 -208
  35. package/src/classes/events-sdk/events-sdk.test.ts +0 -17
  36. package/src/classes/events-sdk/events-sdk.types.ts +0 -75
  37. package/src/classes/logger/logger.class.ts +0 -61
  38. package/src/classes/socket-io/socket-io.class.ts +0 -220
  39. package/src/classes/socket-io/socket-io.d.ts +0 -10
  40. package/src/classes/socket-io/versions/index.ts +0 -52
  41. package/src/classes/socket-io/versions/v1_3_7.js +0 -2083
  42. package/src/classes/storage/storage.class.ts +0 -51
  43. package/src/enum/auth.enum.ts +0 -4
  44. package/src/enum/logger.enum.ts +0 -5
  45. package/src/index.ts +0 -13
  46. package/src/types/auth.d.ts +0 -53
  47. package/src/types/events.d.ts +0 -83
  48. package/src/types/listeners.d.ts +0 -37
  49. package/src/types/public-api.d.ts +0 -39
  50. package/src/types/socket.d.ts +0 -5
  51. package/tsconfig.json +0 -47
  52. package/vite.config.ts +0 -45
@@ -1,355 +0,0 @@
1
- import md5 from 'md5'
2
-
3
- import EventsSdkClass from '@/classes/events-sdk/events-sdk.class'
4
- import { EventsSdkOptions, ServerParameter } from '@/classes/events-sdk/events-sdk.types'
5
- import {
6
- ExternalLoginNewStackResponseData,
7
- ExternalLoginOldStackResponseData,
8
- ExternalLoginResponse,
9
- LoginSessionData,
10
- LoginSessionPayload,
11
- Settings
12
- } from '@/types/auth'
13
- import { LoginType } from '@/enum/auth.enum'
14
- import { StorageClass } from '@/classes/storage/storage.class'
15
- import { LoggerTypeEnum } from '@/enum/logger.enum'
16
-
17
- class AuthClass{
18
- constructor (private readonly eventsSdkClass: EventsSdkClass) {
19
- this.eventsSdkClass = eventsSdkClass
20
-
21
- this.storageKey = ''
22
- }
23
-
24
- private delay = 1000
25
- public lastLoginTimestamp: number | undefined
26
- public token: string | undefined
27
-
28
- private storageKey: string
29
-
30
- public async login (options: EventsSdkOptions) {
31
- const payload: LoginSessionPayload = {
32
- token: options.token,
33
- email: options.email,
34
- password: options.password
35
- }
36
-
37
- this.storageKey = md5(JSON.stringify({
38
- ...options,
39
- loggerSocketConnection: null
40
- }))
41
-
42
- if (this.lastLoginTimestamp && this.lastLoginTimestamp + this.delay > new Date().getTime()) {
43
- return
44
- }
45
-
46
- this.updateLastLoginTimestamp()
47
-
48
- const isLoggedIn = await this.checkLoginStatus(this.storageKey)
49
-
50
- if (!isLoggedIn) {
51
- StorageClass.clearSessionStorage()
52
-
53
- await this.userLoginFunction(payload, this.storageKey, options.loginType)
54
- }
55
- }
56
-
57
- public updateLastLoginTimestamp () {
58
- this.lastLoginTimestamp = new Date().getTime()
59
- }
60
-
61
- private async checkLoginStatus (key: string): Promise<boolean> {
62
- const loginSessionData = await StorageClass.getSessionStorageDataByKey<LoginSessionData>(key)
63
-
64
- if (loginSessionData) {
65
- this.eventsSdkClass.loggerClass.log(LoggerTypeEnum.INFO, 'got data from session', loginSessionData)
66
-
67
- this.onLoginResponse(loginSessionData)
68
-
69
- return true
70
- }
71
-
72
- return false
73
- }
74
-
75
- private async userLoginFunction (
76
- payload: LoginSessionPayload,
77
- key: string,
78
- loginType: LoginType,
79
- ) {
80
- let externalLoginResponse
81
-
82
- let settings
83
-
84
- let loginSessionData: Partial<LoginSessionData>
85
-
86
- if (this.eventsSdkClass.options.isNewStack) {
87
- externalLoginResponse = await this.externalLogin<ExternalLoginNewStackResponseData>(
88
- this.eventsSdkClass.options.loginUrl,
89
- payload,
90
- loginType,
91
- )
92
-
93
- settings = await this.getSettings(externalLoginResponse.Data.AccessToken)
94
-
95
- loginSessionData = {
96
- ...externalLoginResponse.Data,
97
- ...settings
98
- }
99
- } else {
100
- externalLoginResponse = await this.externalLogin<ExternalLoginOldStackResponseData>(
101
- this.eventsSdkClass.options.loginUrl,
102
- payload,
103
- loginType,
104
- )
105
-
106
- loginSessionData = {
107
- ...externalLoginResponse.Data.Socket,
108
- }
109
- }
110
-
111
- this.onLoginResponse(loginSessionData)
112
-
113
- await StorageClass.updateSessionStorageKey(key, loginSessionData)
114
- }
115
-
116
- private onLoginResponse (loginSessionData: Partial<LoginSessionData>) {
117
- if (!this.eventsSdkClass.options.isNewStack && this.eventsSdkClass.options.servers) {
118
- this.eventsSdkClass.servers = [ ...this.eventsSdkClass.options.servers ]
119
- this.eventsSdkClass.server = this.eventsSdkClass.servers.reduce((prev, current) =>
120
- (prev.Priority > current.Priority) ? prev : current
121
- )
122
- }
123
- if (this.eventsSdkClass.options.isNewStack && this.eventsSdkClass.options.servers) {
124
- this.eventsSdkClass.servers = [ ...this.eventsSdkClass.options.servers ]
125
- this.eventsSdkClass.server = this.eventsSdkClass.servers.reduce((prev, current) =>
126
- (prev.Priority > current.Priority) ? prev : current
127
- )
128
- }
129
- if (loginSessionData.MonitorList && loginSessionData.MonitorList.length) {
130
- this.eventsSdkClass.servers = [ ...loginSessionData.MonitorList ]
131
- this.eventsSdkClass.server = this.eventsSdkClass.servers.reduce((prev, current) =>
132
- (prev.Priority > current.Priority) ? prev : current
133
- )
134
- }
135
- if (!this.eventsSdkClass.options.isNewStack && !this.eventsSdkClass.servers.length && loginSessionData.URLList) {
136
- this.eventsSdkClass.URLList = loginSessionData.URLList
137
- }
138
- if (!this.eventsSdkClass.options.isNewStack && !this.eventsSdkClass.URLList.length && !this.eventsSdkClass.servers.length) {
139
- throw new Error('Socket servers not defined')
140
- }
141
- if (this.eventsSdkClass.options.isNewStack && !this.eventsSdkClass.servers.length) {
142
- throw new Error('Socket servers not defined')
143
- }
144
- if (this.eventsSdkClass.server) {
145
- this.eventsSdkClass.socketIoClass.getSocketIoFunction(`v=${this.eventsSdkClass.server.Version}`)
146
- }
147
- if (!this.eventsSdkClass.server && this.eventsSdkClass.URLList.length) {
148
- this.eventsSdkClass.socketIoClass.getSocketIoFunction(`v=${loginSessionData.Client}`)
149
- }
150
- if (loginSessionData.IdentityCode) {
151
- this.token = loginSessionData.IdentityCode
152
- this.eventsSdkClass.connect(ServerParameter.MAIN)
153
- }
154
- if (loginSessionData.Token) {
155
- this.token = loginSessionData.Token
156
- this.eventsSdkClass.connect(ServerParameter.MAIN)
157
- }
158
- if (loginSessionData.RefreshToken && loginSessionData.IdentityCodeExpiry && this.eventsSdkClass.options.loginType === LoginType.USER) {
159
- this.eventsSdkClass.options.refreshToken = loginSessionData.RefreshToken
160
- this.eventsSdkClass.options.tokenExpiry = loginSessionData.IdentityCodeExpiry
161
- this.handleTokenExpiry()
162
- }
163
- if (loginSessionData.RefreshToken && loginSessionData.TokenExpiry && this.eventsSdkClass.options.loginType === LoginType.USER) {
164
- this.eventsSdkClass.options.refreshToken = loginSessionData.RefreshToken
165
- this.eventsSdkClass.options.tokenExpiry = loginSessionData.TokenExpiry
166
- this.handleTokenExpiry()
167
- }
168
- }
169
-
170
- public handleTokenExpiry () {
171
- if (!this.eventsSdkClass.options.refreshTokenUrl) {
172
- throw new Error('refreshTokenUrl not provided')
173
- }
174
-
175
- let date: Date
176
-
177
- if (this.eventsSdkClass.options.tokenExpiry) {
178
- date = new Date(this.eventsSdkClass.options.tokenExpiry)
179
- } else {
180
- return
181
- }
182
-
183
- const timeout = date.getTime() - new Date().getTime() - 5000 // 5 seconds before expire
184
-
185
- const maxAllowedTimeout = Math.min(timeout, 0x7FFFFFFF)
186
-
187
- setTimeout(
188
- async () => {
189
- if (this.eventsSdkClass.options.refreshToken) {
190
- this.eventsSdkClass.socketIoClass.closeAllConnections()
191
-
192
- let settings
193
-
194
- let loginSessionData: Partial<LoginSessionData>
195
-
196
- if (this.eventsSdkClass.options.isNewStack) {
197
- const refreshTokenResponse = await this.refreshToken<ExternalLoginNewStackResponseData>(
198
- this.eventsSdkClass.options.refreshTokenUrl,
199
- this.eventsSdkClass.options.refreshToken
200
- )
201
-
202
- settings = await this.getSettings(refreshTokenResponse.Data.AccessToken)
203
-
204
- loginSessionData = {
205
- ...refreshTokenResponse.Data,
206
- ...settings
207
- }
208
- } else {
209
- const refreshTokenResponse = await this.refreshToken<ExternalLoginOldStackResponseData>(
210
- this.eventsSdkClass.options.refreshTokenUrl,
211
- this.eventsSdkClass.options.refreshToken
212
- )
213
-
214
- loginSessionData = {
215
- ...refreshTokenResponse.Data.Socket,
216
- }
217
- }
218
-
219
- this.onLoginResponse(loginSessionData)
220
-
221
- await StorageClass.updateSessionStorageKey(this.storageKey, loginSessionData)
222
- }
223
- },
224
- maxAllowedTimeout)
225
- }
226
-
227
- private async externalLogin<T> (
228
- url: string,
229
- { password, token, email }: LoginSessionPayload,
230
- loginType: LoginType,
231
- ): Promise<ExternalLoginResponse<T>> {
232
- if (!url) {
233
- throw new Error('loginUrl not provided')
234
- }
235
-
236
- let body: string
237
-
238
- if (this.eventsSdkClass.options.isNewStack) {
239
- if (loginType === LoginType.TOKEN) {
240
- body = JSON.stringify({
241
- identityType: LoginType.TOKEN,
242
- token
243
- })
244
- } else {
245
- body = JSON.stringify({
246
- identityType: LoginType.USER,
247
- username: email,
248
- password,
249
- })
250
- }
251
- } else {
252
- if (this.eventsSdkClass.options.loginType === LoginType.TOKEN) {
253
- body = JSON.stringify({ token })
254
-
255
- url = `${url}/${LoginType.TOKEN}`
256
- } else {
257
- body = JSON.stringify({
258
- email,
259
- pin: password
260
- })
261
-
262
- url = `${url}/${LoginType.USER}`
263
- }
264
- }
265
-
266
- try {
267
- const res = await fetch(url, {
268
- method: 'POST',
269
- headers: {
270
- 'Content-Type': 'application/json'
271
- },
272
- body,
273
- })
274
-
275
- if (!res.ok && res.status === 400) {
276
- throw new Error('Bad body request. Login type or isNewStack values not correct or not provided')
277
- }
278
-
279
- if (!res.ok && res.status === 401) {
280
- throw new Error('Unauthorized. Invalid token provided')
281
- }
282
-
283
- if (!res.ok && res.status === 403) {
284
- throw new Error('Forbidden. Identity token not provided or not valid')
285
- }
286
-
287
- const data = await res.json()
288
-
289
- if (data.error) {
290
- throw new Error(data.error)
291
- }
292
- return data
293
- } catch (error) {
294
- this.eventsSdkClass.loggerClass.log(
295
- LoggerTypeEnum.ERROR,
296
- `External login ${url}`,
297
- error
298
- )
299
-
300
- throw error
301
- }
302
- }
303
-
304
- private async getSettings (token: string): Promise<Settings> {
305
- try {
306
- if (!this.eventsSdkClass.options.getSettingsUrl) {
307
- throw new Error('getSettingsUrl not provided')
308
- }
309
-
310
- const res = await fetch(this.eventsSdkClass.options.getSettingsUrl, {
311
- headers: {
312
- Authorization: `Bearer ${token}`
313
- }
314
- })
315
-
316
- if (!res.ok && res.status === 401) {
317
- throw new Error('Unauthorized. Access token not provided or not valid')
318
- }
319
-
320
- return res.json()
321
- } catch (error) {
322
- this.eventsSdkClass.loggerClass.log(
323
- LoggerTypeEnum.ERROR,
324
- `Get settings ${this.eventsSdkClass.options.getSettingsUrl}`,
325
- error
326
- )
327
-
328
- throw error
329
- }
330
- }
331
-
332
- private async refreshToken<T> (refreshTokenUrl: string, oldRefreshToken: string): Promise<ExternalLoginResponse<T>> {
333
- try {
334
- const res = await fetch(refreshTokenUrl, {
335
- method: 'GET',
336
-
337
- headers: {
338
- 'Content-Type': 'application/json',
339
- Authorization: `Bearer ${oldRefreshToken}`
340
- }
341
- })
342
- return res.json()
343
- } catch (error) {
344
- this.eventsSdkClass.loggerClass.log(
345
- LoggerTypeEnum.ERROR,
346
- `Refresh token ${refreshTokenUrl}`,
347
- error
348
- )
349
-
350
- throw error
351
- }
352
- }
353
- }
354
-
355
- export default AuthClass
@@ -1,73 +0,0 @@
1
- import {
2
- EventCallbackListenersMap,
3
- EventSpecificCallback,
4
- EventTypeData,
5
- EventTypeNames,
6
- GenericEventWrapper
7
- } from '@/types/events'
8
- import { EventsEnum } from '@voicenter-team/real-time-events-types'
9
- import EventsSdkClass from '@/classes/events-sdk/events-sdk.class'
10
-
11
- export class EventEmitterClass{
12
- private listeners: EventCallbackListenersMap = {
13
- [EventsEnum.ALL_EXTENSION_STATUS]: [],
14
- [EventsEnum.ALL_DIALER_STATUS]: [],
15
- [EventsEnum.ALL_USERS_STATUS]: [],
16
- [EventsEnum.QUEUE_EVENT]: [],
17
- [EventsEnum.EXTENSION_EVENT]: [],
18
- [EventsEnum.DIALER_EVENT]: [],
19
- [EventsEnum.LOGIN_SUCCESS]: [],
20
- [EventsEnum.LOGIN_STATUS]: [],
21
- [EventsEnum.KEEP_ALIVE_RESPONSE]: [],
22
- [EventsEnum.ONLINE_STATUS_EVENT]: [],
23
- [EventsEnum.EXTENSIONS_UPDATED]: []
24
- }
25
- private allListeners: Array<(data: GenericEventWrapper) => void> = []
26
-
27
- constructor (private readonly eventsSdkClass: EventsSdkClass) {
28
- this.eventsSdkClass = eventsSdkClass
29
- }
30
-
31
- public on<T extends EventTypeNames> (event: T, callback: EventSpecificCallback<T>): void
32
- public on (event: '*', callback: (data: GenericEventWrapper) => void): void
33
- public on (event: unknown, callback: unknown) {
34
- if (event === '*') {
35
- this.allListeners.push(callback as (data: GenericEventWrapper) => void)
36
- } else {
37
- // Handle specific event type with strong typing
38
- this.listeners[event as EventTypeNames].push(callback as EventSpecificCallback<EventTypeNames>)
39
- }
40
- }
41
-
42
- public off<T extends EventTypeNames> (event: T, callback: EventSpecificCallback<T>): void
43
- public off (event: '*', callback: (data: GenericEventWrapper) => void): void
44
- public off (event: unknown, callback: unknown) {
45
- if (event === '*') {
46
- this.allListeners = this.allListeners.filter(item => item !== callback)
47
- } else {
48
- const data = this.listeners[event as EventTypeNames] as Array<EventSpecificCallback<EventTypeNames>>
49
- const filtered = data.filter(item => item !== callback)
50
-
51
- this.listeners = {
52
- ...this.listeners,
53
- [event as EventTypeNames]: filtered
54
- }
55
- }
56
- }
57
-
58
- public emit <T extends EventTypeNames> (event: T, data: EventTypeData<T>) {
59
- this.eventsSdkClass.socketIoClass.lastEventTimestamp = new Date().getTime()
60
-
61
- this.listeners[event].forEach(callback => callback({
62
- name: event,
63
- data
64
- }))
65
-
66
- const allEventData: GenericEventWrapper = {
67
- name: event,
68
- data: data as any
69
- }
70
-
71
- this.allListeners.forEach((callback) => callback(allEventData))
72
- }
73
- }
@@ -1,34 +0,0 @@
1
- import { EventsSdkOptions } from '@/classes/events-sdk/events-sdk.types'
2
-
3
- export const eventsSdkDefaultOptions: Partial<EventsSdkOptions> = {
4
- isNewStack: false,
5
- forceNew: true,
6
- reconnectionDelay: 10000,
7
- reconnectionDelayMax: 10000,
8
- maxReconnectAttempts: 5,
9
- timeout: 10000,
10
- keepAliveTimeout: 60000,
11
- idleInterval: 60000 * 5,
12
- protocol: 'https',
13
- transports: [ 'websocket' ],
14
- upgrade: false,
15
- serverFetchStrategy: 'static',
16
- serverType: 0,
17
- useLogger: true,
18
- loggerServer: 'http://socketlog.voicenter.co',
19
- loggerConfig: {
20
- logToConsole: true,
21
- overloadGlobalConsole: false,
22
- namespace: 'events-sdk',
23
- socketEmitInterval: 10000,
24
- },
25
- loggerConnectOptions: {
26
- reconnection: true,
27
- reconnectionDelay: 5000,
28
- reconnectionAttempts: 10,
29
- perMessageDeflate: undefined,
30
- upgrade: false,
31
- transports: [ 'websocket' ],
32
- debug: false
33
- },
34
- }
@@ -1,208 +0,0 @@
1
- import AuthClass from '@/classes/auth/auth.class'
2
- import { debounce } from 'lodash'
3
- import { eventsSdkDefaultOptions } from '@/classes/events-sdk/events-sdk-default-options'
4
- import { SocketIoClass } from '@/classes/socket-io/socket-io.class'
5
- import { EventsSdkOptions, ReconnectOptions, Server, ServerParameter } from '@/classes/events-sdk/events-sdk.types'
6
- import { SocketTyped } from '@/types/socket'
7
- import {
8
- EventSpecificCallback,
9
- EventTypeNames,
10
- GenericEventWrapper,
11
- } from '@/types/events'
12
- import { EventsEnum } from '@voicenter-team/real-time-events-types'
13
- import { LoggerClass } from '@/classes/logger/logger.class'
14
- import { EventEmitterClass } from '@/classes/event-emitter/event-emitter.class'
15
-
16
- class EventsSdkClass{
17
- private argumentOptions: EventsSdkOptions
18
- public readonly options: EventsSdkOptions
19
- public servers: Server[] = []
20
- public URLList: string[] = []
21
- public server: Server
22
- public URL: string | undefined
23
- public socket: SocketTyped | undefined
24
- private mainServer: Server | undefined
25
-
26
- private alreadyAttemptedOtherServers: Array<number | string> = []
27
-
28
- public authClass = new AuthClass(this)
29
- public socketIoClass = new SocketIoClass(this)
30
- public loggerClass = new LoggerClass(this)
31
- public eventEmitterClass = new EventEmitterClass(this)
32
-
33
- public reconnectOptions: ReconnectOptions
34
-
35
- public retryConnection
36
-
37
- constructor (options: EventsSdkOptions) {
38
- this.options = {
39
- ...eventsSdkDefaultOptions,
40
- ...options
41
- }
42
-
43
- this.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
- }
50
-
51
- this.server = this.options.fallbackServer
52
-
53
- this.retryConnection = debounce(this.connect.bind(this), this.reconnectOptions.reconnectionDelay, {
54
- leading: true,
55
- trailing: false
56
- })
57
-
58
- this.argumentOptions = {
59
- ...options
60
- }
61
- }
62
-
63
- public on<T extends EventTypeNames> (event: T, callback: EventSpecificCallback<T>): void
64
- public on (event: '*', callback: (data: GenericEventWrapper) => void): void {
65
- this.eventEmitterClass.on(event, callback)
66
- }
67
-
68
- public emit (event: EventsEnum, data: unknown) {
69
- if (this.socketIoClass.io) {
70
- this.socketIoClass.io.emit(event, data)
71
- }
72
- }
73
-
74
- public connect (serverParameter: ServerParameter) {
75
- // if (server === ServerParameter.DEFAULT) {
76
- // serverToConnect = this.findCurrentServer()
77
- // }
78
- //
79
- // if (server === ServerParameter.NEXT) {
80
- // serverToConnect = this.findNextAvailableServer()
81
- // }
82
- //
83
- // if (server === ServerParameter.PREVIOUS) {
84
- // serverToConnect = this.findMaxPriorityServer()
85
- // }
86
-
87
- if (serverParameter === ServerParameter.MAIN) {
88
- this.findMainServer()
89
- }
90
-
91
- if (serverParameter === ServerParameter.NEXT) {
92
- this.findNextServer()
93
- }
94
-
95
- this.socketIoClass.doReconnect = true
96
-
97
- this.socketIoClass.initSocketConnection()
98
-
99
- this.socketIoClass.initSocketEvents()
100
-
101
- this.socketIoClass.initKeepAlive()
102
-
103
- this.loggerClass.init()
104
- }
105
-
106
- public disconnect () {
107
- this.socketIoClass.doReconnect = false
108
- this.socketIoClass.closeAllConnections()
109
- }
110
-
111
- public clearKeepAliveInterval () {
112
- this.socketIoClass.clearKeepAliveInterval()
113
- }
114
-
115
- private findMainServer () {
116
- if (this.servers.length) {
117
- this.mainServer = this.servers.reduce((prev, cur) => {
118
- return cur.Priority > prev.Priority ? cur : prev
119
- })
120
-
121
- this.server = this.mainServer
122
- } else {
123
- if (this.URLList.length) {
124
- this.URL = this.URLList[0]
125
- }
126
- }
127
- }
128
-
129
- private findNextServer () {
130
- if (this.servers.length) {
131
- if (this.server.Priority === this.mainServer!.Priority) {
132
- let filteredServers = this.servers.filter(
133
- server =>
134
- server.Priority !== this.mainServer!.Priority &&
135
- this.alreadyAttemptedOtherServers.indexOf(server.Priority) + 1 === 0
136
- )
137
-
138
- if (!filteredServers.length) {
139
- this.alreadyAttemptedOtherServers = []
140
-
141
- filteredServers = this.servers.filter(
142
- server =>
143
- server.Priority !== this.mainServer!.Priority &&
144
- this.alreadyAttemptedOtherServers.indexOf(server.Priority) + 1 === 0
145
- )
146
- }
147
-
148
- if (filteredServers.length) {
149
- this.server = filteredServers.reduce((prev, cur) => {
150
- return cur.Priority > prev.Priority ? cur : prev
151
- })
152
-
153
- this.alreadyAttemptedOtherServers.push(this.server.Priority)
154
- }
155
- } else {
156
- this.server = this.mainServer!
157
- }
158
- } else {
159
- if (this.URLList.length) {
160
- if (this.URL === this.URLList[0]) {
161
- let filteredServers = this.URLList.filter(
162
- url =>
163
- url !== this.URLList[0] &&
164
- this.alreadyAttemptedOtherServers.indexOf(url) + 1 === 0
165
- )
166
-
167
- if (!filteredServers.length) {
168
- this.alreadyAttemptedOtherServers = []
169
-
170
- filteredServers = this.URLList.filter(
171
- url =>
172
- url !== this.URLList[0] &&
173
- this.alreadyAttemptedOtherServers.indexOf(url) + 1 === 0
174
- )
175
- }
176
-
177
- if (filteredServers.length) {
178
- this.URL = filteredServers[0]
179
-
180
- this.alreadyAttemptedOtherServers.push(this.URL)
181
- }
182
- } else {
183
- this.URL = this.URLList[0]
184
- }
185
- }
186
- }
187
- }
188
-
189
- public async init () {
190
- if (this.socket) {
191
- // this.emit(eventTypes.CLOSE);
192
- }
193
-
194
- await this.authClass.login(this.options)
195
-
196
- this.getServers()
197
-
198
- return true
199
- }
200
-
201
- private getServers () {
202
- if (this.options.serverFetchStrategy === 'static' && this.argumentOptions.servers && Array.isArray(this.argumentOptions.servers) && this.argumentOptions.servers.length > 1) {
203
- this.servers = this.argumentOptions.servers
204
- }
205
- }
206
- }
207
-
208
- export default EventsSdkClass
@@ -1,17 +0,0 @@
1
- import EventsSdkClass from '@/classes/events-sdk/events-sdk.class'
2
- import { LoginType } from '@/enum/auth.enum'
3
-
4
- describe('EventsSdkClass', () => {
5
- it('should be true', () => {
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
-
15
- expect(eventsSdkClass.init()).toBe(true)
16
- })
17
- })