pub struct AsyncRtmpClient<S = TcpStream> { /* private fields */ }tokio only.Expand description
A publishing RTMP client over a stream (a TcpStream by default): the
adapter for ClientSession, mirroring
RtmpConnection. Every awaited IO is bounded by the config’s Timeouts.
Implementations§
Source§impl AsyncRtmpClient<TcpStream>
impl AsyncRtmpClient<TcpStream>
Sourcepub async fn connect(config: RtmpClientConfig) -> Result<Self>
pub async fn connect(config: RtmpClientConfig) -> Result<Self>
DNS + TCP connect bounded by the config’s timeouts.connect; publish
is NOT started.
An rtmps target is refused: this adapter opens plain TCP, and sending
RTMP in the clear to a TLS port (443) would leak the stream key. Wrap a
TLS stream and use AsyncRtmpClient::from_stream instead.
Source§impl<S: AsyncRead + AsyncWrite + Unpin> AsyncRtmpClient<S>
impl<S: AsyncRead + AsyncWrite + Unpin> AsyncRtmpClient<S>
Sourcepub fn from_stream(stream: S, config: RtmpClientConfig) -> Self
pub fn from_stream(stream: S, config: RtmpClientConfig) -> Self
Wraps an already-connected stream (e.g. a TLS one, for an rtmps
target); the handshake bytes are queued and go out with the first call
that flushes.
Sourcepub async fn publish(&mut self) -> Result<()>
pub async fn publish(&mut self) -> Result<()>
Runs handshake -> connect -> createStream -> publish; returns once the
server accepted the publish. Bounded by Timeouts::handshake as a
whole. A server error (ClientEvent::Error) is
io::ErrorKind::ConnectionRefused.
Sourcepub async fn send_audio(
&mut self,
timestamp: Timestamp,
data: &[u8],
) -> Result<()>
pub async fn send_audio( &mut self, timestamp: Timestamp, data: &[u8], ) -> Result<()>
Sends one audio message (FLV audio tag body) at timestamp, carried on
the wire as whole milliseconds.
The adapter reads inbound traffic (server acks, pings, errors) only inside
next_events; a caller that only sends must also drive
next_events (e.g. in a select!) or the server’s acknowledgement window
is never serviced.
Sourcepub async fn send_video(
&mut self,
timestamp: Timestamp,
data: &[u8],
) -> Result<()>
pub async fn send_video( &mut self, timestamp: Timestamp, data: &[u8], ) -> Result<()>
Sends one video message (FLV video tag body) at timestamp, carried on
the wire as whole milliseconds.
Sourcepub async fn send_metadata(
&mut self,
metadata: &[(String, Amf0Value)],
) -> Result<()>
pub async fn send_metadata( &mut self, metadata: &[(String, Amf0Value)], ) -> Result<()>
Sends @setDataFrame/onMetaData stream metadata.
Sourcepub fn encode_audio(
&mut self,
timestamp: Timestamp,
data: &[u8],
) -> Result<Vec<u8>>
pub fn encode_audio( &mut self, timestamp: Timestamp, data: &[u8], ) -> Result<Vec<u8>>
Sans-IO half of send_audio: the chunk-stream-framed
message bytes for one audio tag, without writing. Lets a caller
driving its own egress (e.g. multimux’s PushTransportEgress) frame a
message now and write it verbatim later via
write_frame.
Sourcepub fn encode_video(
&mut self,
timestamp: Timestamp,
data: &[u8],
) -> Result<Vec<u8>>
pub fn encode_video( &mut self, timestamp: Timestamp, data: &[u8], ) -> Result<Vec<u8>>
Sans-IO half of send_video — see
encode_audio.
Sourcepub fn encode_metadata(
&mut self,
metadata: &[(String, Amf0Value)],
) -> Result<Vec<u8>>
pub fn encode_metadata( &mut self, metadata: &[(String, Amf0Value)], ) -> Result<Vec<u8>>
Sans-IO half of send_metadata — see
encode_audio.
Sourcepub fn encode_publish_message(
&mut self,
message: &PublishMessage,
) -> Result<Vec<u8>>
pub fn encode_publish_message( &mut self, message: &PublishMessage, ) -> Result<Vec<u8>>
Sans-IO half of sending one message of a
publish_open plan — see
encode_audio.
Sourcepub async fn write_frame(&mut self, bytes: Vec<u8>) -> Result<()>
pub async fn write_frame(&mut self, bytes: Vec<u8>) -> Result<()>
Writes one already-framed message verbatim (the async half of the
encode_* methods above), bounded by Timeouts::write.
Sourcepub async fn next_events(&mut self) -> Result<Option<Vec<ClientEvent>>>
pub async fn next_events(&mut self) -> Result<Option<Vec<ClientEvent>>>
Next batch of server events (acks, errors, close); Ok(None) at EOF.
Same deadline rules and cancel-safety as RtmpConnection::next_events.