init
This commit is contained in:
commit
75a1bcfecb
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
node_modules
|
22
package.json
Normal file
22
package.json
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"name": "blive-ws",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"description": "",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "abearxiong <xiongxiao@xiongxiao.me> (https://www.xiongxiao.me)",
|
||||||
|
"license": "MIT",
|
||||||
|
"packageManager": "pnpm@10.6.2",
|
||||||
|
"type": "module",
|
||||||
|
"dependencies": {
|
||||||
|
"@tokine/bilibili-bridge": "^0.2.24",
|
||||||
|
"ws": "npm:@kevisual/ws"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@kevisual/types": "^0.0.9",
|
||||||
|
"@types/ws": "^8.18.1"
|
||||||
|
}
|
||||||
|
}
|
1996
pnpm-lock.yaml
generated
Normal file
1996
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
39
src/live.ts
Normal file
39
src/live.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { WebSocket } from 'ws';
|
||||||
|
|
||||||
|
// 连接到代理服务器
|
||||||
|
const socket = new WebSocket('wss://blive.deno.dev', {
|
||||||
|
rejectUnauthorized: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.addEventListener('open', () => {
|
||||||
|
console.log('WebSocket connection opened');
|
||||||
|
// 进入房间命令
|
||||||
|
socket.send(
|
||||||
|
JSON.stringify({
|
||||||
|
cmd: 'enter', // 命令名,必填
|
||||||
|
rid: 6811411, // 房间号,必填
|
||||||
|
events: ['DANMU_MSG'], // 监听这个房间中的事件列表,必填
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
// 退出房间命令
|
||||||
|
// socket.send(
|
||||||
|
// JSON.stringify({
|
||||||
|
// cmd: 'leave', // 命令名,必填
|
||||||
|
// rid: 123, // 房间号,必填
|
||||||
|
// }),
|
||||||
|
// );
|
||||||
|
|
||||||
|
// // 退出所有房间
|
||||||
|
// socket.send(
|
||||||
|
// JSON.stringify({
|
||||||
|
// cmd: 'exit',
|
||||||
|
// }),
|
||||||
|
// );
|
||||||
|
});
|
||||||
|
|
||||||
|
// 接收进入房间时`events`参数所指定的消息
|
||||||
|
socket.addEventListener('message', ({ data }) => {
|
||||||
|
// 接收到的消息,格式为 { rid: 房间号, payload: {} }
|
||||||
|
console.log(data);
|
||||||
|
});
|
51
src/test/index.ts
Normal file
51
src/test/index.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import WSClient from '@tokine/bilibili-bridge/lib/service/bilibili/ws.ts';
|
||||||
|
import state from '@tokine/bilibili-bridge/lib/service/state.ts';
|
||||||
|
import { sendMessage } from '@tokine/bilibili-bridge/lib/service/bilibili/sdk.ts';
|
||||||
|
console.log('state', state);
|
||||||
|
import event from '@tokine/bilibili-bridge/lib/service/event.ts';
|
||||||
|
import { CMDS, EVENTS } from '@tokine/bilibili-bridge/lib/service/const.ts';
|
||||||
|
const cookie =
|
||||||
|
'_uuid=1B1E53FD-98C5-FF1A-CF6B-1012728F7979D58482infoc;b_lsid=3D1055DF5_1968A4717E4;b_nut=1742308859;bili_jct=bf5ea5420482ce93238bc0c09a5e6c4f;bili_ticket=eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NDYzMzM4MTAsImlhdCI6MTc0NjA3NDU1MCwicGx0IjotMX0.N-XYXAtfbQUWcf48qZ5oPWwNJ_-zwR7O0nU74tqvWJc;bili_ticket_expires=1746333750;bp_t_offset_33178546=1061871406272217088;browser_resolution=1440-700;bsource=search_google;buvid_fp=2f38edc9acdcd47ea6741e387ba27e68;buvid_fp_plain=undefined;buvid3=2D3F5EBD-E95B-81C6-0717-4CDB5AB4A67E59080infoc;buvid4=96A8723D-2D12-8ED7-E6F8-12E0AAFE6EC459080-025031814-Bqlj4k15WaJUd4eekIreI07aLUUH4OZpmc5X8YPxT4xB%2FSlENo%2FP%2F6hu%2FvtyBsV0;CURRENT_FNVAL=4048;DedeUserID=33178546;DedeUserID__ckMd5=ca2d12f64a9b8568;enable_feed_channel=ENABLE;enable_web_push=DISABLE;fingerprint=2f38edc9acdcd47ea6741e387ba27e68;header_theme_version=CLOSE;hit-dyn-v2=1;home_feed_column=5;LIVE_BUVID=AUTO3717428161265239;PVID=6;rpdid=0zbfvS5A3K|exlyW49O|3zy|3w1TUy7S;SESSDATA=ec1f4ed4%2C1761626603%2Cbe63d%2A51CjDy2D2iaGGO5mQNpsZ77fWRe9NvSQ9gwha7TAap2XV_xmPUZ_YpHSJpZbgZVTSNIA4SVjIySjNLbk1YMG5mandTcTF6ekd1M0ZSM3NDV21jVFNsTFZOQzZSbFlKS0VUbkpzZ1pCWEFrX0U2UTFhRjAtbFRuYU1JRU5DOTZNUDNYcnVGa000dnZ3IIEC;sid=7fmz6v8u;bmg_af_switch=1;bmg_src_def_domain=i0.hdslb.com;';
|
||||||
|
|
||||||
|
state.set('userCookie', cookie);
|
||||||
|
const options = {
|
||||||
|
roomId: 6811411,
|
||||||
|
uid: 33178546,
|
||||||
|
};
|
||||||
|
const wsClient = new WSClient(options);
|
||||||
|
event.on(EVENTS.MESSAGE, (payload) => {
|
||||||
|
const data = payload.data;
|
||||||
|
if (Array.isArray(data)) {
|
||||||
|
// console.log('message EVENT', payload.data);
|
||||||
|
const d0 = data[0];
|
||||||
|
if (d0.cmd === 'DANMU_MSG') {
|
||||||
|
console.log('DANMU_MSG', d0);
|
||||||
|
const info = d0.info;
|
||||||
|
const text = info[1];
|
||||||
|
console.log('text', text);
|
||||||
|
// console.log('danmu', JSON.stringify(d0));
|
||||||
|
// const text = d0[1];
|
||||||
|
// const uid = d0[2];
|
||||||
|
// const uname = d0[3];
|
||||||
|
// const medal = d0[4];
|
||||||
|
// const medalName = medal[0];
|
||||||
|
// console.log(text, 'uid', uid, 'uname', uname, 'medal', medalName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const main = async () => {
|
||||||
|
const res = await wsClient.connect(options);
|
||||||
|
// console.log('res', res);
|
||||||
|
setTimeout(() => {
|
||||||
|
sendMessage(
|
||||||
|
{
|
||||||
|
message: 'sendMessg',
|
||||||
|
roomId: options.roomId,
|
||||||
|
},
|
||||||
|
cookie,
|
||||||
|
);
|
||||||
|
}, 1000);
|
||||||
|
};
|
||||||
|
|
||||||
|
main();
|
21
src/ws.ts
Normal file
21
src/ws.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { WebSocket } from 'ws';
|
||||||
|
const url = 'wss://zj-cn-live-comet.chat.bilibili.com:2245/sub';
|
||||||
|
|
||||||
|
const ws = new WebSocket(url, {
|
||||||
|
rejectUnauthorized: false,
|
||||||
|
headers: {
|
||||||
|
'sec-websocket-extensions': 'permessage-deflate; client_max_window_bits',
|
||||||
|
'sec-websocket-key': 'M+/4M8nREisawyttYYGuUQ==',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
ws.on('open', () => {
|
||||||
|
console.log('open');
|
||||||
|
});
|
||||||
|
ws.on('message', (data) => {
|
||||||
|
console.log(data);
|
||||||
|
});
|
||||||
|
|
||||||
|
ws.on('error', (err) => {
|
||||||
|
console.error('WebSocket error:', err);
|
||||||
|
});
|
15
tsconfig.json
Normal file
15
tsconfig.json
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"extends": "@kevisual/types/json/backend.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"baseUrl": "./",
|
||||||
|
"paths": {
|
||||||
|
"@/*": [
|
||||||
|
"src/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*.ts",
|
||||||
|
],
|
||||||
|
"exclude": [],
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user