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.

messaging
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.

ESM import; CommonJS requires destructuring.

import { LiveWS } from 'bilibili-live-ws'

ESM import; CommonJS requires destructuring.

import { LiveTCP } from 'bilibili-live-ws'

Auto-reconnecting WebSocket version.

import { KeepLiveWS } from 'bilibili-live-ws'
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 footguns
breakingVersion 6.x requires ESM imports; CommonJS require() must be destructured.
deprecatedLiveTCP and KeepLiveTCP are experimental and may be removed in the future.
gotchaBrowser support is experimental; you may need to manually import from 'bilibili-live-ws/browser'.
breakingVersion 5.x to 6.x: authBody option shape changed; now object is encoded automatically.
gotchaprotover=3 (brotli) requires Node.js >= 11.7 or browser with brotli support.
gotchaIf roomId is invalid, the 'live' event may never fire; check room existence.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
18 hits · last 30 days
gptbot
3
bytedance
3
ahrefsbot
1
Resources