buzzk 1.3.3 โ†’ 1.5.0

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 (3) hide show
  1. package/README.md +16 -8
  2. package/lib/chat.js +46 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -17,21 +17,19 @@
17
17
 
18
18
  ## ๐Ÿ“– ์—…๋ฐ์ดํŠธ ๋‚ด์—ญ
19
19
 
20
- - ํ•จ์ˆ˜ ์ด๋ฆ„ ์ˆ˜์ •
21
-
22
- **ํ•˜๋‹จ์˜ 1.3.0 ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ ๊ฐ€์ด๋“œ ์ฐธ๊ณ **
20
+ - ์ฑ„ํŒ…์ฐฝ ์—ฐ๊ฒฐ์ด ๋Š๊ธฐ๋˜ ๋ฌธ์ œ ํ•ด๊ฒฐ (Ping ์ถ”๊ฐ€)
21
+ - ์ฑ„ํŒ…์ฐฝ ID ๋ณ€๊ฒฝ ์‹œ ์žฌ์—ฐ๊ฒฐ ๊ตฌํ˜„
23
22
 
24
- >
23
+ >
25
24
 
25
+ - onDisconnect ํ•จ์ˆ˜ ์ถ”๊ฐ€
26
26
  - ์ฑ„ํŒ…์— ์—ฐ๊ฒฐํ•˜์ง€ ๋ชปํ–ˆ๋˜ ๋ฌธ์ œ ํ•ด๊ฒฐ (UID๋ฅผ ์ œ๊ฑธ๋กœ ํ•ด๋†จ๋˜... ๋น™๊ตฌ...)
27
+ - ํ•จ์ˆ˜ ์ด๋ฆ„ ์ˆ˜์ •
27
28
 
28
- >
29
+ **ํ•˜๋‹จ์˜ 1.3.0 ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ ๊ฐ€์ด๋“œ ์ฐธ๊ณ **
29
30
 
30
31
  - channelID๋กœ ์ฑ„๋„ ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ ํ•จ์ˆ˜ ์ถ”๊ฐ€
31
32
  - ws ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ข…์†์„ฑ ์ถ”๊ฐ€
32
-
33
- >
34
-
35
33
  - ์ž๋™์™„์„ฑ ๊ธฐ๋Šฅ ์ง€์›
36
34
  - ํŒ”๋กœ์šฐ / ์–ธํŒ”๋กœ์šฐ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
37
35
  - live.getLiveDetail์˜ Return ๊ฐ’์— chatLimit ์ถ”๊ฐ€ (ํŒ”๋กœ์šฐ ๋Œ€์ƒ ์ฑ„ํŒ… ๋“ฑ...)
@@ -137,6 +135,10 @@
137
135
  //์ฑ„ํŒ… ๋ณด๋‚ด๊ธฐ (login ํ›„์—๋งŒ ๊ฐ€๋Šฅ)
138
136
  }
139
137
  });
138
+
139
+ chat.onDisconnect(async () => { //์ฑ„ํŒ…์ฐฝ ์—ฐ๊ฒฐ์ด ๋Š๊ฒผ์„ ๋•Œ
140
+ //TODO
141
+ });
140
142
 
141
143
  }
142
144
 
@@ -302,6 +304,12 @@ dotenv์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๋งค์šฐ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค.
302
304
 
303
305
  </details>
304
306
 
307
+ chat.onDisconnect(() => { //์ฑ„ํŒ…์ฐฝ ์—ฐ๊ฒฐ์ด ๋Š๊ฒผ์„ ๋•Œ
308
+ //TODO
309
+ });
310
+
311
+ >
312
+
305
313
  await chat.send("ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹ใ…‹"); //์ฑ„ํŒ… ๋ณด๋‚ด๊ธฐ (login ํ›„์—๋งŒ ๊ฐ€๋Šฅ)
306
314
 
307
315
  >
package/lib/chat.js CHANGED
@@ -18,6 +18,7 @@ class chzzkChat {
18
18
  #chatID;
19
19
 
20
20
  #pollingStatus = false;
21
+ #pingStatus = false;
21
22
  //Private
22
23
 
23
24
  /**
@@ -106,7 +107,10 @@ class chzzkChat {
106
107
  //Ping Pong
107
108
 
108
109
  //Connected
109
- else if (data.cmd == 10100) resolve(true);
110
+ else if (data.cmd == 10100) {
111
+ if (!this.#pingStatus) this.#ping();
112
+ resolve(true);
113
+ }
110
114
  //Connected
111
115
  });
112
116
  //WS Message
@@ -208,6 +212,17 @@ class chzzkChat {
208
212
  });
209
213
  }
210
214
 
215
+ /**
216
+ * @param {function} callback
217
+ */
218
+ onDisconnect(callback) {
219
+ if (!this.#ws) return callback(null);
220
+
221
+ this.#ws.on("close", () => {
222
+ callback();
223
+ });
224
+ }
225
+
211
226
  /**
212
227
  * @param {?number} size
213
228
  * @return {Promise<chzzkMessages>}
@@ -285,12 +300,40 @@ class chzzkChat {
285
300
 
286
301
  //Get ChatID
287
302
  let cidRes = await getStatus(this.channelID);
288
- this.#chatID = cidRes.chatID;
303
+ if (cidRes.chatID && cidRes.chatID != this.#chatID) {
304
+ this.#chatID = cidRes.chatID;
305
+
306
+ //Reconnect
307
+ this.#pollingStatus = false;
308
+ await this.disconnect();
309
+ await this.connect();
310
+ return;
311
+ //Reconnect
312
+ }
289
313
  //Get ChatID
290
314
 
315
+ let interval;
316
+ if (cidRes.polling && cidRes.polling.callPeriodMilliSecond) interval = cidRes.polling.callPeriodMilliSecond;
317
+ else interval = 10000;
318
+
291
319
  setTimeout(() => {
292
320
  return this.#polling();
293
- }, cidRes.polling.callPeriodMilliSecond);
321
+ }, interval);
322
+ }
323
+
324
+ async #ping () {
325
+ if (!this.#ws) return this.#pingStatus = false;
326
+ this.#pingStatus = true;
327
+
328
+ let pingOpt = {
329
+ "ver": "2",
330
+ "cmd": 0
331
+ };
332
+ this.#ws.send(JSON.stringify(pingOpt));
333
+
334
+ setTimeout(() => {
335
+ return this.#ping();
336
+ }, 20000);
294
337
  }
295
338
  }
296
339
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "buzzk",
3
3
  "displayName": "BUZZK",
4
- "version": "1.3.3",
4
+ "version": "1.5.0",
5
5
  "description": "๋ฟŒ์ง€์ง (BUZZK) - ์น˜์ง€์ง(CHZZK) ์ฑ—๋ด‡์„ ๋”์šฑ ์‰ฝ๊ฒŒ ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ๋„๋ก ๋•๋Š” ๋น„๊ณต์‹ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ.",
6
6
  "main": "lib/index.js",
7
7
  "type": "commonjs",