buzzk 1.0.0 → 1.1.0
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/README.md +20 -5
- package/lib/channel.js +26 -3
- package/lib/chat.js +34 -6
- package/lib/index.js +2 -0
- package/lib/live.js +3 -0
- package/lib/tool.js +16 -0
- package/lib/vm.js +18 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,15 +15,23 @@
|
|
|
15
15
|
|
|
16
16
|
---
|
|
17
17
|
|
|
18
|
+
## 업데이트 내역
|
|
19
|
+
|
|
20
|
+
- 팔로우 / 언팔로우 기능 추가
|
|
21
|
+
- live.getLiveDetail의 Return 값에 chatLimit 추가 (팔로우 대상 채팅 등...)
|
|
22
|
+
- 폴링 함수 추가 (chatID 변경 감지)
|
|
23
|
+
- API 호출 실패 시 오류 핸들링 (Return true / null)
|
|
24
|
+
- chat.disconnect 함수 보완
|
|
25
|
+
- 버전 체크 함수 추가
|
|
26
|
+
|
|
18
27
|
## 설치
|
|
19
28
|
|
|
20
|
-
1.
|
|
21
|
-
2.
|
|
22
|
-
3. `const buzzk = require("./buzzk");`
|
|
29
|
+
1. `npm install buzzk`
|
|
30
|
+
2. `const buzzk = require("buzzk");`
|
|
23
31
|
|
|
24
32
|
## 빠른. 시작.
|
|
25
33
|
|
|
26
|
-
const buzzk = require("
|
|
34
|
+
const buzzk = require("buzzk");
|
|
27
35
|
buzzk.login("NID_AUT 쿠키 값", "NID_SES 쿠키 값");
|
|
28
36
|
|
|
29
37
|
const buzzkChat = buzzk.chat;
|
|
@@ -85,6 +93,12 @@ dotenv와 함께 사용하는 것을 매우 권장합니다.
|
|
|
85
93
|
|
|
86
94
|
</details>
|
|
87
95
|
|
|
96
|
+
await buzzk.channel.followChannel("channelID 값");
|
|
97
|
+
|
|
98
|
+
>
|
|
99
|
+
|
|
100
|
+
await buzzk.channel.unFollowChannel("channelID 값");
|
|
101
|
+
|
|
88
102
|
---
|
|
89
103
|
|
|
90
104
|
> live
|
|
@@ -99,6 +113,7 @@ dotenv와 함께 사용하는 것을 매우 권장합니다.
|
|
|
99
113
|
- channelID
|
|
100
114
|
- channel
|
|
101
115
|
- chatID
|
|
116
|
+
- chatLimit //팔로워 전용 채팅 등...
|
|
102
117
|
- userCount
|
|
103
118
|
- now
|
|
104
119
|
- total
|
|
@@ -189,4 +204,4 @@ dotenv와 함께 사용하는 것을 매우 권장합니다.
|
|
|
189
204
|
|
|
190
205
|
>
|
|
191
206
|
|
|
192
|
-
chat.disconnect(); //채팅창 연결 끊기
|
|
207
|
+
await chat.disconnect(); //채팅창 연결 끊기
|
package/lib/channel.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { reqChzzk } = require("./tool.js");
|
|
1
|
+
const { reqChzzk, exChzzk } = require("./tool.js");
|
|
2
2
|
|
|
3
3
|
class chzzkChannel {
|
|
4
4
|
constructor(channelID, name, description, follower, imageURL, isLive) {
|
|
@@ -15,9 +15,10 @@ async function getChannel (keyword) {
|
|
|
15
15
|
return new Promise(async (resolve, reject) => {
|
|
16
16
|
|
|
17
17
|
let chSearch = await reqChzzk("service/v1/search/channels?keyword=" + keyword + "&offset=0&size=13&withFirstChannelContent=false");
|
|
18
|
+
if (chSearch.code != 200) return resolve(null);
|
|
18
19
|
chSearch = chSearch.content.data;
|
|
19
20
|
|
|
20
|
-
if (!chSearch) return resolve();
|
|
21
|
+
if (!chSearch) return resolve(null);
|
|
21
22
|
|
|
22
23
|
let chRes = new Map();
|
|
23
24
|
|
|
@@ -31,6 +32,28 @@ async function getChannel (keyword) {
|
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
async function followChannel (channelID) {
|
|
36
|
+
return new Promise(async (resolve, reject) => {
|
|
37
|
+
|
|
38
|
+
let flRes = await exChzzk("POST", "service/v1/channels/" + channelID + "/follow");
|
|
39
|
+
if (flRes.code == 200) return resolve(true);
|
|
40
|
+
else return resolve(null);
|
|
41
|
+
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function unFollowChannel (channelID) {
|
|
46
|
+
return new Promise(async (resolve, reject) => {
|
|
47
|
+
|
|
48
|
+
let flRes = await exChzzk("DELETE", "service/v1/channels/" + channelID + "/follow");
|
|
49
|
+
if (flRes.code == 200) return resolve(true);
|
|
50
|
+
else return resolve(null);
|
|
51
|
+
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
34
55
|
module.exports = {
|
|
35
|
-
getChannel: getChannel
|
|
56
|
+
getChannel: getChannel,
|
|
57
|
+
followChannel: followChannel,
|
|
58
|
+
unFollowChannel: unFollowChannel
|
|
36
59
|
}
|
package/lib/chat.js
CHANGED
|
@@ -15,19 +15,22 @@ class chzzkChat {
|
|
|
15
15
|
#svcid; //game
|
|
16
16
|
#sid;
|
|
17
17
|
#chatID;
|
|
18
|
+
|
|
19
|
+
#pollingStatus = false;
|
|
18
20
|
//Private
|
|
19
21
|
|
|
20
22
|
connect() {
|
|
21
23
|
return new Promise(async (resolve, reject) => {
|
|
24
|
+
if (this.#ws) return resolve(null);
|
|
25
|
+
|
|
22
26
|
//Get ChatID
|
|
23
27
|
let cidRes = await getLiveStatus(this.channelID);
|
|
24
|
-
|
|
25
28
|
this.#chatID = cidRes.chatID;
|
|
26
29
|
//Get ChatID
|
|
27
30
|
|
|
28
31
|
//Get accTkn
|
|
29
32
|
let accRes = await reqGame("nng_main/v1/chats/access-token?channelId=" + this.#chatID + "&chatType=STREAMING");
|
|
30
|
-
|
|
33
|
+
if (accRes.code != 200) return resolve(null);
|
|
31
34
|
this.#accTkn = accRes.content.accessToken;
|
|
32
35
|
//Get accTkn
|
|
33
36
|
|
|
@@ -39,6 +42,10 @@ class chzzkChat {
|
|
|
39
42
|
this.#ws = new WebSocket("wss://kr-ss" + this.#ssID + ".chat.naver.com/chat");
|
|
40
43
|
//Connect Web Socket
|
|
41
44
|
|
|
45
|
+
//SetPolling
|
|
46
|
+
if (!this.#pollingStatus) this.polling();
|
|
47
|
+
//SetPolling
|
|
48
|
+
|
|
42
49
|
//WS Open
|
|
43
50
|
this.#ws.on("open", () => {
|
|
44
51
|
console.log("[WS] Connected!");
|
|
@@ -90,7 +97,7 @@ class chzzkChat {
|
|
|
90
97
|
//Ping Pong
|
|
91
98
|
|
|
92
99
|
//Connected
|
|
93
|
-
else if (data.cmd == 10100) resolve();
|
|
100
|
+
else if (data.cmd == 10100) resolve(true);
|
|
94
101
|
//Connected
|
|
95
102
|
});
|
|
96
103
|
//WS Message
|
|
@@ -100,6 +107,7 @@ class chzzkChat {
|
|
|
100
107
|
|
|
101
108
|
send(message) {
|
|
102
109
|
return new Promise(async (resolve, reject) => {
|
|
110
|
+
if (!this.#ws) return resolve(null);
|
|
103
111
|
|
|
104
112
|
let extras = {
|
|
105
113
|
"chatType":"STREAMING",
|
|
@@ -129,7 +137,7 @@ class chzzkChat {
|
|
|
129
137
|
|
|
130
138
|
this.#ws.send(JSON.stringify(sendOpt));
|
|
131
139
|
|
|
132
|
-
return resolve();
|
|
140
|
+
return resolve(true);
|
|
133
141
|
//WS Send
|
|
134
142
|
|
|
135
143
|
});
|
|
@@ -213,8 +221,28 @@ class chzzkChat {
|
|
|
213
221
|
});
|
|
214
222
|
}
|
|
215
223
|
|
|
216
|
-
disconnect() {
|
|
217
|
-
|
|
224
|
+
async disconnect() {
|
|
225
|
+
return new Promise(async (resolve, reject) => {
|
|
226
|
+
if (!this.#ws) return resolve(null);
|
|
227
|
+
|
|
228
|
+
await this.#ws.close();
|
|
229
|
+
this.#ws = null;
|
|
230
|
+
return resolve(true);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async polling () {
|
|
235
|
+
if (!this.#ws) return this.#pollingStatus = false;
|
|
236
|
+
this.#pollingStatus = true;
|
|
237
|
+
|
|
238
|
+
//Get ChatID
|
|
239
|
+
let cidRes = await getLiveStatus(this.channelID);
|
|
240
|
+
this.#chatID = cidRes.chatID;
|
|
241
|
+
//Get ChatID
|
|
242
|
+
|
|
243
|
+
setTimeout(() => {
|
|
244
|
+
return this.polling();
|
|
245
|
+
}, cidRes.polling.callPeriodMilliSecond);
|
|
218
246
|
}
|
|
219
247
|
}
|
|
220
248
|
|
package/lib/index.js
CHANGED
package/lib/live.js
CHANGED
|
@@ -4,12 +4,14 @@ async function getLiveDetail (channelID) {
|
|
|
4
4
|
return new Promise(async (resolve, reject) => {
|
|
5
5
|
|
|
6
6
|
let res = await reqChzzk("service/v2/channels/" + channelID + "/live-detail");
|
|
7
|
+
if (res.code != 200) return resolve(null);
|
|
7
8
|
res = res.content;
|
|
8
9
|
|
|
9
10
|
let lvDetail = {
|
|
10
11
|
channelID: res.channel.channelId,
|
|
11
12
|
channel: res.channel,
|
|
12
13
|
chatID: res.chatChannelId,
|
|
14
|
+
chatLimit: res.chatAvailableGroup,
|
|
13
15
|
userCount: { now: res.concurrentUserCount, total: res.accumulateCount },
|
|
14
16
|
title: res.liveTitle,
|
|
15
17
|
startOn: res.openDate,
|
|
@@ -27,6 +29,7 @@ async function getLiveStatus (channelID) {
|
|
|
27
29
|
return new Promise(async (resolve, reject) => {
|
|
28
30
|
|
|
29
31
|
let res = await reqChzzk("polling/v2/channels/" + channelID + "/live-status");
|
|
32
|
+
if (res.code != 200) return resolve(null);
|
|
30
33
|
res = res.content;
|
|
31
34
|
|
|
32
35
|
let lvStatus = {
|
package/lib/tool.js
CHANGED
|
@@ -15,6 +15,21 @@ function reqChzzk (path) {
|
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
function exChzzk (method, path) {
|
|
19
|
+
return new Promise(async (resolve, reject) => {
|
|
20
|
+
|
|
21
|
+
fetch(chzzkBaseURL + path, {
|
|
22
|
+
method: method,
|
|
23
|
+
headers: {
|
|
24
|
+
"Cookie": "NID_AUT=" + NID.AUT + ";NID_SES=" + NID.SES
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
.then((response) => resolve(response.json()));
|
|
29
|
+
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
18
33
|
function reqGame (path) {
|
|
19
34
|
return new Promise(async (resolve, reject) => {
|
|
20
35
|
|
|
@@ -32,5 +47,6 @@ function reqGame (path) {
|
|
|
32
47
|
|
|
33
48
|
module.exports = {
|
|
34
49
|
reqChzzk: reqChzzk,
|
|
50
|
+
exChzzk: exChzzk,
|
|
35
51
|
reqGame: reqGame
|
|
36
52
|
}
|
package/lib/vm.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
async function check () {
|
|
2
|
+
|
|
3
|
+
let localPkg = require("../package.json");
|
|
4
|
+
let remotePkg = await fetch("https://raw.githubusercontent.com/Emin-G/buzzk/master/package.json");
|
|
5
|
+
|
|
6
|
+
if (remotePkg.status != 200) return console.log("[BUZZK] 최신 버전에 대한 정보를 불러오지 못했습니다.");
|
|
7
|
+
|
|
8
|
+
remotePkg = await remotePkg.json();
|
|
9
|
+
|
|
10
|
+
localPkg = String(localPkg.version).split(".");
|
|
11
|
+
remotePkg = String(remotePkg.version).split(".");
|
|
12
|
+
|
|
13
|
+
for (let v in remotePkg) {
|
|
14
|
+
if (parseInt(remotePkg[v]) > parseInt(localPkg[v])) return console.log("[BUZZK] 새로운 버전을 찾았습니다! ( 현재 버전 : " + localPkg.join(".") + " / 새로운 버전 : " + remotePkg.join(".") + " )");
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
check();
|