npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bilibili-danmaku-client

v2.0.0

Published

A Node.js client for the Bilibili Live Danmaku Interface

Downloads

21

Readme

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

Introduction

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.

Installation

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.

Usage

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');
    // https://live.bilibili.com/5440
    const client = new DanmakuClient(5440);
    client.start();

Listen to Events

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

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

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.terminate();
    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.

Development

To build and test the package yourself:

  1. Clone the github repository
    $ git clone -b master https://github.com/std4453/bilibili-danmaku-client.git
  1. Build
    $ npm install && npm run build
  1. Test
    $ npm test

Links

Author

License

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