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