-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
67 lines (49 loc) · 1.27 KB
/
main.js
File metadata and controls
67 lines (49 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const Ws = require('./connect')
class WS extends Ws {
constructor(...args) {
super(...args)
this.___interval = 0
this.___count = 0
this.on('open', this.___ONOPEN)
this.on('close', this.___ONCLOSE)
}
stop = () => {
this.interval = 0
this.close()
}
start = (int) => {
if (int) this.interval = int
else this.interval = this._reconnectInterval
this.connect()
}
setInterval = (int) => {
if (typeof int != 'number') throw 'interval must be a number'
this._reconnectInterval = int
this.interval = int
}
set interval(val) {
if (typeof val != 'number') throw 'interval must be a number'
this.___interval = val
}
get interval() {
return this.___interval
}
___ONOPEN = () => {
this.___count = 0
}
___ONCLOSE = () => {
if (this.interval) {
this.state = 'connecting'
if (this.___count === 0) {
this.___count++
this.connect()
} else {
let dis = this
setTimeout(function () {
dis.connect()
}, dis.interval)
}
}
}
}
module.exports = WS