I'm Diu 👋 / Front-end developer / Amateur designer.
Or follow me on Instagram / Dribbble / Figma / Mastodon / Twitter / 哔哩哔哩 / 小红书
View my personal configuration: VS Code Settings / Workspace
Bilibili live danmu listener with type. 类型友好的 Bilibili 直播间弹幕监听库。
Home Page: https://npmjs.com/blive-message-listener
License: MIT License
pnpm i blive-message-listener
X [ERROR] No matching export in "browser-external:node:net" for import "connect"
node_modules/.pnpm/[email protected]/node_modules/tiny-bilibili-ws/dist/index.mjs:1:9:
1 │ import { connect } from 'node:net';
╵ ~~~~~~~
X [ERROR] No matching export in "browser-external:node:zlib" for import "brotliDecompress"
node_modules/.pnpm/[email protected]/node_modules/tiny-bilibili-ws/dist/index.mjs:5:9:
5 │ import { brotliDecompress as brotliDecompress$1, inflate as inflate$1 } from 'node:zlib';
╵ ~~~~~~~~~~~~~~~~
X [ERROR] No matching export in "browser-external:node:zlib" for import "inflate"
node_modules/.pnpm/[email protected]/node_modules/tiny-bilibili-ws/dist/index.mjs:5:49:
5 │ import { brotliDecompress as brotliDecompress$1, inflate as inflate$1 } from 'node:zlib';
╵ ~~~~~~~
22:54:27 [vite] error while updating dependencies:
Error: Build failed with 3 errors:
node_modules/.pnpm/[email protected]/node_modules/tiny-bilibili-ws/dist/index.mjs:1:9: ERROR: No matching export in "browser-external:node:net" for import "connect"
node_modules/.pnpm/[email protected]/node_modules/tiny-bilibili-ws/dist/index.mjs:5:9: ERROR: No matching export in "browser-external:node:zlib" for import "brotliDecompress"
node_modules/.pnpm/[email protected]/node_modules/tiny-bilibili-ws/dist/index.mjs:5:49: ERROR: No matching export in "browser-external:node:zlib" for import "inflate"
at failureErrorWithLog (C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:1624:15)
at C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:1266:28
at runOnEndCallbacks (C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:1046:63)
at buildResponseToResult (C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:1264:7)
at C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:1377:14
at C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:678:9
at handleIncomingPacket (C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:775:9)
at Socket.readFromStdout (C:\Users\why00\Documents\project\bubblebox-web\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:644:7)
at Socket.emit (node:events:526:28)
at addChunk (node:internal/streams/readable:315:12)
貌似和这个issues 是同一个原因。
我暂时还不知道有什么解决方法。
现在b站不登录的情况下不允许查看相关内容了,是不是可以新增一个配置项 传入cookie等信息 或者header自定义配置
const bilive = require('blive-message-listener');
bilive.startListen(5050, {
onOpen() {
console.log('open');
},
onClose() {
console.log('close');
process.exit()
},
onIncomeDanmu: (msg) => {
console.log(msg.id, msg.body);
},
});
运行后立刻就关闭了。
https://stackblitz.com/edit/stackblitz-starters-d4vbxi?file=index.js
System:
OS: macOS 14.1.2
CPU: (10) arm64 Apple M1 Pro
Memory: 280.48 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
pnpm: 8.7.6 - /opt/homebrew/bin/pnpm
bun: 1.0.0 - /opt/homebrew/bin/bun
Browsers:
Chrome: 123.0.6312.87
pnpm
Add test files for main/browser
package.
No response
No response
当某位 UP 发起一次天选之人时,会有大量的抽奖弹幕,在一定程度上会挤掉文字性弹幕。此处我使用了白河愁的直播间(老白真的好喜欢抽奖)。
改进方案:可以通过弹幕消息中的 data.info[0][9]
字段初步判断是不是抽奖弹幕,当这个字段不是 0,则可能是抽奖弹幕,在 我的分析 中给出了初步的判断
上图中颜文字弹幕就是抽奖弹幕
blive-message-listener/src/index.ts
Line 6 in 7db1bd4
如果需要断开 TCP/WS 连接,simon300000/bilibili-live-ws 提供了 live.close()
方法。
但是本项目中 live
并没有返回,是否有可能把 live
一并作为 startListen()
的返回值,以方便关闭连接?
目前只在 onRoomInfoChange
回调中看到有和直播间相关的信息,是否有其他字段或方法可以在 onStartListen
后获取直播间的相关信息呢?如 直播间名称、主播名称、上下播时间之类的。
十分感谢!
RT
如题
如题
No response
No response
Currently it should only be available in the Node.js environment.
Later it will need to be tested and supported in the browser environment.
还有这几个事件你都加上呗 ^_^ 我常用
报错内容如下:
error in ./node_modules/blive-message-listener/dist/chunk-XFSH6FXD.mjs
Module parse failed: Unexpected token (159:29)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| timestamp: rawData[0][4],
| lottery: rawData[0][9] !== 0,
> emoticon: rawData[0][13]?.emoticon_unique ? {
| id: rawData[0][13].emoticon_unique,
| height: rawData[0][13].height,
@ ./node_modules/blive-message-listener/dist/index.mjs 1:0-3:30 20:2-11
error in ./node_modules/tiny-bilibili-ws/dist/index.cjs
Module parse failed: Unexpected token (20:45)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| function brotliDecompress(buf, options) {
| return new Promise((resolve, reject) => {
> node_zlib.brotliDecompress(buf, options ?? {}, handler(resolve, reject));
| });
| }
@ ./node_modules/blive-message-listener/dist/index.mjs 6:0-47 19:19-30
自我排查应该是webpack没有能解析mjs和cjs,不太清楚如何解决
环境:
"electron": "23.1.0",
"vue": "^3.0.0",
"blive-message-listener": "^0.4.4",
文档中的 handler.onRoomInfoChange
类型定义:
export type Handler = {
/** 直播间信息修改 */
onRoomInfoChange: (msg: Message<RoomInfoChangeMsg>) => void
}
type msgType = 'ROOM_CHANGE'
export interface RoomInfoChangeMsg {
/** 直播间标题 */
title: number
/** 一级分区id */
parent_area_id: number
/** 一级分区名 */
parent_area_name: number
/** 二级分区id */
area_id: number
/** 二级分区名 */
area_name: number
}
parent_area_name
和 area_name
是否是应该为 string
类型呢?
yarn add blive-message-listener
Error: require() of ES Module C:\Users\why00\Documents\project\2someone-app\node_modules\blive-message-listener\dist\index.js from C:\Users\why00\Documents\project\2someone-app\dist\preload\index.js not supported.
Instead change the require of C:\Users\why00\Documents\project\2someone-app\node_modules\blive-message-listener\dist\index.js in C:\Users\why00\Documents\project\2someone-app\dist\preload\index.js to a dynamic import() which is available in all CommonJS modules.
at __node_internal_captureLargerStackTrace (node:internal/errors:465:5)
at new NodeError (node:internal/errors:372:5)
at Module._extensions..js (node:internal/modules/cjs/loader:1148:19)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:829:12)
at c._load (node:electron/js2c/asar_bundle:5:13343)
at i._load (node:electron/js2c/renderer_init:33:356)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (C:\Users\why00\Documents\project\2someone-app\dist\preload\index.js:3:37)
at Object.<anonymous> (C:\Users\why00\Documents\project\2someone-app\dist\preload\index.js:13:3)
at Module._compile (node:internal/modules/cjs/loader:1120:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1175:10)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Module._load (node:internal/modules/cjs/loader:829:12)
at c._load (node:electron/js2c/asar_bundle:5:13343)
at i._load (node:electron/js2c/renderer_init:33:356)
at Object.<anonymous> (node:electron/js2c/renderer_init:73:2296)
at ./lib/renderer/init.ts (node:electron/js2c/renderer_init:73:2423)
at __webpack_require__ (node:electron/js2c/renderer_init:1:170)
at node:electron/js2c/renderer_init:1:1242
at ___electron_webpack_init__ (node:electron/js2c/renderer_init:1:1310)
at node:electron/js2c/renderer_init:141:194
at NativeModule.compileForInternalLoader (node:internal/bootstrap/loaders:312:7)
at NativeModule.compileForPublicLoader (node:internal/bootstrap/loaders:252:10)
at loadNativeModule (node:internal/modules/cjs/helpers:49:9)
at Module._load (node:internal/modules/cjs/loader:811:15)
at c._load (node:electron/js2c/asar_bundle:5:13343)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
// preload/index.ts
import { startListen } from 'blive-message-listener'
contextBridge.exposeInMainWorld(
'biliApi',
{
startListen,
},
)
// ****.vue
window.biliApi.startListen(inputRoomId, handler)
console.log(typeof window.biliApi.startListen) // undefine
TypeError: Cannot read properties of undefined (reading 'startListen')
at DanmuTest.vue:31:5
at callWithErrorHandling (runtime-core.esm-bundler.js:155:22)
at callWithAsyncErrorHandling (runtime-core.esm-bundler.js:164:21)
at hook.__weh.hook.__weh (runtime-core.esm-bundler.js:2684:29)
at flushPostFlushCbs (runtime-core.esm-bundler.js:341:32)
at render2 (runtime-core.esm-bundler.js:6234:9)
at mount (runtime-core.esm-bundler.js:4424:25)
at app.mount (runtime-dom.esm-bundler.js:1606:23)
at main.ts:4:16
大佬能从报错看出问题吗?如果需要看源码请直接回复。
发现有些房间的房间号是比较短的,房号只有 3、4 位(好像是排行榜靠前的或者一些比较火的主播会有这样的房间号),通过这种短的房号无法抓到弹幕;不知道是什么原因呢?有点疑惑;有没有一些解决方法?
Chinese is OK for me, I would like chatting in Chinese.
I wrote a very simple program, and it goes like this:
onIncomeDanmu: (msg) => {
...
},
onOpen: () => {
console.log('connected')
},
onStartListen: () => {
console.log('start listen')
},
onError: (err: any) => {
console.log(`error: ${err}`)
In the past few days, every time this code is executed, it can output connected
and start listen
correctly but there is no Danmu msg received.
I don't know what happened, but I noticed that there is a similar issue with the library that this project depends on here.
https://gist.github.com/tymon42/ca150b1f93a82c1be0f1bffb0586f716
System:
OS: macOS 13.4
CPU: (8) arm64 Apple M2
Memory: 79.36 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 19.7.0 - ~/.nvm/versions/node/v19.7.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v19.7.0/bin/yarn
npm: 9.5.0 - ~/.nvm/versions/node/v19.7.0/bin/npm
pnpm: 8.5.1 - ~/.nvm/versions/node/v19.7.0/bin/pnpm
Browsers:
Edge: 115.0.1901.188
Safari: 16.5
yarn
代码如下:
import { startListen } from "blive-message-listener";
const listener = startListen(652581, {
onClose: () => console.log("与直播间的连接断开了"),
});
setTimeout(() => listener.close(), 2000);
console.log会被执行两次:
与直播间的连接断开了
与直播间的连接断开了
感觉像是tiny-bilibili-ws的问题,但不确定到底是什么原因
none
node v16.13.1
npm
既然你要类型友好,就不如把emoji加上,不是指别的表情
比如[花],[爱]的这种从表情面板选择的
我现在的做法如下,字段是在info[0][15]里,height,width也有,但我写死20了,反正也是20
你可以定义个更友好的字段或几个字段,让用户自己这样拼也行
//解emoji表情的地址
const extra = JSON.parse(msg.raw.info[0][15].extra)
if(extra.emots){
// 替换emoji表情
console.log(extra.emots)
msg.body.contentHtml = msg.body.content
for(let key in extra.emots){
let reg = new RegExp(key.replace('[','\\[').replace(']','\\]'),'gi')
msg.body.contentHtml = msg.body.contentHtml.replaceAll(reg, `<img style="width: 20px; height: 20px;" src="${extra.emots[key].url}" />`)
}
}
目前,onUserAction
事件融合了 INTERACT_WORD
与 ENTRY_EFFECT
两类消息。
INTERACT_WORD
包括一般用户与大航海用户的进入消息,但会有遗漏ENTRY_EFFECT
应该仅包含大航海用户的,不过昵称不全,超长时会截断这样航海用户进入直播间时,很容易会发送两次。计划开启一个稍短的定时器来融合两条消息。
因为 app.d.ts 里有个 export enum GuardLevel
,现在会编译到 index.d.ts 里变成 enum GuardLevel
,然后引入这个包后就会报错:
// file: index.ts
import { startListen, MsgHandler } from 'blive-message-listener'
// ... codes ...
$ tsc
node_modules/blive-message-listener/dist/index.d.ts:41:1 - error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier.
编译的时候 d.ts 和 ts 的处理是不同的,其实按你这个项目的用途来看,app 不应该是 d.ts,而是一个正常的 ts 文件,因为按照官方的解释 microsoft/TypeScript#5112 (comment) ,d.ts 文件应该是构建系统的输入,不应该参与到输出,而你 app 文件里全是用于输出的,所以应该是 ts 文件,那样就可以编译成正常的 declare enum GuardLevel
。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.