Crates.io | srs-client |
lib.rs | srs-client |
version | 0.2.0 |
source | src |
created_at | 2024-07-20 22:34:06.540659 |
updated_at | 2024-07-20 22:34:06.540659 |
description | Provides bindings for the main functionalities of the SRS |
homepage | |
repository | https://github.com/InnovateAndBuild/srs-client |
max_upload_size | |
id | 1309940 |
size | 40,473 |
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:
In this mode, srs-client uses HTTP to communicate with the server based on the SRS HTTP API specification.
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(())
}
In this mode, srs-client provides structs to handle callbacks sent by SRS.
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")
}
HTTP Client Mode:
HTTP Callback Mode:
Full API Reference is available here.
Add this to your Cargo.toml
:
[dependencies]
srs-client = "0.1.0"
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.