buzzk 2.2.0 → 2.2.2
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/LICENSE +20 -20
- package/lib/chat.js +9 -2
- package/lib/oauth.js +0 -4
- package/lib/tool.js +2 -2
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Emin-G
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Emin-G
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/lib/chat.js
CHANGED
|
@@ -47,7 +47,8 @@ class chzzkChat {
|
|
|
47
47
|
|
|
48
48
|
#status = {
|
|
49
49
|
ws: false,
|
|
50
|
-
established: false
|
|
50
|
+
established: false,
|
|
51
|
+
reconnect: true
|
|
51
52
|
}
|
|
52
53
|
//Private
|
|
53
54
|
|
|
@@ -60,6 +61,8 @@ class chzzkChat {
|
|
|
60
61
|
if (this.#status.ws) return resolve(false);
|
|
61
62
|
this.#status.ws = true;
|
|
62
63
|
|
|
64
|
+
this.#status.reconnect = true;
|
|
65
|
+
|
|
63
66
|
let channel = await oauth.resolve(this.accessToken);
|
|
64
67
|
if (!channel) {
|
|
65
68
|
this.#status.ws = false;
|
|
@@ -135,11 +138,14 @@ class chzzkChat {
|
|
|
135
138
|
});
|
|
136
139
|
|
|
137
140
|
this.#ws.on("disconnect", (data) => {
|
|
141
|
+
if (this.#callbacks.disconnect) this.#callbacks.disconnect(data);
|
|
142
|
+
|
|
143
|
+
if (!this.#status.reconnect) return;
|
|
144
|
+
|
|
138
145
|
console.log("[WS] Disconnected! (" + data + ")");
|
|
139
146
|
|
|
140
147
|
this.#status.ws = false;
|
|
141
148
|
this.#status.established = false;
|
|
142
|
-
if (this.#callbacks.disconnect) this.#callbacks.disconnect(data);
|
|
143
149
|
|
|
144
150
|
if (this.#ws) this.#ws.off();
|
|
145
151
|
if (!this.#status.established) resolve(null);
|
|
@@ -280,6 +286,7 @@ class chzzkChat {
|
|
|
280
286
|
async disconnect() {
|
|
281
287
|
return new Promise(async (resolve, reject) => {
|
|
282
288
|
if (!this.#status.ws) return resolve(null);
|
|
289
|
+
this.#status.reconnect = false;
|
|
283
290
|
|
|
284
291
|
await this.#ws.off();
|
|
285
292
|
await this.#ws.close();
|
package/lib/oauth.js
CHANGED
|
@@ -40,8 +40,6 @@ async function get (code) {
|
|
|
40
40
|
state: state
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
options = JSON.stringify(options);
|
|
44
|
-
|
|
45
43
|
let oauthGet = await CLIENT.post("auth/v1/token", options);
|
|
46
44
|
if (oauthGet.code != 200) return resolve(null);
|
|
47
45
|
|
|
@@ -66,8 +64,6 @@ async function refresh (refreshToken) {
|
|
|
66
64
|
refreshToken: refreshToken,
|
|
67
65
|
}
|
|
68
66
|
|
|
69
|
-
options = JSON.stringify(options);
|
|
70
|
-
|
|
71
67
|
let oauthGet = await CLIENT.post("auth/v1/token", options);
|
|
72
68
|
if (oauthGet.code != 200) return resolve(null);
|
|
73
69
|
|
package/lib/tool.js
CHANGED
|
@@ -40,7 +40,7 @@ function clientPost (path, body) {
|
|
|
40
40
|
"Content-Type": "application/json",
|
|
41
41
|
"User-Agent": "BuzzkLib/" + vm.getVersion() + " (Node)"
|
|
42
42
|
},
|
|
43
|
-
|
|
43
|
+
data: body
|
|
44
44
|
})
|
|
45
45
|
|
|
46
46
|
.then((response) => {
|
|
@@ -89,7 +89,7 @@ function userPost (token, path, body) {
|
|
|
89
89
|
"Content-Type": "application/json",
|
|
90
90
|
"User-Agent": "BuzzkLib/" + vm.getVersion() + " (Node)"
|
|
91
91
|
},
|
|
92
|
-
|
|
92
|
+
data: body
|
|
93
93
|
})
|
|
94
94
|
|
|
95
95
|
.then((response) => {
|