{"id":20808378,"url":"https://github.com/std4453/bilibili-danmaku-client","last_synced_at":"2025-05-07T06:06:02.208Z","repository":{"id":32568634,"uuid":"136827523","full_name":"std4453/bilibili-danmaku-client","owner":"std4453","description":"A Node.js client for the Bilibili Live Danmaku Interface","archived":false,"fork":false,"pushed_at":"2022-01-05T16:40:57.000Z","size":649,"stargazers_count":49,"open_issues_count":7,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T06:05:54.670Z","etag":null,"topics":["bilibili-api","bilibili-live","javascript","node","websocket"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/std4453.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-10T16:54:43.000Z","updated_at":"2024-12-14T05:42:03.000Z","dependencies_parsed_at":"2022-08-07T17:45:31.130Z","dependency_job_id":null,"html_url":"https://github.com/std4453/bilibili-danmaku-client","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/std4453%2Fbilibili-danmaku-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/std4453%2Fbilibili-danmaku-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/std4453%2Fbilibili-danmaku-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/std4453%2Fbilibili-danmaku-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/std4453","download_url":"https://codeload.github.com/std4453/bilibili-danmaku-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252823918,"owners_count":21809713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bilibili-api","bilibili-live","javascript","node","websocket"],"created_at":"2024-11-17T19:48:12.117Z","updated_at":"2025-05-07T06:06:02.185Z","avatar_url":"https://github.com/std4453.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿![Header image](assets/header.svg)\n\n[![npm](https://img.shields.io/npm/v/bilibili-danmaku-client.svg?style=flat-square)](https://www.npmjs.com/package/bilibili-danmaku-client)\n[![npm](https://img.shields.io/npm/l/bilibili-danmaku-client.svg?style=flat-square)](https://www.npmjs.com/package/bilibili-danmaku-client)\n[![david-dm](https://img.shields.io/david/std4453/bilibili-danmaku-client.svg?style=flat-square)](https://github.com/std4453/bilibili-danmaku-client)\n[![Maintainability](https://api.codeclimate.com/v1/badges/0f3581cbb3d2d9bd0243/maintainability)](https://codeclimate.com/github/std4453/bilibili-danmaku-client/maintainability)\n\n# Bilibili Danmaku Client\n\nA standalone client for connecting to the Bilibili Live Danmaku Interface, in Node.js and the browser.\n\n_Read this in another language: [English](README.md), [简体中文](README.zh-cn.md)._\n\n## Table of content\n\n- [Introduction](#introduction)\n- [Installation](#installation)\n- [Usage](#usage)\n    - [Open a connection](#open-a-connection)\n    - [Listen to Events](#listen-to-events)\n    - [Listen to client lifecycle](#listen-to-client-lifecycle)\n    - [Terminate client](#terminate-client)\n- [Usage in browser](#usage-in-browser)\n- [Developement](#development)\n- [Links](#links)\n- [Author](#author)\n- [License](#license)\n\n## Introduction\n\nNever heard of Bilibili or Danmaku? You're out of this. Close this page and have a cup of coffee might be the wise choice.\n\nAnd 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.\n\n`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.\n\n## Installation\n\nIt can't be easier to install a `npm` package.\n\nFirst make sure that you have `npm` and `node` correctly installed and in `PATH`, and then:\n\n```console\n    $ npm install --save bilibili-danmaku-client\n```\n\nIf you see something like `peer dependencies not installed`, don't panic, see [this sector](#usage-in-browser) below.\n\n## Usage\n\n\u003e If you wonder what you can do with this package, please see this [demo](https://std4453.github.io/bilibili-danmaku-client) first.\n\n`bilibili-danmaku-client` is easy to use. You can:\n\n### Open a connection\n\n```javascript\n    const DanmakuClient = require('bilibili-danmaku-client');\n    // https://live.bilibili.com/5440\n    const client = new DanmakuClient(5440);\n    client.start();\n```\n\n### Listen to Events\n\n```javascript\n    const client = ...;\n    \n    const onDanmaku = ({ content, sender }) =\u003e\n        console.log(`${sender.name}: ${content}`);\n    const onGift = ({ gift, num, sender }) =\u003e\n        console.log(`${sender.name} =\u003e ${gift.name} * ${num}`);\n\n    client.on('event', ({ name, content }) =\u003e {\n        switch (name) {\n        case 'danmaku':\n            onDanmaku(content);\n            break;\n        case 'gift':\n            onGift(content);\n            break;\n        }\n    })\n```\n\nFor more information about __Events__, see [Wiki](https://github.com/std4453/bilibili-danmaku-client/wiki/Events).\n\n### Listen to client lifecycle\n\n```javascript\n    const client = ...;\n    client.on('open', () =\u003e console.log('Client opened.'));\n    client.on('close', () =\u003e console.log('Client closed.'));\n```\n\n### Terminate client\n\n```javascript\n    const client = ...;\n    client.terminate();\n    client.on('close' () =\u003e console.log('Client closed.'));\n```\n\nNote that you must listen to the `'close'` event to be notified when the client is actually closed. `terminate()` only requests close, not forces it.\n\nFor more information about how to use `DanmakuClient`, see [Wiki](https://github.com/std4453/bilibili-danmaku-client/wiki/DanmakuClient).\n\n## Usage in browser\n\nActually 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.\n\nIn 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_](https://nodejs.org/en/blog/npm/peer-dependencies/). So if you run `npm install`, you might hear it complain about not installed peer dependecies.\n\nDon'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.\n\nI recommend using a bundler like [browserify](https://browserify.org/) or [webpack](https://webpack.js.org/). 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.\n\n## Development\n\nTo build and test the package yourself:\n\n1. Clone the github repository\n\n```console\n    $ git clone -b master https://github.com/std4453/bilibili-danmaku-client.git\n```\n\n2. Build\n\n```console\n    $ npm install \u0026\u0026 npm run build\n```\n\n3. Test\n\n```console\n    $ npm test\n```\n\n## Links\n\n- [Live demo](https://std4453.github.io/bilibili-danmaku-client)\n- [npm package](https://www.npmjs.com/package/bilibili-danmaku-client)\n- [Zhihu article](https://zhuanlan.zhihu.com/p/37874066) (Chinese)\n- [API reference](https://github.com/std4453/bilibili-danmaku-client/wiki/DanmakuClient)\n\n## Author\n\n- __std4453__ - [me@std4453.com](mailto:me@std4453.com) - [blog](http://blog.std4453.com)\n\n## License\n\nThis project is licensed under the _MIT License_, see [LICENSE](/LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstd4453%2Fbilibili-danmaku-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstd4453%2Fbilibili-danmaku-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstd4453%2Fbilibili-danmaku-client/lists"}