Skip to content

ddiu8081/tiny-bilibili-ws

 
 

Repository files navigation

tiny-bilibili-ws

Version Build Size

特点

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

文档

阅读 文档 查看更多信息.

安装

Npm

npm install --save tiny-bilibili-ws

Yarn

yarn add tiny-bilibili-ws

Pnpm

pnpm install tiny-bilibili-ws

简单使用

// In Nodejs environment
import { KeepLiveTCP, toMessageData, getLongRoomId } from 'tiny-bilibili-ws'

const { data } = await getLongRoomId(652581)
const room = data.room_id
const tcp = new KeepLiveTCP(room)

tcp.runWhenConnected(() => {
  console.log(`正在监听 ${room}`)
})

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

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

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

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

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

// 因为存在跨域问题, getLongRoomId 这个 API 不能在浏览器中运行

new KeepLiveWS(652581) // Now Long Room id: 4350043

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

About

Bilibili Live websocket api. (API docs WIP)

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages

  • TypeScript 98.1%
  • Other 1.9%