buzzk 1.9.7 → 1.9.8
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 +49 -42
- 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,54 +122,60 @@ class chzzkChat {
|
|
|
121
122
|
});
|
|
122
123
|
|
|
123
124
|
//WS Message
|
|
124
|
-
this.#
|
|
125
|
-
|
|
126
|
-
data = await JSON.parse(data);
|
|
127
|
-
}
|
|
125
|
+
this.#connectHandler(this.#status.wsID);
|
|
126
|
+
//WS Message
|
|
128
127
|
|
|
129
|
-
|
|
130
|
-
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
#connectHandler(wsID) {
|
|
132
|
+
this.#ws.on("message", async (data) => {
|
|
133
|
+
if (wsID != this.#status.wsID) return;
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
data = await JSON.parse(data);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
catch (error) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
//Update Var
|
|
144
|
+
if (data.cid) this.#chatID = data.cid;
|
|
145
|
+
if (data.svcid) this.#svcid = data.svcid;
|
|
146
|
+
if (data.bdy && data.bdy.sid) this.#sid = data.bdy.sid;
|
|
147
|
+
//Update Var
|
|
148
|
+
|
|
149
|
+
//Ping Pong
|
|
150
|
+
if (data.cmd == 0) {
|
|
151
|
+
let pongOpt = {
|
|
152
|
+
"ver": "2",
|
|
153
|
+
"cmd": 10000
|
|
154
|
+
};
|
|
155
|
+
this.#ws.send(JSON.stringify(pongOpt));
|
|
156
|
+
}
|
|
157
|
+
//Ping Pong
|
|
158
|
+
|
|
159
|
+
//Connected
|
|
160
|
+
else if (data.cmd == 10100) {
|
|
161
|
+
if (!this.#status.ping) {
|
|
162
|
+
this.#status.ping = true;
|
|
163
|
+
this.#status.pingID++;
|
|
164
|
+
this.#ping(this.#status.pingID);
|
|
131
165
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (data.svcid) this.#svcid = data.svcid;
|
|
136
|
-
if (data.bdy && data.bdy.sid) this.#sid = data.bdy.sid;
|
|
137
|
-
//Update Var
|
|
138
|
-
|
|
139
|
-
//Ping Pong
|
|
140
|
-
if (data.cmd == 0) {
|
|
141
|
-
let pongOpt = {
|
|
142
|
-
"ver": "2",
|
|
143
|
-
"cmd": 10000
|
|
144
|
-
};
|
|
145
|
-
this.#ws.send(JSON.stringify(pongOpt));
|
|
166
|
+
if (!this.#status.polling) {
|
|
167
|
+
this.#status.polling = true;
|
|
168
|
+
this.#polling();
|
|
146
169
|
}
|
|
147
|
-
//Ping Pong
|
|
148
|
-
|
|
149
|
-
//Connected
|
|
150
|
-
else if (data.cmd == 10100) {
|
|
151
|
-
if (!this.#status.ping) {
|
|
152
|
-
this.#status.ping = true;
|
|
153
|
-
this.#status.pingID++;
|
|
154
|
-
this.#ping(this.#status.pingID);
|
|
155
|
-
}
|
|
156
|
-
if (!this.#status.polling) {
|
|
157
|
-
this.#status.polling = true;
|
|
158
|
-
this.#polling();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
for (let o in this.#callbacks) {
|
|
162
|
-
if (this.#callbacks[o].type === "message") this.#onMessageHandler(this.#status.wsID, this.#callbacks[o].callback);
|
|
163
|
-
else if (this.#callbacks[o].type === "donation") this.#onDonationHandler(this.#status.wsID, this.#callbacks[o].callback);
|
|
164
|
-
}
|
|
165
170
|
|
|
166
|
-
|
|
171
|
+
for (let o in this.#callbacks) {
|
|
172
|
+
if (this.#callbacks[o].type === "message") this.#onMessageHandler(this.#status.wsID, this.#callbacks[o].callback);
|
|
173
|
+
else if (this.#callbacks[o].type === "donation") this.#onDonationHandler(this.#status.wsID, this.#callbacks[o].callback);
|
|
167
174
|
}
|
|
168
|
-
//Connected
|
|
169
|
-
});
|
|
170
|
-
//WS Message
|
|
171
175
|
|
|
176
|
+
resolve(true);
|
|
177
|
+
}
|
|
178
|
+
//Connected
|
|
172
179
|
});
|
|
173
180
|
}
|
|
174
181
|
|