douyin-danma-listener 0.4.0 → 0.4.1
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/index.js +23 -15
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,22 +1,8 @@
|
|
|
1
|
-
import { parse, format } from "node:url";
|
|
2
1
|
import WebSocket from "ws";
|
|
3
2
|
import { TypedEmitter } from "tiny-typed-emitter";
|
|
4
3
|
import { decompressGzip, getXMsStub, getSignature, getUserUniqueId } from "./utils.js";
|
|
5
4
|
import protobuf from "./proto.js";
|
|
6
5
|
import { getCookie } from "./api.js";
|
|
7
|
-
function buildRequestUrl(url) {
|
|
8
|
-
const parsedUrl = parse(url, true);
|
|
9
|
-
const existingParams = parsedUrl.query;
|
|
10
|
-
existingParams["aid"] = "6383";
|
|
11
|
-
existingParams["device_platform"] = "web";
|
|
12
|
-
existingParams["browser_language"] = "zh-CN";
|
|
13
|
-
existingParams["browser_platform"] = "Win32";
|
|
14
|
-
existingParams["browser_name"] = "Mozilla";
|
|
15
|
-
existingParams["browser_version"] = "92.0.4515.159";
|
|
16
|
-
parsedUrl.search = null;
|
|
17
|
-
parsedUrl.query = existingParams;
|
|
18
|
-
return format(parsedUrl);
|
|
19
|
-
}
|
|
20
6
|
class DouYinDanmaClient extends TypedEmitter {
|
|
21
7
|
ws;
|
|
22
8
|
roomId;
|
|
@@ -61,6 +47,9 @@ class DouYinDanmaClient extends TypedEmitter {
|
|
|
61
47
|
this.ws = new WebSocket(url, {
|
|
62
48
|
headers: {
|
|
63
49
|
Cookie: cookies,
|
|
50
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
|
|
51
|
+
Origin: "https://live.douyin.com",
|
|
52
|
+
Referer: "https://live.douyin.com/",
|
|
64
53
|
},
|
|
65
54
|
});
|
|
66
55
|
this.ws.on("open", () => {
|
|
@@ -373,18 +362,37 @@ class DouYinDanmaClient extends TypedEmitter {
|
|
|
373
362
|
return;
|
|
374
363
|
}
|
|
375
364
|
const webcast5Params = {
|
|
365
|
+
app_name: "douyin_web",
|
|
376
366
|
room_id: roomId,
|
|
377
367
|
compress: "gzip",
|
|
378
368
|
version_code: String(versionCode),
|
|
379
369
|
webcast_sdk_version: webcastSdkVersion,
|
|
370
|
+
update_version_code: webcastSdkVersion,
|
|
380
371
|
live_id: "1",
|
|
381
372
|
did_rule: "3",
|
|
382
373
|
user_unique_id: userUniqueId,
|
|
383
374
|
identity: "audience",
|
|
384
375
|
signature: signature.toString(),
|
|
376
|
+
device_platform: "web",
|
|
377
|
+
cookie_enabled: "true",
|
|
378
|
+
screen_width: "1920",
|
|
379
|
+
screen_height: "1080",
|
|
380
|
+
browser_language: "zh-CN",
|
|
381
|
+
browser_platform: "Win32",
|
|
382
|
+
browser_name: "Mozilla",
|
|
383
|
+
browser_version: "5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
|
|
384
|
+
browser_online: "true",
|
|
385
|
+
tz_name: "Etc/GMT-8",
|
|
386
|
+
host: "https://live.douyin.com",
|
|
387
|
+
aid: "6383",
|
|
388
|
+
endpoint: "live_pc",
|
|
389
|
+
support_wrds: "1",
|
|
390
|
+
im_path: "/webcast/im/fetch/",
|
|
391
|
+
need_persist_msg_count: "15",
|
|
392
|
+
heartbeatDuration: "0",
|
|
385
393
|
};
|
|
386
394
|
const wssUrl = `wss://${this.host}/webcast/im/push/v2/?${new URLSearchParams(webcast5Params).toString()}`;
|
|
387
|
-
return
|
|
395
|
+
return wssUrl;
|
|
388
396
|
}
|
|
389
397
|
}
|
|
390
398
|
export default DouYinDanmaClient;
|