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 🙏

© 2025 – Pkg Stats / Ryan Hefner

isomorphic-danmaku

v0.0.8

Published

[![version](https://img.shields.io/npm/v/isomorphic-danmaku.svg)](https://www.npmjs.com/package/isomorphic-danmaku) [![MIT License](https://img.shields.io/npm/l/isomorphic-danmaku.svg)](https://github.com/3Shain/isomorphic-danmaku/LICENSE) [![PRs Welcome]

Downloads

19

Readme

📖 isomorphic-danmaku

version MIT License PRs Welcome

browser/nodejs 同构的直播平台弹幕获取

此package仍在活跃开发阶段,接口规范尚未确定,请注意后续可能产生的breaking change

💻 支持平台(字母排序)

  • acfun
  • bilibili

暂不对数据二次封装,需自行处理消息的解析。之后可能会有计划提出并封装为一种标准格式并提供一个 pure function pipe

📖 安装

npm install isomorphic-danmaku

🍥 食用方法

建立连接

  1. 预获取房间信息(bilibili可省略,acfun必须)
// 以esmodule导入为例子,nodejs下也可以使用require()
import { getAcfunRoomInfo, getBilibiliRoomInfo } from 'isomorphic-danmaku-server'; //注意后面的-server

// 获取对应房间信息

const acinfo = await getAcfunRoomInfo(123456);

const biliinfo = await getBilibiliRoomInfo(123456);

此步骤只能运行在nodejs上,因为浏览器无法跨域请求。如果你想在浏览器上直接连接(ws默认不禁止跨域),则需要有一个服务端为其提供这些预请求房间信息。

  1. 连接房间并获取弹幕

import { connectBilibiliLiveWs } from 'isomorphic-danmaku';
// 对于acfun
import { connectAcfunLiveWs } from 'isomorphic-danmaku';

for await (let msg of connectBilibiliLiveWs({ roomId: 123456 })){
    // 直接处理msg
    console.log(msg);
    // 跳过continue,停止处理则可使用break
}

Acfun需要的参数信息

{
    roomId: number; //房间号
    //以下字段均从上述接口获取
    acSecurity: string;
    serviceToken: string;
    tickets: string[];
    liveId: string;
    userId: stirng;
    enterRoomAttach: string;
}

Bilibili需要的参数信息

{
    roomId: number; // 房间号
    host?: string; // 连接的服务器,是一个域名
    token?: string; // 可从roominfo接口获取
}

scripts/文件夹内有nodejs的例子。

在浏览器上使用(连接ws的部分)

在 package.json 里添加以下字段

"browser": {
    "@peculiar/webcrypto": false
}

这是为了告诉 bundler(如 webpack,rollup 此类)忽略这些包的导入(大多是node环境独有的包)。

暂不提供 umd 打包格式,即无法直接通过添加一个<script>标签的形式引入

📃 TODO

  • acfun返回内容的细化(搬砖)
  • 添加测试
  • 标准化信息,标准的制定,pure function pipe

❓ 常见问题

Q: 'Can't resolve module 'xxx' ....

A: 这是使用webpack等打包浏览器端时经常出现的问题。原因往往是引入的包引入的包引入的包...总之在某一层引入了只能运行于node环境的包,即使实际逻辑根本不会用到那个包。可以通过上述package.json中的browser字段添加那个包以解决。