5 unstable releases

0.3.1 Mar 26, 2023
0.3.0 Mar 23, 2023
0.2.1 Dec 2, 2022
0.2.0 Dec 2, 2022
0.1.0 Nov 27, 2022

#282 in WebSocket

40 downloads per month

MIT license

27KB
681 lines

felgens

Bilibili live danmu websocket library

asciicast

Usage

use anyhow::Result;
use felgens::{ws_socket_object, WsStreamMessageType};
use tokio::sync::mpsc::{self, UnboundedReceiver};

#[tokio::main]
async fn main() {
   let (tx, rx) = mpsc::unbounded_channel();

   // bilibili live room id (true id): 22746343

   let ws = ws_socket_object(tx, 22746343);

   if let Err(e) = tokio::select! {v = ws => v, v = recv(rx) => v} {
       eprintln!("{}", e);
   }
}

async fn recv(mut rx: UnboundedReceiver<WsStreamMessageType>) -> Result<()> {
   while let Some(msg) = rx.recv().await {
       println!("{:?}", msg);
   }

   Ok(())
}

Or run cargo run --example danmu

To-do!

  • 弹幕
  • SC
  • xxx 进了该房间
  • 礼物
  • 红包

Dependencies

~15–29MB
~606K SLoC