Skip to content

Commit

Permalink
rtmp: README: use Rust formatting code block
Browse files Browse the repository at this point in the history
Also, no need to extra-indent the code.
  • Loading branch information
gdesmott committed May 15, 2023
1 parent e0a7ee0 commit fda0d59
Showing 1 changed file with 88 additions and 84 deletions.
172 changes: 88 additions & 84 deletions protocol/rtmp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,100 +10,104 @@ This is a simple rtmp library for easy use and reading, you can build your own s

## Single Server

use rtmp::channels::channels::ChannelsManager;
use rtmp::rtmp::RtmpServer;
```rust
use rtmp::channels::channels::ChannelsManager;
use rtmp::rtmp::RtmpServer;

#[tokio::main]
#[tokio::main]

async fn main() -> Result<()> {
async fn main() -> Result<()> {

let mut channel = ChannelsManager::new();
let producer = channel.get_session_event_producer();

let listen_port = 1935;
let address = format!("0.0.0.0:{port}", port = listen_port);

let mut rtmp_server = RtmpServer::new(address, producer.clone());
tokio::spawn(async move {
if let Err(err) = rtmp_server.run().await {
log::error!("rtmp server error: {}\n", err);
}
});

tokio::spawn(async move { channel.run().await });
let mut channel = ChannelsManager::new();
let producer = channel.get_session_event_producer();

let listen_port = 1935;
let address = format!("0.0.0.0:{port}", port = listen_port);

let mut rtmp_server = RtmpServer::new(address, producer.clone());
tokio::spawn(async move {
if let Err(err) = rtmp_server.run().await {
log::error!("rtmp server error: {}\n", err);
}
});

signal::ctrl_c().await?;
Ok(())
}
tokio::spawn(async move { channel.run().await });

signal::ctrl_c().await?;
Ok(())
}
```

## Cluster

use rtmp::channels::channels::ChannelsManager;
use rtmp::rtmp::RtmpServer;
use rtmp::relay::{pull_client::PullClient, push_client::PushClient},

#[tokio::main]

async fn main() -> Result<()> {

let mut channel = ChannelsManager::new();
let producer = channel.get_session_event_producer();
// push the rtmp stream from local to 192.168.0.2:1935
let address = format!(
"{ip}:{port}",
ip = "192.168.0.2",
port = 1935
);

let mut push_client = PushClient::new(
address,
channel.get_client_event_consumer(),
producer.clone(),
);
tokio::spawn(async move {
if let Err(err) = push_client.run().await {
log::error!("push client error {}\n", err);
}
});
channel.set_rtmp_push_enabled(true);

//pull the rtmp stream from 192.168.0.3:1935 to local
let address = format!(
"{ip}:{port}",
ip = "192.168.0.3",
port = pull_cfg_value.port
);
log::info!("start rtmp pull client from address: {}", address);
let mut pull_client = PullClient::new(
address,
channel.get_client_event_consumer(),
producer.clone(),
tokio::spawn(async move {
if let Err(err) = pull_client.run().await {
log::error!("pull client error {}\n", err);
}
});
channel.set_rtmp_pull_enabled(true);
```rust
use rtmp::channels::channels::ChannelsManager;
use rtmp::rtmp::RtmpServer;
use rtmp::relay::{pull_client::PullClient, push_client::PushClient},

#[tokio::main]

async fn main() -> Result<()> {

let mut channel = ChannelsManager::new();
let producer = channel.get_session_event_producer();

// the local rtmp server
let listen_port = 1935;
let address = format!("0.0.0.0:{port}", port = listen_port);

let mut rtmp_server = RtmpServer::new(address, producer.clone());
tokio::spawn(async move {
if let Err(err) = rtmp_server.run().await {
log::error!("rtmp server error: {}\n", err);
}
});
// push the rtmp stream from local to 192.168.0.2:1935
let address = format!(
"{ip}:{port}",
ip = "192.168.0.2",
port = 1935
);

let mut push_client = PushClient::new(
address,
channel.get_client_event_consumer(),
producer.clone(),
);
tokio::spawn(async move {
if let Err(err) = push_client.run().await {
log::error!("push client error {}\n", err);
}
});
channel.set_rtmp_push_enabled(true);

//pull the rtmp stream from 192.168.0.3:1935 to local
let address = format!(
"{ip}:{port}",
ip = "192.168.0.3",
port = pull_cfg_value.port
);
log::info!("start rtmp pull client from address: {}", address);
let mut pull_client = PullClient::new(
address,
channel.get_client_event_consumer(),
producer.clone(),

tokio::spawn(async move { channel.run().await });

signal::ctrl_c().await?;
Ok(())
}
tokio::spawn(async move {
if let Err(err) = pull_client.run().await {
log::error!("pull client error {}\n", err);
}
});
channel.set_rtmp_pull_enabled(true);


// the local rtmp server
let listen_port = 1935;
let address = format!("0.0.0.0:{port}", port = listen_port);

let mut rtmp_server = RtmpServer::new(address, producer.clone());
tokio::spawn(async move {
if let Err(err) = rtmp_server.run().await {
log::error!("rtmp server error: {}\n", err);
}
});

tokio::spawn(async move { channel.run().await });

signal::ctrl_c().await?;
Ok(())
}
```

For more detailed implementation please reference to [xiu server](https://github.com/harlanc/xiu/blob/master/application/xiu/src/main.rs)

Expand Down

0 comments on commit fda0d59

Please sign in to comment.