+75
-14
@@ -51,3 +51,5 @@ const { getStatus } = require("./live.js"); | ||
| established: false, | ||
| reconnect: true | ||
| watchDogID: null, | ||
| reconnect: true, | ||
| reconnectID: null | ||
| } | ||
@@ -84,3 +86,2 @@ //Private | ||
| reconnection: false, | ||
| "force new connection": true, | ||
| "connect timeout": 6000, | ||
@@ -92,2 +93,12 @@ transports: ["websocket"] | ||
| if (!this.#status.watchDogID) { | ||
| this.#status.watchDogID = setTimeout(() => { | ||
| this.#status.watchDogID = null; | ||
| if (this.#status.established) return; | ||
| return this.#rePromise(); | ||
| }, 20000); | ||
| } | ||
| this.#ws.on("connect", async (data) => { | ||
@@ -112,2 +123,3 @@ console.log("[WS] Connected!"); | ||
| //Events | ||
| this.#ws.on("CHAT", (data) => { | ||
@@ -137,7 +149,11 @@ if (!this.#callbacks.message) return; | ||
| }); | ||
| //Events | ||
| //Disconnect Handle | ||
| this.#ws.on("error", (error) => { | ||
| console.log(error); | ||
| if (!this.#status.reconnect) return; | ||
| if (!this.#status.established) return resolve(null); | ||
| console.log("[WS] Disconnected! (" + error + ")"); | ||
| return this.#rePromise(); | ||
| }); | ||
@@ -147,3 +163,2 @@ | ||
| if (this.#callbacks.disconnect) this.#callbacks.disconnect(data); | ||
| if (!this.#status.reconnect) return; | ||
@@ -153,17 +168,63 @@ | ||
| this.#status.ws = false; | ||
| this.#status.established = false; | ||
| return this.#rePromise(); | ||
| }); | ||
| if (this.#ws) this.#ws.off(); | ||
| if (!this.#status.established) resolve(null); | ||
| this.#ws.on("connect_error", (data) => { | ||
| if (!this.#status.reconnect) return; | ||
| this.#ws = null; | ||
| this.#channelID = null; | ||
| this.#session = null; | ||
| return this.connect(); | ||
| console.log("[WS] Disconnected! (" + data + ")"); | ||
| return this.#rePromise(); | ||
| }); | ||
| this.#ws.on("connect_timeout", () => { | ||
| if (!this.#status.reconnect) return; | ||
| console.log("[WS] Disconnected! (Connect Timeout)"); | ||
| return this.#rePromise(); | ||
| }); | ||
| this.#ws.on("handshake_timeout", () => { | ||
| if (!this.#status.reconnect) return; | ||
| console.log("[WS] Disconnected! (Handshake Timeout)"); | ||
| return this.#rePromise(); | ||
| }); | ||
| //Disconnect Handle | ||
| }); | ||
| } | ||
| async #rePromise() { | ||
| if (!this.#status.reconnect) return; | ||
| if (this.#status.reconnectID) return; | ||
| let reIntv = Math.floor(Math.random() * 15000) + 8000; | ||
| this.#status.reconnectID = setTimeout(() => { | ||
| try { | ||
| if (this.#ws) this.#ws.off(); | ||
| if (this.#ws) this.#ws.disconnect(); | ||
| } | ||
| catch(error) { | ||
| console.log("[WS] Cleanup Disconnect Failed."); | ||
| } | ||
| this.#status.ws = false; | ||
| this.#status.established = false; | ||
| this.#ws = null; | ||
| this.#channelID = null; | ||
| this.#session = null; | ||
| setTimeout(() => { | ||
| this.#status.reconnectID = null; | ||
| return this.connect(); | ||
| }, 2000); | ||
| }, reIntv); | ||
| } | ||
| /** | ||
@@ -299,3 +360,3 @@ * @param {string} message | ||
| await this.#ws.off(); | ||
| await this.#ws.close(); | ||
| await this.#ws.disconnect(); | ||
@@ -302,0 +363,0 @@ this.#status.ws = false; |
+7
-0
@@ -25,2 +25,3 @@ const { chzzkAPIURL, chzzkBaseURL, gameBaseURL, naverBaseURL, NID, AUTH } = require("./val.js"); | ||
| .catch((error) => { | ||
| console.log(error); | ||
| return resolve({"code": 500}); | ||
@@ -52,2 +53,3 @@ }); | ||
| .catch((error) => { | ||
| console.log(error); | ||
| return resolve({"code": 500}); | ||
@@ -77,2 +79,3 @@ }); | ||
| .catch((error) => { | ||
| console.log(error); | ||
| return resolve({"code": 500}); | ||
@@ -103,2 +106,3 @@ }); | ||
| .catch((error) => { | ||
| console.log(error); | ||
| return resolve({"code": 500}); | ||
@@ -127,2 +131,3 @@ }); | ||
| .catch((error) => { | ||
| console.log(error); | ||
| return resolve({"code": 500}); | ||
@@ -174,2 +179,3 @@ }); | ||
| .catch((error) => { | ||
| console.log(error); | ||
| return resolve({"code": 500}); | ||
@@ -197,2 +203,3 @@ }); | ||
| .catch((error) => { | ||
| console.log(error); | ||
| return resolve({"code": 500}); | ||
@@ -199,0 +206,0 @@ }); |
+1
-1
| { | ||
| "name": "buzzk", | ||
| "displayName": "BUZZK", | ||
| "version": "2.3.3", | ||
| "version": "2.3.4", | ||
| "description": "뿌지직 (BUZZK) - 치지직(CHZZK) 챗봇을 더욱 쉽게 개발할 수 있도록 돕는 비공식 라이브러리.", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
42694
4.88%888
6.09%