Expand description
A simple stream-based bilibili live client library.
Minimum supported rust version: 1.53.0
§Runtime Support
This crate supports both tokio and async-std runtime.
tokio support is enabled by default. While used on an async-std runtime, change the corresponding dependency in Cargo.toml to
bililive = { version = "0.1", default-features = false, features = ["async-native-tls"] }See Crates Features section for more.
§Features
- Ergonomic
Stream/Sinkinterface. - Easy establishment of connection via given live room id.
- Handles heartbeat packets automatically.
- Auto retry when connection fails (optional).
- Decompresses
Zlibpayloads automatically.
§Example
use bililive::connect::tokio::connect_with_retry;
use bililive::errors::Result;
use bililive::{ConfigBuilder, RetryConfig};
use futures::StreamExt;
use log::info;
use serde_json::Value;
let config = ConfigBuilder::new()
.by_uid(1602085)
.await?
.fetch_conf()
.await?
.build()?;
let mut stream = connect_with_retry(config, RetryConfig::default()).await?;
while let Some(e) = stream.next().await {
match e {
Ok(packet) => {
info!("raw: {:?}", packet);
if let Ok(json) = packet.json::<Value>() {
info!("json: {:?}", json);
}
}
Err(e) => {
info!("err: {:?}", e);
}
}
}§Crate Features
tokio-native-tls(default): Enablestokiosupport with TLS implemented via tokio-native-tls.tokio-rustls-native-certs: Enablestokiosupport with TLS implemented via tokio-rustls and uses native system certificates found with rustls-native-certs.tokio-rustls-webpki-roots: Enablestokiosupport with TLS implemented via tokio-rustls and uses the certificates webpki-roots provides.async-native-tls: Enablesasync_stdsupport with TLS implemented via async-native-tls.
Modules§
- builder
bililiveconfig builder.- config
- Configuration types.
- connect
- Connection related functions and types.
- errors
- Error types.
- packet
- Packet types.
- stream
- Bilibili live stream.
Structs§
- Bililive
Stream - A wrapper around an underlying websocket stream (w/o retry) which implements bilibili live protocol.
- Config
Builder bililivestream config builder.- Packet
- Bililive packet.
- Retry
Config - The configuration for retry behavior.
- Stream
Config - The configuration for bilibili live stream connection.
Enums§
- Bililive
Error - The main error type.
- Operation
- Live event types.
- Protocol
- Protocol types.