buzzk 1.9.12 → 1.10.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/lib/chat.js +23 -5
  2. package/lib/live.js +11 -2
  3. package/package.json +1 -1
package/lib/chat.js CHANGED
@@ -74,7 +74,9 @@ class chzzkChat {
74
74
  //Load Balancing
75
75
 
76
76
  //Connect Web Socket
77
- this.#ws = new WebSocket("wss://kr-ss" + this.#ssID + ".chat.naver.com/chat");
77
+ this.#ws = new WebSocket("wss://kr-ss" + this.#ssID + ".chat.naver.com/chat", {
78
+ handshakeTimeout: 60000
79
+ });
78
80
  this.#status.wsID++;
79
81
  //Connect Web Socket
80
82
 
@@ -94,6 +96,14 @@ class chzzkChat {
94
96
  });
95
97
  }
96
98
 
99
+ getwsID() {
100
+ return this.#status.wsID;
101
+ }
102
+
103
+ getwsStatus() {
104
+ return this.#status.ws;
105
+ }
106
+
97
107
  #openHandler(wsID) {
98
108
  return new Promise(async (resolve, reject) => {
99
109
  this.#ws.on("open", () => {
@@ -234,7 +244,13 @@ class chzzkChat {
234
244
  "tid": 3
235
245
  };
236
246
 
237
- this.#ws.send(JSON.stringify(sendOpt));
247
+ try {
248
+ this.#ws.send(JSON.stringify(sendOpt));
249
+ }
250
+
251
+ catch (error) {
252
+ return resolve(false);
253
+ }
238
254
 
239
255
  return resolve(true);
240
256
  //WS Send
@@ -559,7 +575,7 @@ class chzzkChat {
559
575
  }
560
576
  //Get ChatID
561
577
 
562
- let interval = 30000;
578
+ let interval = Math.floor(Math.random() * 20000) + 30000;
563
579
 
564
580
  setTimeout(() => {
565
581
  return this.#polling();
@@ -570,6 +586,8 @@ class chzzkChat {
570
586
  if (!this.#status.ws) return this.#status.ping = false;
571
587
  if (!this.#status.ping || pingID != this.#status.pingID) return;
572
588
 
589
+ let interval = Math.floor(Math.random() * 20000) + 30000;
590
+
573
591
  let pingOpt = {
574
592
  "ver": "3",
575
593
  "cmd": 0
@@ -580,12 +598,12 @@ class chzzkChat {
580
598
  catch (error) {
581
599
  return setTimeout(async () => {
582
600
  return this.#ping(pingID);
583
- }, 30000);
601
+ }, Math.floor(Math.random() * 20000) + 30000);
584
602
  }
585
603
 
586
604
  setTimeout(() => {
587
605
  return this.#ping(pingID);
588
- }, 30000);
606
+ }, interval);
589
607
  }
590
608
  }
591
609
 
package/lib/live.js CHANGED
@@ -1,4 +1,4 @@
1
- const { reqChzzk } = require("./tool.js");
1
+ const { reqChzzk, reqGame } = require("./tool.js");
2
2
 
3
3
  /**
4
4
  * @typedef {Object} chzzkLiveDetail
@@ -106,7 +106,16 @@ async function getStatus (channelID) {
106
106
  });
107
107
  }
108
108
 
109
+ async function getAccess (chatID) {
110
+ return new Promise(async (resolve, reject) => {
111
+ let accRes = await reqGame("nng_main/v1/chats/access-token?channelId=" + chatID + "&chatType=STREAMING");
112
+ if (accRes.code != 200) return resolve(null);
113
+ return resolve(accRes.content.accessToken);
114
+ });
115
+ }
116
+
109
117
  module.exports = {
110
118
  getDetail: getDetail,
111
- getStatus: getStatus
119
+ getStatus: getStatus,
120
+ getAccess: getAccess
112
121
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "buzzk",
3
3
  "displayName": "BUZZK",
4
- "version": "1.9.12",
4
+ "version": "1.10.0",
5
5
  "description": "뿌지직 (BUZZK) - 치지직(CHZZK) 챗봇을 더욱 쉽게 개발할 수 있도록 돕는 비공식 라이브러리.",
6
6
  "main": "lib/index.js",
7
7
  "type": "commonjs",