buzzk 1.9.6 → 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 +50 -42
- package/package.json +1 -1
package/lib/chat.js
CHANGED
|
@@ -110,64 +110,72 @@ 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;
|
|
116
117
|
this.#status.pingID++;
|
|
117
118
|
setTimeout(() => {
|
|
119
|
+
this.#status.reconnect = true;
|
|
118
120
|
this.connect();
|
|
119
121
|
}, 2000);
|
|
120
122
|
});
|
|
121
123
|
|
|
122
124
|
//WS Message
|
|
123
|
-
this.#
|
|
124
|
-
|
|
125
|
-
data = await JSON.parse(data);
|
|
126
|
-
}
|
|
125
|
+
this.#connectHandler(this.#status.wsID);
|
|
126
|
+
//WS Message
|
|
127
127
|
|
|
128
|
-
|
|
129
|
-
|
|
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);
|
|
130
165
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (data.svcid) this.#svcid = data.svcid;
|
|
135
|
-
if (data.bdy && data.bdy.sid) this.#sid = data.bdy.sid;
|
|
136
|
-
//Update Var
|
|
137
|
-
|
|
138
|
-
//Ping Pong
|
|
139
|
-
if (data.cmd == 0) {
|
|
140
|
-
let pongOpt = {
|
|
141
|
-
"ver": "2",
|
|
142
|
-
"cmd": 10000
|
|
143
|
-
};
|
|
144
|
-
this.#ws.send(JSON.stringify(pongOpt));
|
|
166
|
+
if (!this.#status.polling) {
|
|
167
|
+
this.#status.polling = true;
|
|
168
|
+
this.#polling();
|
|
145
169
|
}
|
|
146
|
-
//Ping Pong
|
|
147
|
-
|
|
148
|
-
//Connected
|
|
149
|
-
else if (data.cmd == 10100) {
|
|
150
|
-
if (!this.#status.ping) {
|
|
151
|
-
this.#status.ping = true;
|
|
152
|
-
this.#status.pingID++;
|
|
153
|
-
this.#ping(this.#status.pingID);
|
|
154
|
-
}
|
|
155
|
-
if (!this.#status.polling) {
|
|
156
|
-
this.#status.polling = true;
|
|
157
|
-
this.#polling();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
for (let o in this.#callbacks) {
|
|
161
|
-
if (this.#callbacks[o].type === "message") this.#onMessageHandler(this.#status.wsID, this.#callbacks[o].callback);
|
|
162
|
-
else if (this.#callbacks[o].type === "donation") this.#onDonationHandler(this.#status.wsID, this.#callbacks[o].callback);
|
|
163
|
-
}
|
|
164
170
|
|
|
165
|
-
|
|
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);
|
|
166
174
|
}
|
|
167
|
-
//Connected
|
|
168
|
-
});
|
|
169
|
-
//WS Message
|
|
170
175
|
|
|
176
|
+
resolve(true);
|
|
177
|
+
}
|
|
178
|
+
//Connected
|
|
171
179
|
});
|
|
172
180
|
}
|
|
173
181
|
|