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

tiny-bilibili-ws

v1.0.1

Published

Bilibili Live WebSocket/TCP API

Downloads

395

Readme

tiny-bilibili-ws

Version Build Size jsDocs.io

特点

  • 开箱即用
  • 同时支持浏览器和 NodeJs 环境
  • 开箱即用的 Typescript 类型提示
  • 轻量级的包体积

文档

阅读 文档 查看更多信息.

安装

pnpm install tiny-bilibili-ws

简单使用

在 Nodejs 中使用

import { KeepLiveWS, toMessageData } from 'tiny-bilibili-ws'

const room = 652581
const live = new KeepLiveWS(room, {
  // 触发风控后,你会无法获取弹幕发送者的用户名,详情可见:https://github.com/ddiu8081/blive-message-listener/issues/29, 传入以下参数即可解除
  headers: {
    Cookie: 'xxx', // 从 Bilibili 网页版获取
  },
  uid: 0, // 你的 Cookie 对应的 UID
})

live.runWhenConnected(() => {
  console.log(`正在监听 ${room}`) // 连接成功后才会触发
})

live.on('heartbeat', (online) => {
  console.log('人气值: ', online)
})

live.on('DANMU_MSG', (danmu) => {
  console.log(toMessageData(danmu))
})

live.on('error', (e) => {
  console.error('错误: ', e)
})

live.on('close', () => {
  console.log(`退出监听 ${room}`)
})

在浏览器中使用

import { KeepLiveWS } from 'tiny-bilibili-ws/browser'

// 因为存在跨域问题, Bilibili API 不能在浏览器中访问,现在需要手动传入 key 和 url
// 例子可以参考 https://github.com/starknt/tiny-bilibili-ws/blob/master/playground/src/App.vue#L13
const room = 652581
const live = new KeepLiveWS(room, {
  url: 'xxx',
  key: 'xxx',
})

live.runWhenConnected(() => {
  console.log(`正在监听 ${room}`) // 连接成功后才会触发
})

live.on('heartbeat', (online) => {
  console.log('人气值: ', online)
})

live.on('DANMU_MSG', (danmu) => {
  console.log(toMessageData(danmu))
})

live.on('error', (e) => {
  console.error('错误: ', e)
})

live.on('close', () => {
  console.log(`退出监听 ${room}`)
})

Credits

Inspired by https://github.com/simon300000/bilibili-live-ws

参考资料

Bilibili API: https://github.com/lovelyyoshino/Bilibili-Live-API/blob/master/API.WebSocket.md

License

MIT License ©2022 starknt