buzzk 1.9.7 → 1.9.9

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 (2) hide show
  1. package/lib/chat.js +16 -6
  2. package/package.json +1 -1
package/lib/chat.js CHANGED
@@ -110,6 +110,7 @@ class chzzkChat {
110
110
 
111
111
  this.#ws.on("close", () => {
112
112
  console.log("[WS] Disconnect!");
113
+ this.#ws = null;
113
114
  this.#status.ws = false;
114
115
  this.#status.wsID++;
115
116
  this.#status.ping = false;
@@ -121,7 +122,18 @@ class chzzkChat {
121
122
  });
122
123
 
123
124
  //WS Message
124
- this.#ws.on("message", async (data) => {
125
+ await this.#connectHandler(this.#status.wsID);
126
+ return resolve(true);
127
+ //WS Message
128
+
129
+ });
130
+ }
131
+
132
+ #connectHandler(wsID) {
133
+ return new Promise(async (resolve, reject) => {
134
+ this.#ws.on("message", async (data) => {
135
+ if (wsID != this.#status.wsID) return;
136
+
125
137
  try {
126
138
  data = await JSON.parse(data);
127
139
  }
@@ -129,13 +141,13 @@ class chzzkChat {
129
141
  catch (error) {
130
142
  return;
131
143
  }
132
-
144
+
133
145
  //Update Var
134
146
  if (data.cid) this.#chatID = data.cid;
135
147
  if (data.svcid) this.#svcid = data.svcid;
136
148
  if (data.bdy && data.bdy.sid) this.#sid = data.bdy.sid;
137
149
  //Update Var
138
-
150
+
139
151
  //Ping Pong
140
152
  if (data.cmd == 0) {
141
153
  let pongOpt = {
@@ -145,7 +157,7 @@ class chzzkChat {
145
157
  this.#ws.send(JSON.stringify(pongOpt));
146
158
  }
147
159
  //Ping Pong
148
-
160
+
149
161
  //Connected
150
162
  else if (data.cmd == 10100) {
151
163
  if (!this.#status.ping) {
@@ -167,8 +179,6 @@ class chzzkChat {
167
179
  }
168
180
  //Connected
169
181
  });
170
- //WS Message
171
-
172
182
  });
173
183
  }
174
184
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "buzzk",
3
3
  "displayName": "BUZZK",
4
- "version": "1.9.7",
4
+ "version": "1.9.9",
5
5
  "description": "뿌지직 (BUZZK) - 치지직(CHZZK) 챗봇을 더욱 쉽게 개발할 수 있도록 돕는 비공식 라이브러리.",
6
6
  "main": "lib/index.js",
7
7
  "type": "commonjs",