buzzk 1.9.10 → 1.9.11
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 +26 -10
- package/package.json +1 -1
package/lib/chat.js
CHANGED
|
@@ -79,7 +79,25 @@ class chzzkChat {
|
|
|
79
79
|
//Connect Web Socket
|
|
80
80
|
|
|
81
81
|
//WS Open
|
|
82
|
+
await this.#openHandler(this.#status.wsID);
|
|
83
|
+
//WS Open
|
|
84
|
+
|
|
85
|
+
this.#ws.on("error", console.error);
|
|
86
|
+
|
|
87
|
+
this.#closeHandler(this.#status.wsID);
|
|
88
|
+
|
|
89
|
+
//WS Message
|
|
90
|
+
await this.#connectHandler(this.#status.wsID);
|
|
91
|
+
return resolve(true);
|
|
92
|
+
//WS Message
|
|
93
|
+
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#openHandler(wsID) {
|
|
98
|
+
return new Promise(async (resolve, reject) => {
|
|
82
99
|
this.#ws.on("open", () => {
|
|
100
|
+
if (wsID != this.#status.wsID) return;
|
|
83
101
|
console.log("[WS] Connected!");
|
|
84
102
|
|
|
85
103
|
//WS First Connect
|
|
@@ -100,16 +118,20 @@ class chzzkChat {
|
|
|
100
118
|
},
|
|
101
119
|
"tid": 1
|
|
102
120
|
};
|
|
103
|
-
|
|
121
|
+
|
|
104
122
|
this.#ws.send(JSON.stringify(connectOpt));
|
|
123
|
+
return resolve(true);
|
|
105
124
|
//WS First Connect
|
|
106
125
|
});
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
this.#ws.on("error", console.error);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
110
128
|
|
|
129
|
+
#closeHandler(wsID) {
|
|
130
|
+
return new Promise(async (resolve, reject) => {
|
|
111
131
|
this.#ws.on("close", () => {
|
|
112
132
|
console.log("[WS] Disconnect!");
|
|
133
|
+
if (wsID != this.#status.wsID) return;
|
|
134
|
+
if (this.#status.reconnect) return;
|
|
113
135
|
this.#ws = null;
|
|
114
136
|
this.#status.ws = false;
|
|
115
137
|
this.#status.wsID++;
|
|
@@ -120,12 +142,6 @@ class chzzkChat {
|
|
|
120
142
|
this.connect();
|
|
121
143
|
}, 2000);
|
|
122
144
|
});
|
|
123
|
-
|
|
124
|
-
//WS Message
|
|
125
|
-
await this.#connectHandler(this.#status.wsID);
|
|
126
|
-
return resolve(true);
|
|
127
|
-
//WS Message
|
|
128
|
-
|
|
129
145
|
});
|
|
130
146
|
}
|
|
131
147
|
|