bililive/lib.rs
1//! A simple stream-based bilibili live client library.
2//!
3//! *Minimum supported rust version: 1.53.0*
4//!
5//! ## Runtime Support
6//!
7//! This crate supports both `tokio` and `async-std` runtime.
8//!
9//! `tokio` support is enabled by default. While used on an `async-std` runtime, change the corresponding dependency in Cargo.toml to
10//!
11//! ```toml
12//! bililive = { version = "0.1", default-features = false, features = ["async-native-tls"] }
13//! ```
14//!
15//! See `Crates Features` section for more.
16//!
17//! ## Features
18//!
19//! - Ergonomic `Stream`/`Sink` interface.
20//! - Easy establishment of connection via given live room id.
21//! - Handles heartbeat packets automatically.
22//! - Auto retry when connection fails (optional).
23//! - Decompresses `Zlib` payloads automatically.
24//!
25//! ## Example
26//!
27//! ```rust
28//! # #[cfg(feature = "tokio")]
29//! use bililive::connect::tokio::connect_with_retry;
30//! use bililive::errors::Result;
31//! use bililive::{ConfigBuilder, RetryConfig};
32//!
33//! use futures::StreamExt;
34//! use log::info;
35//! use serde_json::Value;
36//!
37//! # #[cfg(feature = "tokio")]
38//! # async fn test() -> Result<()> {
39//! let config = ConfigBuilder::new()
40//! .by_uid(1602085)
41//! .await?
42//! .fetch_conf()
43//! .await?
44//! .build()?;
45//!
46//! let mut stream = connect_with_retry(config, RetryConfig::default()).await?;
47//! while let Some(e) = stream.next().await {
48//! match e {
49//! Ok(packet) => {
50//! info!("raw: {:?}", packet);
51//! if let Ok(json) = packet.json::<Value>() {
52//! info!("json: {:?}", json);
53//! }
54//! }
55//! Err(e) => {
56//! info!("err: {:?}", e);
57//! }
58//! }
59//! }
60//! #
61//! # Ok(())
62//! # }
63//! ```
64//!
65//! ## Crate Features
66//!
67//! * `tokio-native-tls`(default): Enables `tokio` support with TLS implemented
68//! via [tokio-native-tls](https://crates.io/crates/tokio-native-tls).
69//! * `tokio-rustls-native-certs`: Enables `tokio` support with TLS implemented
70//! via [tokio-rustls](https://crates.io/crates/tokio-rustls) and uses native system certificates found
71//! with [rustls-native-certs](https://github.com/rustls/rustls-native-certs).
72//! * `tokio-rustls-webpki-roots`: Enables `tokio` support with TLS implemented
73//! via [tokio-rustls](https://crates.io/crates/tokio-rustls) and uses the
74//! certificates [webpki-roots](https://github.com/rustls/webpki-roots) provides.
75//! * `async-native-tls`: Enables `async_std` support with TLS implemented
76//! via [async-native-tls](https://crates.io/crates/async-native-tls).
77
78#[doc(inline)]
79pub use crate::builder::ConfigBuilder;
80#[doc(inline)]
81pub use crate::config::{RetryConfig, StreamConfig};
82#[doc(inline)]
83pub use crate::errors::BililiveError;
84#[doc(inline)]
85pub use crate::packet::{Operation, Packet, Protocol};
86#[doc(inline)]
87pub use crate::stream::BililiveStream;
88
89#[macro_use]
90mod utils;
91pub mod builder;
92pub mod config;
93pub mod connect;
94pub mod errors;
95pub mod packet;
96pub mod stream;