A TypeScript-friendly WebSocket client for Bilibili live danmaku (bullet comments) and room events. Version 0.7.16 supports Node.js and browser environments with ESM and CJS builds. Provides LiveWS and KeepLiveWS classes for connecting to Bilibili live rooms, automatically handling heartbeats, reconnection, and message parsing. It decodes zlib (protover=2) and brotli (protover=3) payloads, emits typed events for commands like DANMU_MSG, SEND_GIFT, and HEARTBEAT_REPLY. Compared to alternatives like bilibili-live-ws, this library modernizes the API using standard WebSocket and EventTarget patterns, includes TypeScript definitions, and supports custom auth for open-live.bilibili.com. Released under MIT license with monthlyish updates.
npm install bilibili-live-danmakuNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Connects to Bilibili room 14327465 using LiveWS, listens for DANMU_MSG and SEND_GIFT events.
Use addEventListener with uppercase event names: 'CONNECT_SUCCESS', 'HEARTBEAT_REPLY', 'MESSAGE', 'DANMU_MSG', etc.
Set protover to 2 (zlib) if environment doesn't support Brotli, or use a polyfill.
Replace live.on('DANMU_MSG', callback) with live.addEventListener('DANMU_MSG', callback).Check KeepLiveWS signature: new KeepLiveWS(roomid, options) but options.authBody is used instead of individual fields.
Ensure authBody matches expected format; roomid in authBody takes precedence.
Install 'ws' and set global.WebSocket = require('ws') before importing the library.Install 'ws' and set global.WebSocket = require('ws'); before importing the library.Run 'npm install bilibili-live-danmaku' and use correct import: import { LiveWS } from 'bilibili-live-danmaku'. Ensure tsconfig has esModuleInterop or moduleResolution node.Use import { LiveWS } from 'bilibili-live-danmaku' instead of import LiveWS from 'bilibili-live-danmaku'.