@voicenter-team/events-sdk 0.0.2 → 0.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voicenter-team/events-sdk",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
5
  "main": "dist/voicenter-events-sdk.cjs.js",
6
6
  "jsdelivr": "dist/voicenter-events-sdk.umd.js",
@@ -127,17 +127,29 @@ class EventsSdkClass{
127
127
  this.server = this.findCurrentServer()
128
128
  }
129
129
 
130
+ this.socketIoClass.doReconnect = true
131
+
130
132
  this.socketIoClass.initSocketConnection()
131
133
 
132
134
  this.socketIoClass.initSocketEvents()
133
135
 
134
136
  this.socketIoClass.initKeepAlive()
135
137
 
138
+ // TODO: check if it is needed here
136
139
  if (skipLogin) {
137
140
  return
138
141
  }
139
142
  }
140
143
 
144
+ public disconnect () {
145
+ this.socketIoClass.doReconnect = false
146
+ this.socketIoClass.closeAllConnections()
147
+ }
148
+
149
+ public clearKeepAliveInterval () {
150
+ this.socketIoClass.clearKeepAliveInterval()
151
+ }
152
+
141
153
  private findCurrentServer (): Server {
142
154
  if (this.servers.length) {
143
155
  this.server = this.servers[0]
@@ -14,6 +14,7 @@ export class SocketIoClass{
14
14
  public io: SocketTyped | undefined
15
15
  public ioFunction: TypedSocketIo | undefined
16
16
  public lastEventTimestamp = new Date().getTime()
17
+ public doReconnect = true
17
18
  private keepAliveInterval: ReturnType<typeof setInterval> | undefined
18
19
  private keepReconnectInterval: ReturnType<typeof setInterval> | undefined
19
20
  private connected = false
@@ -82,10 +83,14 @@ export class SocketIoClass{
82
83
  }
83
84
  }
84
85
 
85
- public initKeepAlive () {
86
+ public clearKeepAliveInterval () {
86
87
  if (this.keepAliveInterval) {
87
88
  clearInterval(this.keepAliveInterval)
88
89
  }
90
+ }
91
+
92
+ public initKeepAlive () {
93
+ this.clearKeepAliveInterval()
89
94
 
90
95
  this.keepAliveInterval = setInterval(async () => {
91
96
  const now = new Date().getTime()
@@ -159,6 +164,10 @@ export class SocketIoClass{
159
164
 
160
165
  this.eventsSdkClass.emit(EventsEnum.ONLINE_STATUS_EVENT, { isSocketConnected: false })
161
166
 
167
+ if (!this.doReconnect) {
168
+ return
169
+ }
170
+
162
171
  this.keepReconnectInterval = setInterval(() => {
163
172
  console.log('attempt to connect...')
164
173
  this.eventsSdkClass.connect(ServerParameter.NEXT, true)
package/src/index.ts CHANGED
@@ -1,3 +1,9 @@
1
1
  import EventsSdkClass from '@/classes/events-sdk/events-sdk.class'
2
+ import { Environment } from '@/classes/events-sdk/events-sdk.types'
3
+ import { EventsEnum } from '@/enum/events.enum'
2
4
 
5
+ export {
6
+ Environment,
7
+ EventsEnum
8
+ }
3
9
  export default EventsSdkClass