All Projects → simon300000 → Bilibili Live Ws

simon300000 / Bilibili Live Ws

Licence: mit
Bilibili live WebSocket/tcp API

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Bilibili Live Ws

Hprose Nodejs
Hprose is a cross-language RPC. This project is Hprose 2.0 for Node.js
Stars: ✭ 297 (+275.95%)
Mutual labels:  websocket, tcp
Gsnova
Private proxy solution & network troubleshooting tool.
Stars: ✭ 509 (+544.3%)
Mutual labels:  websocket, tcp
Laravel S
LaravelS is an out-of-the-box adapter between Swoole and Laravel/Lumen.
Stars: ✭ 3,479 (+4303.8%)
Mutual labels:  websocket, tcp
Bilibili danmuji
(Bilibili)B站直播礼物答谢、定时广告、关注感谢,自动回复工具,房管工具,自动打卡,Bilibili直播弹幕姬(使用websocket协议),java版B站弹幕姬,基于springboot。
Stars: ✭ 76 (-3.8%)
Mutual labels:  bilibili, websocket
Elixir Socket
Socket wrapping for Elixir.
Stars: ✭ 642 (+712.66%)
Mutual labels:  websocket, tcp
Shineframe
高性能超轻量级C++开发库及服务器编程框架
Stars: ✭ 274 (+246.84%)
Mutual labels:  websocket, tcp
Message Io
Event-driven message library for building network applications easy and fast.
Stars: ✭ 321 (+306.33%)
Mutual labels:  websocket, tcp
Qtswissarmyknife
QSAK (Qt Swiss Army Knife) is a multi-functional, cross-platform debugging tool based on Qt.
Stars: ✭ 196 (+148.1%)
Mutual labels:  websocket, tcp
Blinksocks
A framework for building composable proxy protocol stack.
Stars: ✭ 587 (+643.04%)
Mutual labels:  websocket, tcp
Grain
grain是一个极简的、组件式的RPC框架,灵活且适合渐进学习,可与任何框架整合。同时包含(系统通用多线程模型与消息通讯 || 多对多关系的分布式锁 || 基于Servlet的HTTP框架 || 基于系统通用多线程模型的Websocket框架 || 支持行级锁的多线程锁 )等组件,按需选择组件,不绑架开发者。
Stars: ✭ 577 (+630.38%)
Mutual labels:  websocket, tcp
Rsocket Kotlin
RSocket Kotlin multi-platform implementation
Stars: ✭ 256 (+224.05%)
Mutual labels:  websocket, tcp
Bigq
Messaging platform in C# for TCP and Websockets, with or without SSL
Stars: ✭ 18 (-77.22%)
Mutual labels:  websocket, tcp
Frpc Android
Android,安卓版frpc,一个快速反向代理,可帮助您将NAT或防火墙后面的本地服务器暴露给Internet。
Stars: ✭ 205 (+159.49%)
Mutual labels:  websocket, tcp
Firefly
Firefly is an asynchronous web framework for rapid development of high-performance web application.
Stars: ✭ 277 (+250.63%)
Mutual labels:  websocket, tcp
Asio2
Header only c++ network library, based on asio,support tcp,udp,http,websocket,rpc,ssl,icmp,serial_port.
Stars: ✭ 202 (+155.7%)
Mutual labels:  websocket, tcp
Simps
🚀 A simple, lightweight and high-performance PHP coroutine framework.
Stars: ✭ 318 (+302.53%)
Mutual labels:  websocket, tcp
Actionhero
Actionhero is a realtime multi-transport nodejs API Server with integrated cluster capabilities and delayed tasks
Stars: ✭ 2,280 (+2786.08%)
Mutual labels:  websocket, tcp
Httpcanary
A powerful capture and injection tool for the Android platform
Stars: ✭ 2,188 (+2669.62%)
Mutual labels:  websocket, tcp
Getty
a netty like asynchronous network I/O library based on tcp/udp/websocket; a bidirectional RPC framework based on JSON/Protobuf; a microservice framework based on zookeeper/etcd
Stars: ✭ 532 (+573.42%)
Mutual labels:  websocket, tcp
Beetlex
high performance dotnet core socket tcp communication components, support TLS, HTTP, HTTPS, WebSocket, RPC, Redis protocols, custom protocols and 1M connections problem solution
Stars: ✭ 802 (+915.19%)
Mutual labels:  websocket, tcp

bilibili-live-ws npm Coverage Status Node CI

Bilibili 直播 WebSocket/TCP API

LiveWS/KeepLiveWS 支持浏览器 (实验性)

API

const { LiveWS, LiveTCP, KeepLiveWS, KeepLiveTCP } = require('bilibili-live-ws')
const live = new LiveWS(roomid)
// 或
const live = new LiveTCP(roomid)

举个栗子:

const live = new LiveWS(14275133)

live.on('open', () => console.log('Connection is established'))
// Connection is established
live.on('live', () => {
  live.on('heartbeat', console.log)
  // 74185
})

或者用TCP (新功能):

const live = new LiveTCP(26283)

live.on('open', () => console.log('Connection is established'))
// Connection is established
live.on('live', () => {
  live.on('heartbeat', console.log)
  // 13928
})

晚上做梦梦到一个白胡子的老爷爷和我说TCP更节约内存哦!

Class: LiveWS / LiveTCP / KeepLiveWS / KeepLiveTCP

(Keep)LiveWS 和 (Keep)LiveTCP 的大部分API基本上一样, 区别在本文末尾有注明

new LiveWS(roomid [, { address, protover, key }])

new LiveTCP(roomid [, { host, port, protover, key }])

  • roomid 房间号

    比如 https://live.bilibili.com/14327465 中的 14327465

  • address 可选, WebSocket连接的地址

    默认 'wss://broadcastlv.chat.bilibili.com/sub'

  • host 可选, TCP连接的地址

    默认 'broadcastlv.chat.bilibili.com'

  • port 可选, TCP连接的端口

    默认 2243

  • protover 可选, 见 #17

    默认 2

  • key 可选, WS握手的Token

live.on('open')

WebSocket连接上了

live.on('live')

成功登入房间

live.on('heartbeat', (online) => ...)

收到服务器心跳包,会在30秒之后自动发送心跳包。

  • online 当前人气值

live.on('msg', (data) => ...)

  • data 收到信息/弹幕/广播等

    data的例子: (我simon3000送了一个辣条)

    {
      cmd: 'SEND_GIFT',
      data: {
        giftName: '辣条',
        num: 1,
        uname: 'simon3000',
        face: 'http://i1.hdslb.com/bfs/face/c26b9f670b10599ad105e2a7fea4b5f21c0f0bcf.jpg',
        guard_level: 0,
        rcost: 2318827,
        uid: 3499295,
        top_list: [],
        timestamp: 1555690631,
        giftId: 1,
        giftType: 0,
        action: '喂食',
        super: 0,
        super_gift_num: 0,
        price: 100,
        rnd: '1555690616',
        newMedal: 0,
        newTitle: 0,
        medal: [],
        title: '',
        beatId: '0',
        biz_source: 'live',
        metadata: '',
        remain: 6,
        gold: 0,
        silver: 0,
        eventScore: 0,
        eventNum: 0,
        smalltv_msg: [],
        specialGift: null,
        notice_msg: [],
        capsule: null,
        addFollow: 0,
        effect_block: 1,
        coin_type: 'silver',
        total_coin: 100,
        effect: 0,
        tag_image: '',
        user_count: 0
      }
    }
    

live.on(cmd, (data) => ...)

用法如上,只不过只会收到特定cmd的Event。

比如 live.on('DANMU_MSG') 只会收到弹幕Event,一个弹幕Event的Data例子如下: (我simon3000发了个233)

{
  cmd: 'DANMU_MSG',
  info: [
    [0, 1, 25, 16777215, 1555692037, 1555690616, 0, 'c5c630b1', 0, 0, 0],
    '233',
    [3499295, 'simon3000', 0, 0, 0, 10000, 1, ''],
    [5, '財布', '神楽めあOfficial', 12235923, 5805790, ''],
    [11, 0, 6406234, '>50000'],
    ['title-58-1', 'title-58-1'],
    0,
    0,
    null,
    { ts: 1555692037, ct: '2277D56A' }
  ]
}

live.on('close')

连接关闭事件

live.on('error', (e) => ...)

连接 error 事件,连接同时也会关闭

live.heartbeat()

无视30秒时间,直接发送一个心跳包。

如果连接正常,会收到来自服务器的心跳包,也就是 live.on('heartbeat'),可以用于更新人气值。

live.close()

关闭WebSocket/TCP Socket连接。

live.getOnline()

立即调用 live.heartbeat() 刷新人气数值,并且返回 Promise,resolve 人气刷新后数值

live.on('message')

WebSocket/TCP收到的Raw Buffer(不推荐直接使用)

live.send(buffer)

使用 WebSocket 或者 TCP 发送信息

getConf(roomid)

选一个cdn,Resolve host, address 和 key, 可以直接放进(Keep)LiveWS/TCP设置

(需要安装 got npm i -S got)

const { getConf } = require('bilibili-live-ws/extra')

getConf(roomid)
// Return
Promise<{
    key: string;
    host: string;
    address: string;
}>

Keep和无Keep的区别

KeepLiveWS 和 KeepLiveTCP 有断线重新连接的功能

new KeepLiveWS(roomid [, { address, protover, key }])

new KeepLiveTCP(roomid [, { host, port, protover, key }])

所有上方的API都是一样的, 只不过会有以下微小的区别

  • 收到error或者close事件的时候并不代表连接关闭, 必须要手动调用live.close()来关闭连接
  • 内部的连接对象(LiveWS/LiveTCP)在live.connection
  • 内部的连接关闭了之后, 如果不是因为live.close()关闭, 会在100毫秒之后自动打开一个新的连接。
    • 这个100毫秒可以通过改变live.interval来设置
  • 内部的boolean, live.closed, 用于判断是否是因为live.close()关闭。

LiveWS 和 LiveTCP 的区别

LiveWS.ws

LiveWS 内部 WebSocket 对象,需要时可以直接操作

Doc: https://github.com/websockets/ws/blob/master/doc/ws.md#class-websocket

LiveTCP.socket

LiveTCP 内部 TCP Socket 对象,需要时可以直接操作

Doc: https://nodejs.org/api/net.html#net_class_net_socket

LiveTCP.buffer

LiveTCP内部TCP流的Buffer缓冲区,有不完整的包

LiveTCP.splitBuffer()

处理LiveTCP内部TCP流的Buffer缓冲区,把其中完整的包交给decoder处理

BenchMark 简单对比

在连接了640个直播间后过了一分钟左右(@2.0.0)

LiveWS (wss) LiveWS (ws) LiveTCP
内存占用 63 MB 26 MB 18 MB

参考资料: https://github.com/lovelyyoshino/Bilibili-Live-API/blob/master/API.WebSocket.md

贡献

欢迎Issue和Pull Request!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].