Skip to content
A Node.js client for the Bilibili Live Danmaku Interface
Branch: master
Clone or download
Latest commit b738af5 Jun 18, 2018

Header image

npm npm david-dm Maintainability

Bilibili Danmaku Client

A standalone client for connecting to the Bilibili Live Danmaku Interface, in Node.js and the browser.

Read this in another language: English, 简体中文.

Table of content


Never heard of Bilibili or Danmaku? You're out of this. Close this page and have a cup of coffee might be the wise choice.

And if you're finding a way to watch on a Bilibili Live room, analyze danmaku programmatically, either for statistical or some squeaky purposes, you've come the right place. bilibili-danmaku-client will be exactly what you want.

bilibili-danmaku-client is a npm package that runs in Node.js or in the browser, providing an easy, fluent API for listening to the activities happening in a Bilibili Live room.


It can't be easier to install a npm package.

First make sure that you have npm and node correctly installed and in PATH, and then:

    $ npm install --save bilibili-danmaku-client

If you see something like peer dependencies not installed, don't panic, see this sector below.


If you wonder what you can do with this package, please see this demo first.

bilibili-danmaku-client is easy to use. You can:

Open a connection

    const DanmakuClient = require('bilibili-danmaku-client');
    const client = new DanmakuClient(5440);

Listen to Events

    const client = ...;
    const onDanmaku = ({ content, sender }) =>
        console.log(`${}: ${content}`);
    const onGift = ({ gift, num, sender }) =>
        console.log(`${} => ${} * ${num}`);

    client.on('event', ({ name, content }) => {
        switch (name) {
        case 'danmaku':
        case 'gift':

For more information about Events, see Wiki.

Listen to client lifecycle

    const client = ...;
    client.on('open', () => console.log('Client opened.'));
    client.on('close', () => console.log('Client closed.'));

Terminate client

    const client = ...;
    client.on('close' () => console.log('Client closed.'));

Note that you must listen to the 'close' event to be notified when the client is actually closed. terminate() only requests close, not forces it.

For more information about how to use DanmakuClient, see Wiki.

Usage in browser

Actually this is not about bilibili-danmaku-client itself, but about the x-platform-ws package, which bilibili-danmaku-client depends on, and is a small utility package of mine.

In order to be compatible both in Node.js and in the browser, x-platform-ws requies shimming of the buffer and events Node.js module, therefore it declares them as peer dependencies. So if you run npm install, you might hear it complain about not installed peer dependecies.

Don't panic. That's perfectly unproblematic if you're only using bilibili-danmaku-client in Node.js, as shimming is not required there. But if you tend to use the package in a browser, you should read on.

I recommend using a bundler like browserify or webpack. they will automatically detect usage of buffer and events and provide shimming. Unfortunately, I happen to have no knowledge about how to use this package without a bundler, so - you have to figure the solution out yourself.


To build and test the package yourself:

  1. Clone the github repository
    $ git clone -b master
  1. Build
    $ npm install && npm run build
  1. Test
    $ npm test




This project is licensed under the MIT License, see LICENSE for details.

You can’t perform that action at this time.