Struct rust_cast::CastDevice
source · pub struct CastDevice<'a> {
pub connection: ConnectionChannel<'a, SslStream<TcpStream>>,
pub heartbeat: HeartbeatChannel<'a, SslStream<TcpStream>>,
pub media: MediaChannel<'a, SslStream<TcpStream>>,
pub receiver: ReceiverChannel<'a, SslStream<TcpStream>>,
/* private fields */
}
Expand description
Structure that manages connection to a cast device.
Fields§
§connection: ConnectionChannel<'a, SslStream<TcpStream>>
Channel that manages connection responses/requests.
heartbeat: HeartbeatChannel<'a, SslStream<TcpStream>>
Channel that allows connection to stay alive (via ping-pong requests/responses).
media: MediaChannel<'a, SslStream<TcpStream>>
Channel that manages various media stuff.
receiver: ReceiverChannel<'a, SslStream<TcpStream>>
Channel that manages receiving platform (e.g. Chromecast).
Implementations§
source§impl<'a> CastDevice<'a>
impl<'a> CastDevice<'a>
sourcepub fn connect<S>(host: S, port: u16) -> Result<CastDevice<'a>, Error>where
S: Into<Cow<'a, str>>,
pub fn connect<S>(host: S, port: u16) -> Result<CastDevice<'a>, Error>where
S: Into<Cow<'a, str>>,
Connects to the cast device using host name and port.
Examples
use rust_cast::CastDevice;
let device = CastDevice::connect("192.168.1.2", 8009)?;
Arguments
host
- Cast device host name.port
- Cast device port number.
Errors
This method may fail if connection to Cast device can’t be established for some reason (e.g. wrong host name or port).
Return value
Instance of CastDevice
that allows you to manage connection.
sourcepub fn connect_without_host_verification<S>(
host: S,
port: u16
) -> Result<CastDevice<'a>, Error>where
S: Into<Cow<'a, str>>,
pub fn connect_without_host_verification<S>(
host: S,
port: u16
) -> Result<CastDevice<'a>, Error>where
S: Into<Cow<'a, str>>,
Connects to the cast device using host name and port without host verification. Use on your own risk!
Examples
use rust_cast::CastDevice;
let device = CastDevice::connect_without_host_verification("192.168.1.2", 8009)?;
Arguments
host
- Cast device host name.port
- Cast device port number.
Errors
This method may fail if connection to Cast device can’t be established for some reason (e.g. wrong host name or port).
Return value
Instance of CastDevice
that allows you to manage connection.
sourcepub fn receive(&self) -> Result<ChannelMessage, Error>
pub fn receive(&self) -> Result<ChannelMessage, Error>
Waits for any message returned by cast device (e.g. Chromecast) and returns its parsed version.
Examples
use rust_cast::ChannelMessage;
match cast_device.receive() {
Ok(ChannelMessage::Connection(res)) => log::debug!("Connection message: {:?}", res),
Ok(ChannelMessage::Heartbeat(_)) => cast_device.heartbeat.pong()?,
Ok(_) => {},
Err(err) => log::error!("Error occurred while receiving message {}", err)
}
Errors
Usually fails if message returned by device can’t be parsed.
Returned values
Parsed channel message.