Skip to content

eirenik0/srs-client

Repository files navigation

SRS Client

srs-client v0.2.1 (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.

For maintainers releasing new versions, see RELEASE.md for detailed release instructions.

License

This project is licensed under the MIT License.

About

Provides bindings for the main functionalities of the SRS

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published