Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/starknt/tiny-bilibili-ws
Bilibili Live websocket api. (API docs WIP)
https://github.com/starknt/tiny-bilibili-ws
bilibili-api bilibili-live nodejs typescript
Last synced: 12 days ago
JSON representation
Bilibili Live websocket api. (API docs WIP)
- Host: GitHub
- URL: https://github.com/starknt/tiny-bilibili-ws
- Owner: starknt
- License: mit
- Created: 2022-09-26T13:47:33.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-21T06:39:55.000Z (3 months ago)
- Last Synced: 2024-08-21T18:13:39.845Z (3 months ago)
- Topics: bilibili-api, bilibili-live, nodejs, typescript
- Language: TypeScript
- Homepage: https://starknt.github.io/tiny-bilibili-ws
- Size: 686 KB
- Stars: 34
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-bilibili-extra - Tiny-bilibili-ws - Bilibili 直播 WebSocket API.![TypeScript](svg/tsnode.svg?raw=true) (开发 / 直播脚本)
README
# tiny-bilibili-ws
[![Version](https://img.shields.io/npm/v/tiny-bilibili-ws?style=flat&colorA=000000&colorB=000000)](https://www.npmjs.com/package/tiny-bilibili-ws)
[![Build Size](https://img.shields.io/bundlephobia/minzip/jotai?label=bundle%20size&style=flat&colorA=000000&colorB=000000)](https://bundlephobia.com/result?p=tiny-bilibili-ws)
[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/tiny-bilibili-ws)## 特点
- 同时支持浏览器和NodeJs环境
- 开箱即用的 Typescript 类型提示
- 轻量级的包体积## 文档
阅读 [文档](https://starknt.github.io/tiny-bilibili-ws) 查看更多信息.
## 安装
### Npm
```bash
npm install --save tiny-bilibili-ws
```### Yarn
```bash
yarn add tiny-bilibili-ws
```### Pnpm
```bash
pnpm install tiny-bilibili-ws
```## 简单使用
```typescript
// In Nodejs environment
import { KeepLiveTCP, getLongRoomId, toMessageData } from 'tiny-bilibili-ws'// or browser environment
import { KeepLiveWS } from 'tiny-bilibili-ws/browser'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}`)
})// 因为存在跨域问题, getLongRoomId 这个 API 不能在浏览器中运行
new KeepLiveWS(652581) // Now Long Room id: 4350043
```## Credits
Inspired by [https://github.com/simon300000/bilibili-live-ws](https://github.com/simon300000/bilibili-live-ws)
## 参考资料
Bilibili API: [https://github.com/lovelyyoshino/Bilibili-Live-API/blob/master/API.WebSocket.md](https://github.com/lovelyyoshino/Bilibili-Live-API/blob/master/API.WebSocket.md)
## License
[MIT](./LICENSE) License ©2022 [starknt](https://github.com/starknt)