Registry / messaging / bilibili-live-ws

bilibili-live-ws

JSON →
library6.3.1jsnpmunverified

A JavaScript/TypeScript library for connecting to Bilibili Live WebSocket and TCP APIs. Version 6.3.1 is the latest stable release. It provides four main classes (LiveWS, LiveTCP, KeepLiveWS, KeepLiveTCP) for real-time room events like danmaku, gifts, and heartbeats. Supports browser environment with experimental browser build. Includes TypeScript type definitions. Features automatic heartbeats, custom auth for Bilibili Open Live platform, and multiple protocol versions (1, 2, 3) for compression.

npm install bilibili-live-ws
INSTALL
IMPORT
SIG · BILIBILI-LIVE-WS
B
bilibili-live-ws
messagingjavascriptv6.3.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LiveWS
import { LiveWS } from 'bilibili-live-ws'
const LiveWS = require('bilibili-live-ws').LiveWS
ESM import; CommonJS requires destructuring.
LiveTCP
import { LiveTCP } from 'bilibili-live-ws'
const LiveTCP = require('bilibili-live-ws').LiveTCP
ESM import; CommonJS requires destructuring.
KeepLiveWS
import { KeepLiveWS } from 'bilibili-live-ws'
Auto-reconnecting WebSocket version.
KeepLiveTCP
import { KeepLiveTCP } from 'bilibili-live-ws'

Connects to a Bilibili live room via WebSocket, listens for open, live, heartbeat, and message events.

import { LiveWS } from 'bilibili-live-ws'; const roomId = 14275133; // Replace with actual room id const live = new LiveWS(roomId); live.on('open', () => { console.log('Connection is established'); }); live.on('live', () => { console.log('Successfully joined room'); live.on('heartbeat', (online) => { console.log(`Current popularity: ${online}`); }); }); live.on('msg', (data) => { console.log('Received message:', data); }); live.on('error', (err) => { console.error('WebSocket error:', err); });
Debug
Known issues
breakingVersion 6.x requires ESM imports; CommonJS require() must be destructured.
fix
Use `import { LiveWS } from 'bilibili-live-ws'` or `const { LiveWS } = require('bilibili-live-ws')`.
affects: >=6.0.0
deprecatedLiveTCP and KeepLiveTCP are experimental and may be removed in the future.
fix
Consider using LiveWS/KeepLiveWS instead.
affects: >=6.0.0
gotchaBrowser support is experimental; you may need to manually import from 'bilibili-live-ws/browser'.
fix
Use `import { LiveWS } from 'bilibili-live-ws/browser'` in browser environments.
affects: >=6.0.0
breakingVersion 5.x to 6.x: authBody option shape changed; now object is encoded automatically.
fix
Pass authBody as object (not pre-encoded) for automatic encoding.
affects: >=6.0.0
gotchaprotover=3 (brotli) requires Node.js >= 11.7 or browser with brotli support.
fix
Ensure runtime supports brotli or use protover=2 (zlib).
affects: >=6.0.0
gotchaIf roomId is invalid, the 'live' event may never fire; check room existence.
fix
Verify room ID via Bilibili API before connecting.
affects: >=6.0.0
Errors
Common errors & fixes
Error: Cannot find module 'bilibili-live-ws'
Package not installed or not in node_modules.
fix
Run `npm install bilibili-live-ws`.
TypeError: LiveWS is not a constructor
Improper import: using default import instead of named import.
fix
Use `import { LiveWS } from 'bilibili-live-ws'`.
Error: pako is not defined
Missing peer dependency pako or not using buffer.
fix
Install peer dependencies: `npm install pako buffer events`.
Error: Could not connect to wss://broadcastlv.chat.bilibili.com/sub
Network issue or invalid room ID.
fix
Ensure room ID is correct and network allows WebSocket connections to bilibili.com.
Upgrade
Version history
6.3.1latest on npm
Audit
Dependencies
bufferrequiredRequired for WebSocket/ TCP buffer handling
eventsrequiredRequired for event emitter pattern
pakorequiredRequired for zlib inflate (protover=2)
Agent activity
60 hits · last 30 days
node
58
OpenAI (training)
1
Resources
bilibili-live-ws — npm install bilibili-live-ws · libregistry