Code Monkey home page Code Monkey logo

rust-cast's Introduction

Docs Build Status

Usage

Build

Proto files are taken from Chromium Open Screen GitHub mirror.

By default cargo build won't try to generate Rust code from the files located at protobuf/*, if you want to do that use GENERATE_PROTO environment variable during build and make sure you have protoc binary in $PATH:

$ GENERATE_PROTO=true cargo build

Run example

Generic features

First, you need to figure out the address of the device to connect to. For example, you can use avahi with the following command:

$ avahi-browse -a --resolve
// Get some info about the Google Cast enabled device (e.g. Chromecast). 
$ cargo run --example rust_caster -- -a 192.168.0.100 -i

Number of apps run: 1
App#0: Default Media Receiver (CC1AD845)
Volume level: 1
Muted: false

// Run specific app on the Chromecast.
$ cargo run --example rust_caster -- -a 192.168.0.100 -r youtube

// Stop specific active app.
$ cargo run --example rust_caster -- -a 192.168.0.100 -s youtube

// Stop currently active app.
$ cargo run --example rust_caster -- -a 192.168.0.100 --stop-current

The following app has been stopped: Default Media Receiver (CC1AD845)

Media features

// Stream a video.
$ cargo run --example rust_caster -- -a 192.168.0.100 -m http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4

// Stream a video of specific format with buffering.
$ cargo run --example rust_caster -- -a 192.168.0.100 -m http://xxx.webm --media-type video/webm --media-stream-type buffered

// Stream video from YouTube (doesn't work with the latest YouTube app, fix is welcome).
$ cargo run --example rust_caster -- -a 192.168.0.100 -m 7LcUOEP7Brc --media-app youtube

// Display an image.
$ cargo run --example rust_caster -- -a 192.168.0.100 -m https://azasypkin.github.io/style-my-image/images/mozilla.jpg

// Change volume level.
$ cargo run --example rust_caster -- -a 192.168.0.100 --media-volume 0.5

// Mute/unmute media.
$ cargo run --example rust_caster -- -a 192.168.0.100 --media-mute [--media-unmute]

// Pause media.
$ cargo run --example rust_caster -- -a 192.168.0.100 --media-app youtube --media-pause

// Resume/play media.
$ cargo run --example rust_caster -- -a 192.168.0.100 --media-app youtube --media-play

// Seek media.
$ cargo run --example rust_caster -- -a 192.168.0.100 --media-app youtube --media-seek 100

For all possible values of --media-type see Supported Media for Google Cast.

DNS TXT Record description

  • md - Model Name (e.g. "Chromecast");
  • id - UUID without hyphens of the particular device (e.g. xx12x3x456xx789xx01xx234x56789x0);
  • fn - Friendly Name of the device (e.g. "Living Room");
  • rs - Unknown (recent share???) (e.g. "Youtube TV");
  • bs - Uknonwn (e.g. "XX1XXX2X3456");
  • st - Unknown (e.g. "1");
  • ca - Unknown (e.g. "1234");
  • ic - Icon path (e.g. "/setup/icon.png");
  • ve - Version (e.g. "04").

Model names

  • Chromecast - Regular chromecast, supports video/audio;
  • Chromecast Audio - Chromecast Audio device, supports only audio.

Useful links and sources of inspiration

rust-cast's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

rust-cast's Issues

Derive Copy and Clone for StatusEntry

I'm pretty new to Rust, but I think the StatusEntry and others could derive the Copy and Clone too so one could make helpers.

E.g. I've made a helper defined like this:

pub trait BaseMediaReceiver {
    fn play(&self);
    fn pause(&self);
    fn stop(&self);
    fn cast(&self, url: &str);
    fn get_current_time(&self) -> Option<f32>;
    // fn get_status(&self) -> Option<StatusEntry>;
}

But I can't implement the get_status because the StatusEntry is not copyable. Maybe I'm not yet understanding the Rust perfectly. However I keep getting type &StatusEntry from a status.entries.first().unwrap() call and I can't convert it back to StatusEntry because it's not copyable.

Thanks, great library! I've used JavaScript libraries for chromecast before, but boy I don't like those.

async support

Hi,

I am interested in an async module that communicates with my Chromecast as part of a web application.

Would you open to collaborating on this? Alternatively I can make an async version and link back to this repo as the source of much of the work.

Allow setting the `current_time` field within the load command

Hi

I have a use-case in which I want to auto resume a media item from a certain position when loading a media item within the default media receiver of Chromecast.
The current implementation of the load function hard codes the current_time command field to always be 0 (see media.rs#L578).

So if it would be possible that we can get an option to configure this command field, it would be much appreciated.

Doc references: https://developers.google.com/cast/docs/media/messages#Load

Failing to deserialize status messages

Hi,

both my Cast devices started to return MEDIA_STATUS messages which fail to parse with rust-cast. This breaks both my own app, but also your rust-caster example.

I noticed that the "supportedmediaCommands" field in StatusEntry is set to 247772, which clearly wont fit into u8.

Going through the ChromeCast developer documentation I don't see anything that describes what those upper bits are for, the doc only talks about those low 6 bits you already covered...

DEBUG 2018-10-14T08:59:38Z: rust_cast::message_manager: Message received: 
    CastMessage { 
        protocol_version: Some(CASTV2_1_0), 
        source_id: Some("1389b262-07d0-4354-bb20-1e42155b67ef"), 
        destination_id: Some("*"), 
        namespace: Some("urn:x-cast:com.google.cast.media"), 
        payload_type: Some(STRING), 
        payload_utf8: Some("
            {
                \"type\":\"MEDIA_STATUS\",
                \"status\":[{
                    \"mediaSessionId\":1,
                    \"playbackRate\":1,
                    \"playerState\":\"IDLE\",
                    \"currentTime\":0,
                    \"supportedMediaCommands\":274447,          // 0b1000011000000001111
                    \"volume\":{
                        \"level\":1,
                        \"muted\":false},
                    \"media\":{
                        \"contentId\": \"http://192.168.1.42:8000/Test.mp4\",
                        \"streamType\":\"NONE\",
                        \"contentType\":\"\"
                    },
                    \"currentItemId\":1,
                    \"extendedStatus\":{
                        \"playerState\":\"LOADING\",\
                        "media\":{
                            \"contentId\":\"http://192.168.1.42:8000/Test.mp4\",
                            \"streamType\":\"NONE\",
                            \"contentType\":\"\"
                        }
                    },
                    \"repeatMode\":\"REPEAT_OFF\"
                }],
                \"requestId\":0
            }"),
        payload_binary: None, 
        unknown_fields: UnknownFields { 
            fields: None 
        }, 
        cached_size: CachedSize { 
            size: 0 
        } 
}

Stream a local .mp4 file?

-m, --media <media_handle> Media handle (URL for image or video, URL token for youtube video etc.) to load on the Cast connected device.

seems to not support local files?

Consider removing the use of Cow

By using Cow, you need to specify lifetimes on the CastDevice struct. It means I need to specify lifetimes everywhere I use a CastDevice. It's possibile, but it's a bit of an hassle.
Is Cow really needed?

Device discovery?

Hi,

Unless I’m mistaken, there currently isn’t any code to discover new Chromecast devices, and the only way to use them is to know the IP address beforehand having discovered it by some other means. Would you consider implementing that or including some examples of performing discovery by other means (I’ve no idea at the moment how to do zeroconf discovery in Rust)?

use of Rc limiting design possibility

The heavy use of Rc types means I can't construct a CastDevice on one thread and then move or clone it over to another thread (or thread pool) that my proxy server will be running on.

It's pretty common for networked clients to be thread-safe.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.