Skip to content

4t145/bilive-danmaku

Repository files navigation

bilive-danmaku

Crates.io Publish Build

这个库提供模拟bilibili直播的wss连接的功能,持续迭代中

关于发送弹幕等主动api,可以看我这个仓库: https://github.com/4t145/bilibili-client

使用

通过websocket

通过使用 https://github.com/4t145/rudanmaku-core

这使你可以通过ws来获取事件,计划在未来支持ipc通讯(uds for linux,命名管道 for windows)

Cargo.toml中加入

bilive-danmaku = { version = "0.3", features = ["rt_tokio"] }

使用

use bilive_danmaku::Connector;
use futures_util::StreamExt;

async fn tokio_main() {
    let roomid = 851181;
    let connector = Connector::init(roomid, None).await.unwrap();
    let mut stream = connector.connect().await.unwrap();
    while let Some(maybe_evt) = stream.next().await {
        match maybe_evt {
            Ok(evt) => {
                log::info!("{:?}", evt);
            }
            Err(e) => {
                log::warn!("{:?}", e);
            }
        }
    }
    stream.abort();
}

数据类型在model模块中, 事件类型在event模块中

use model::{User, FansMedal};
use event::Event as BiliEvent;

已经支持的事件

参考这个文件

可参考:

feature flag

flag 功能
event 只启用model和event,不包含连接,默认启用
rt_tokio 使用tokio连接直播间
rt_wasm 运行在wasm直播间
bincode 启用bincode正反序列化
json 启用json正反序列化

默认只启用event 比如你想把收到的消息序列化为json格式,启用

[dependencies.bilive-danmaku]
# ****
features = ["rt_tokio", "json"]

提交代码

提交代码请fork一份,在自己的那一份签出新分支,然后提交到master分支

提交前请进行格式化和clippy check,可以直接运行根目录的脚本文件

windows

./fix-all

linux

bash fix-all.sh

About

b站直播api,将bilibili直播间的wss连接转化成事件(弹幕,礼物,sc之类),多runtime

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages