#callback #client #srs #api-client #server-client #api

srs-client

Provides bindings for the main functionalities of the SRS

1 unstable release

0.2.0 Jul 20, 2024

#386 in HTTP client

Download history 45/week @ 2024-07-14 112/week @ 2024-07-21 13/week @ 2024-07-28 1/week @ 2024-09-08 6/week @ 2024-09-15 46/week @ 2024-09-22 22/week @ 2024-09-29 2/week @ 2024-10-06

76 downloads per month

Custom license

25KB
467 lines

SRS Client

srs-client v0.2.0 (changelog)

The SRS (Simple RTMP Server) Rust Client or srs-client is a Rust package that provides bindings for the main functionalities of the SRS server. It supports two modes of operation:

  1. As an HTTP client to interact with the SRS HTTP API
  2. For handling SRS HTTP callbacks

HTTP Client Mode

In this mode, srs-client uses HTTP to communicate with the server based on the SRS HTTP API specification.

Usage

To use srs-client as an HTTP client:

use srs_client::{SrsClient, SrsClientError, SrsClientResp};
use std::env;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let srs_http_api_url = env::var("SRS_HTTP_API_URL").expect("SRS_HTTP_API_URL not set");
    let client = SrsClient::build(&srs_http_api_url)?;
    
    // Get SRS version
    let result: Result<SrsClientResp, SrsClientError> = client.get_version().await;
    println!("SRS version: {:?}", result);

    // Get streams
    let result: Result<SrsClientResp, SrsClientError> = client.get_streams().await;
    println!("Streams: {:?}", result);

    Ok(())
}

HTTP Callback Mode

In this mode, srs-client provides structs to handle callbacks sent by SRS.

Usage

To handle SRS callbacks:

use actix_web::{post, web};
use srs_client::{SrsCallbackEvent, SrsCallbackReq};

#[post("srs_callback")]
pub async fn on_callback(req: web::Json<SrsCallbackReq>) -> Result<&'static str, String> {
    match req.action {
        SrsCallbackEvent::OnConnect => {
            // Handle connection event
            dbg!(&req);
            Ok(())
        }
        _ => Ok(()),
    }
    .map(|()| "0")
}

Features

  • HTTP Client Mode:

    • Retrieve server information (version, vhosts, streams, clients)
    • Monitor system stats (rusages, self_proc_stats, system_proc_stats, meminfos)
    • Manage clients (kickoff)
  • HTTP Callback Mode:

    • Handle various SRS events (OnConnect, OnPublish, etc.)

Full API Reference is available here.

Installation

Add this to your Cargo.toml:

[dependencies]
srs-client = "0.1.0"

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

Dependencies

~4–15MB
~224K SLoC