buzzk 2.3.2 → 2.3.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/lib/chat.js +75 -14
- package/lib/tool.js +7 -0
- package/lib/vm.js +4 -2
- package/package.json +1 -1
package/lib/chat.js
CHANGED
|
@@ -48,7 +48,9 @@ class chzzkChat {
|
|
|
48
48
|
#status = {
|
|
49
49
|
ws: false,
|
|
50
50
|
established: false,
|
|
51
|
-
|
|
51
|
+
watchDogID: null,
|
|
52
|
+
reconnect: true,
|
|
53
|
+
reconnectID: null
|
|
52
54
|
}
|
|
53
55
|
//Private
|
|
54
56
|
|
|
@@ -80,13 +82,22 @@ class chzzkChat {
|
|
|
80
82
|
|
|
81
83
|
const socketOption = {
|
|
82
84
|
reconnection: false,
|
|
83
|
-
"force new connection": true,
|
|
84
85
|
"connect timeout": 6000,
|
|
85
86
|
transports: ["websocket"]
|
|
86
87
|
};
|
|
87
88
|
|
|
88
89
|
this.#ws = io.connect(session, socketOption);
|
|
89
90
|
|
|
91
|
+
if (!this.#status.watchDogID) {
|
|
92
|
+
this.#status.watchDogID = setTimeout(() => {
|
|
93
|
+
this.#status.watchDogID = null;
|
|
94
|
+
|
|
95
|
+
if (this.#status.established) return;
|
|
96
|
+
|
|
97
|
+
return this.#rePromise();
|
|
98
|
+
}, 20000);
|
|
99
|
+
}
|
|
100
|
+
|
|
90
101
|
this.#ws.on("connect", async (data) => {
|
|
91
102
|
console.log("[WS] Connected!");
|
|
92
103
|
});
|
|
@@ -106,6 +117,7 @@ class chzzkChat {
|
|
|
106
117
|
}
|
|
107
118
|
});
|
|
108
119
|
|
|
120
|
+
//Events
|
|
109
121
|
this.#ws.on("CHAT", (data) => {
|
|
110
122
|
if (!this.#callbacks.message) return;
|
|
111
123
|
data = JSON.parse(data);
|
|
@@ -130,35 +142,84 @@ class chzzkChat {
|
|
|
130
142
|
let donationData = new chzzkDonationData(data.donationType, data.payAmount, data.donatorChannelId, data.donatorNickname, data.donationText, data.emojis);
|
|
131
143
|
return this.#callbacks.donation(donationData);
|
|
132
144
|
});
|
|
145
|
+
//Events
|
|
133
146
|
|
|
147
|
+
//Disconnect Handle
|
|
134
148
|
this.#ws.on("error", (error) => {
|
|
135
|
-
|
|
149
|
+
if (!this.#status.reconnect) return;
|
|
136
150
|
|
|
137
|
-
|
|
151
|
+
console.log("[WS] Disconnected! (" + error + ")");
|
|
152
|
+
|
|
153
|
+
return this.#rePromise();
|
|
138
154
|
});
|
|
139
155
|
|
|
140
156
|
this.#ws.on("disconnect", (data) => {
|
|
141
157
|
if (this.#callbacks.disconnect) this.#callbacks.disconnect(data);
|
|
142
|
-
|
|
143
158
|
if (!this.#status.reconnect) return;
|
|
144
159
|
|
|
145
160
|
console.log("[WS] Disconnected! (" + data + ")");
|
|
146
161
|
|
|
147
|
-
this.#
|
|
148
|
-
|
|
162
|
+
return this.#rePromise();
|
|
163
|
+
});
|
|
149
164
|
|
|
150
|
-
|
|
151
|
-
if (!this.#status.
|
|
165
|
+
this.#ws.on("connect_error", (data) => {
|
|
166
|
+
if (!this.#status.reconnect) return;
|
|
152
167
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
this.#
|
|
156
|
-
|
|
168
|
+
console.log("[WS] Disconnected! (" + data + ")");
|
|
169
|
+
|
|
170
|
+
return this.#rePromise();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
this.#ws.on("connect_timeout", () => {
|
|
174
|
+
if (!this.#status.reconnect) return;
|
|
175
|
+
|
|
176
|
+
console.log("[WS] Disconnected! (Connect Timeout)");
|
|
177
|
+
|
|
178
|
+
return this.#rePromise();
|
|
157
179
|
});
|
|
158
180
|
|
|
181
|
+
this.#ws.on("handshake_timeout", () => {
|
|
182
|
+
if (!this.#status.reconnect) return;
|
|
183
|
+
|
|
184
|
+
console.log("[WS] Disconnected! (Handshake Timeout)");
|
|
185
|
+
|
|
186
|
+
return this.#rePromise();
|
|
187
|
+
});
|
|
188
|
+
//Disconnect Handle
|
|
189
|
+
|
|
159
190
|
});
|
|
160
191
|
}
|
|
161
192
|
|
|
193
|
+
async #rePromise() {
|
|
194
|
+
if (!this.#status.reconnect) return;
|
|
195
|
+
if (this.#status.reconnectID) return;
|
|
196
|
+
|
|
197
|
+
let reIntv = Math.floor(Math.random() * 15000) + 8000;
|
|
198
|
+
|
|
199
|
+
this.#status.reconnectID = setTimeout(() => {
|
|
200
|
+
try {
|
|
201
|
+
if (this.#ws) this.#ws.off();
|
|
202
|
+
if (this.#ws) this.#ws.disconnect();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
catch(error) {
|
|
206
|
+
console.log("[WS] Cleanup Disconnect Failed.");
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
this.#status.ws = false;
|
|
210
|
+
this.#status.established = false;
|
|
211
|
+
|
|
212
|
+
this.#ws = null;
|
|
213
|
+
this.#channelID = null;
|
|
214
|
+
this.#session = null;
|
|
215
|
+
|
|
216
|
+
setTimeout(() => {
|
|
217
|
+
this.#status.reconnectID = null;
|
|
218
|
+
return this.connect();
|
|
219
|
+
}, 2000);
|
|
220
|
+
}, reIntv);
|
|
221
|
+
}
|
|
222
|
+
|
|
162
223
|
/**
|
|
163
224
|
* @param {string} message
|
|
164
225
|
* @returns {Promise<boolean>}
|
|
@@ -289,7 +350,7 @@ class chzzkChat {
|
|
|
289
350
|
this.#status.reconnect = false;
|
|
290
351
|
|
|
291
352
|
await this.#ws.off();
|
|
292
|
-
await this.#ws.
|
|
353
|
+
await this.#ws.disconnect();
|
|
293
354
|
|
|
294
355
|
this.#status.ws = false;
|
|
295
356
|
this.#status.established = false;
|
package/lib/tool.js
CHANGED
|
@@ -22,6 +22,7 @@ function clientGet (path) {
|
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
.catch((error) => {
|
|
25
|
+
console.log(error);
|
|
25
26
|
return resolve({"code": 500});
|
|
26
27
|
});
|
|
27
28
|
|
|
@@ -48,6 +49,7 @@ function clientPost (path, body) {
|
|
|
48
49
|
})
|
|
49
50
|
|
|
50
51
|
.catch((error) => {
|
|
52
|
+
console.log(error);
|
|
51
53
|
return resolve({"code": 500});
|
|
52
54
|
});
|
|
53
55
|
|
|
@@ -72,6 +74,7 @@ function userGet (token, path) {
|
|
|
72
74
|
})
|
|
73
75
|
|
|
74
76
|
.catch((error) => {
|
|
77
|
+
console.log(error);
|
|
75
78
|
return resolve({"code": 500});
|
|
76
79
|
});
|
|
77
80
|
|
|
@@ -97,6 +100,7 @@ function userPost (token, path, body) {
|
|
|
97
100
|
})
|
|
98
101
|
|
|
99
102
|
.catch((error) => {
|
|
103
|
+
console.log(error);
|
|
100
104
|
return resolve({"code": 500});
|
|
101
105
|
});
|
|
102
106
|
|
|
@@ -120,6 +124,7 @@ function reqChzzk (path) {
|
|
|
120
124
|
})
|
|
121
125
|
|
|
122
126
|
.catch((error) => {
|
|
127
|
+
console.log(error);
|
|
123
128
|
return resolve({"code": 500});
|
|
124
129
|
});
|
|
125
130
|
|
|
@@ -166,6 +171,7 @@ function reqGame (path) {
|
|
|
166
171
|
})
|
|
167
172
|
|
|
168
173
|
.catch((error) => {
|
|
174
|
+
console.log(error);
|
|
169
175
|
return resolve({"code": 500});
|
|
170
176
|
});
|
|
171
177
|
|
|
@@ -188,6 +194,7 @@ function reqNaver (path) {
|
|
|
188
194
|
})
|
|
189
195
|
|
|
190
196
|
.catch((error) => {
|
|
197
|
+
console.log(error);
|
|
191
198
|
return resolve({"code": 500});
|
|
192
199
|
});
|
|
193
200
|
|
package/lib/vm.js
CHANGED
|
@@ -7,8 +7,10 @@ function getVersion () {
|
|
|
7
7
|
|
|
8
8
|
async function check () {
|
|
9
9
|
let localPkg = require("../package.json");
|
|
10
|
-
let remotePkg = await axios.get("https://raw.githubusercontent.com/Emin-G/buzzk/master/package.json")
|
|
11
|
-
|
|
10
|
+
let remotePkg = await axios.get("https://raw.githubusercontent.com/Emin-G/buzzk/master/package.json").catch((error) => {
|
|
11
|
+
return;
|
|
12
|
+
});
|
|
13
|
+
if (!remotePkg || remotePkg.status != 200) return console.log("[BUZZK] 최신 버전에 대한 정보를 불러오지 못했습니다.");
|
|
12
14
|
|
|
13
15
|
remotePkg = remotePkg.data;
|
|
14
16
|
|