Struct rust_cast::CastDevice
[−]
[src]
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>>, // some fields omitted }
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 (eg. Chromecast).
Methods
impl<'a> CastDevice<'a>
[src]
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
let device = try!(CastDevice::connect(args.flag_address.unwrap(), args.flag_port));
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 (eg. wrong host name or port).
Return value
Instance of CastDevice
that allows you to manage connection.
fn receive(&self) -> Result<ChannelMessage, Error>
Waits for any message returned by cast device (eg. Chromecast) and returns its parsed version.
Examples
match cast_device.receive() { Ok(ChannelMessage::Connection(res)) => debug!("Connection message: {:?}", res), Ok(ChannelMessage::Heartbeat(_)) => cast_device.heartbeat.pong(), ....... Err(err) => error!("Error occurred while receiving message {}", err) }
Errors
Usually fails if message returned by device can't be parsed.
Returned values
Parsed channel message.