Giter VIP home page Giter VIP logo

chromecasts's Introduction

chromecasts

Query your local network for Chromecasts and have them play media

npm install chromecasts --save

Usage

const chromecasts = require('chromecasts')()

chromecasts.on('update', players => {
  console.log('all players: ', players)
  player.play('http://example.com/my-video.mp4', {title: 'my video', type: 'video/mp4'})
})

API

var list = chromecasts()

Creates a chromecast list. When creating a new list it will call list.update() once. It is up to you to call afterwards incase you want to update the list.

list.update()

Updates the player list by querying the local network for chromecast instances.

list.on('update', player)

Emitted when a new player is found on the local network

player.play(url, [opts], cb)

Make the player play a url. Options include:

{
  title: 'My movie',
  type: 'video/mp4',
  seek: seconds, // start by seeking to this offset
  subtitles: ['http://example.com/sub.vtt'], // subtitle track 1,
  autoSubtitles: true // enable first track if you provide subs
}

player.subtitles(track, [cb])

Enable subtitle track. Use player.subtitles(false) to disable subtitles

player.pause([cb])

Make the player pause playback

player.resume([cb])

Resume playback

player.stop([cb])

Stop the playback

player.seek(seconds, [cb])

Seek the video

player.status(cb)

Get a status object of the current played video.

player.on('status', status)

Emitted when a status object is received.

License

MIT

chromecasts's People

Contributors

alxhotel avatar amilajack avatar andyshinn avatar beaugunderson avatar catdad avatar davidyen1124 avatar feross avatar ivshti avatar linusu avatar mafintosh avatar

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  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

chromecasts's Issues

player.status always get undefined

I can't get the player.status method working : I always get undefined

This is the code I use :

chromecasts.update() chromecasts.on('update', function (player) { console.log('player on : ', player) setTimeout(function() { player.status(function (err,data) { if (err) return console.error(err); console.log('status=',data); }) }, 1000) player.on('status', function (status) { console.log('status of player : ', status) }) })

can you help me ?

Adding a "reload" function

I have a use case where I need to change the subtitle at runtime. The chromecast SDK has a "reload" function that you can call after making changes to audio or subtitles tracks and it will restart the player by keeping the timestamp. Unfortunately, chromecasts doesn't expose this function so we have to do workarounds like saving the timestamp, stopping the player and starting it again. The experience obviously doesn't feel as seamless and the whole process takes more time to complete.

Would adding a reload function to chromecasts be a good idea? I would gladly make a PR, but I wasn't sure if that's something that you guys want or if people are still working on this project (the last commit was made 6 months ago).

TypeError: cannot read property mediaSessionId of null

Running this code:

var chromecasts = require('chromecasts')()

var file_url = 'http://......';

chromecasts.on('update', function (player) {
  console.log('all players: ', chromecasts.players)
  player.play(file_url, {title: 'my video', type: 'video/mp4'})
  // pause if after 5 seconds.
  setTimeout(function(){player.pause();}, 5000);
})

Raises a TypeError:

/node_modules/castv2-client/lib/controllers/media.js:88
  data.mediaSessionId = this.currentSession.mediaSessionId;
                                           ^

TypeError: Cannot read property 'mediaSessionId' of null

Getting error messages back from chromecast

Currently, is it possible to listen to error messages? I've got a weird issue where when I pass a (valid) link to a vtt file in the subtitles array, playback won't start - it gives me the loading screen and then gets back to idle mode.

Disabling that vtt fixes the issue. I tried with several links to a different vtt file.

Error on start

In my Manjaro Linux Deepin operative system I have done:

git clone https://github.com/mafintosh/chromecasts.git
cd chromecasts/
npm install
create a chromecast.js file with the content of the Usage file in your GitHub README.md
node chromecast.js

The TV with the Google Chromecast is turned on, and this is the (error) output that chromecast.js gives me

internal/modules/cjs/loader.js:638
    throw err;
    ^

Error: Cannot find module 'chromecasts'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/home/daniel/chromecasts/chromecasts.js:3:19)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)

Remove native dependency

Is there anything we can do to remove the native dependency when installing chromecasts?

> [email protected] install /Users/feross/code/webtorrent/node_modules/chromecasts/node_modules/node-ssdp/node_modules/bunyan/node_modules/dtrace-provider
> node scripts/install.js

Looks like it comes from node-ssdp depending on bunyan.

No MDNS being sent.

Hello @mafintosh

Foremostly, thank you for all your work regarding streaming & peer-peer work. I use a lot of your modules.

When attempting to get a list of players, .update() never dispatches an mDNS query and when rebooting the Chromecast the published mDNS messages are not received by 'chromecasts'.

var casts = require('chromecasts')();
casts.on('update', function(player) { console.log('Update', player); });
// Force an update to attempt to see the message in Wireshark
casts.update();
// Wait an ample amount of time.
setTimeout(function() {
  console.log('Players:', casts.players);
}, 10000);

The update is never fired and the players is an empty array. I can communicate with my Chromecast just fine with Chrome Browser or Android. Wireshark shows Chromecast pushing replies when queried by other devices but Node.JS never dispatches a query and doesn't seem to receive any passive messages from the Chromecast when the device is booted.

Node: v0.12.2
NPM: v2.7.4
Chromecasts: 1.4.0 @650768ffd6
OS: Windows 8.1.1 (x64)

I've tested running as User and Administrator to no avail. I do not see an mDNS query published when calling update.

stream won t start

hi

when i try to load a local stream on my tv (a peerflix stream for exemple) the player start on the tv, i have a grey screen with a sort of (i think) progress from top to bottom but very slow then the cast stop after like 10 -15 seconds.. why is it so slow to load and is there a timeout or something like that ?

thanks

parsing multicast-dns responses results in unreachable device

When I use this module, I get an ETIMEDOUT error connecting to a strange IP address 198.105.244.228. The real IP of my chromecast on my network, however, is 192.168.1.105. I did a bit of investigation and found that the host which is parsed from the multicast-dns results is 072d136d-9716-69e2-2758-36bf56482f43.local, and when I do a dns.lookup() on it, sure enough, it resolves to that strange IP address.

Looking a bit further, I saw what appears to be the issue in the multicast-dns responses. On my network, the answers and additionals that I get are these:

answers: [
  {
    "name": "_googlezone._tcp.local",
    "type": "PTR",
    "class": 1,
    "ttl": 120,
    "flush": false,
    "data": "3e0de4d2-1dc6-b2b9-e93d-d3eadf2a301a._googlezone._tcp.local"
  }
]


additionals: [
  {
    "name": "Chromecast-072d136d971669e2275836bf56482f43._googlecast._tcp.local",
    "type": "TXT",
    "class": 1,
    "ttl": 4500,
    "flush": true,
    "data": {
      "type": "Buffer",
      "data": [
        35,
        61
      ]
    }
  },
  {
    "name": "Chromecast-072d136d971669e2275836bf56482f43._googlecast._tcp.local",
    "type": "SRV",
    "class": 1,
    "ttl": 120,
    "flush": true,
    "data": {
      "priority": 0,
      "weight": 0,
      "port": 8009,
      "target": "072d136d-9716-69e2-2758-36bf56482f43.local"
    }
  },
  {
    "name": "072d136d-9716-69e2-2758-36bf56482f43.local",
    "type": "A",
    "class": 1,
    "ttl": 120,
    "flush": true,
    "data": "192.168.1.105"
  }
]

Looks like there is an A type additional that has the correct IP address. However, this additional is never even looked at. The SRV additional which is used has data.target strange address which resolves to the strange IP.

When I overload the player.host with the correct IP, the module works well and can cast media. However, since the A additional uses different name than the one in the rest of the additionals (and the one used to store cast devices), I am not totally sure how to fix it, since I don't know what other dns responses look like (since I assume this works well on other people's networks).

mDNS discovery not working (PTR vs. A record "name" property mismatch)

The PTR record name property looks like this:
Chromecast-1930a236896105d6f9026ddc5e85e3a8._googlecast._tcp.local

And the A record name property looks like this:
1930a236-8961-05d6-f902-6ddc5e85e3a8.local

After the replace done in the code, we end up with:
PTR: Chromecast-1930a236896105d6f9026ddc5e85e3a8
A: 1930a236-8961-05d6-f902-6ddc5e85e3a8

To emit() a device, there is a condition that fails is the 2 above string are not the same.

When testing with a Chromecast 2nd gen, well, they are never the same.

I'm wondering if this issue is specific to:

  • my Chromecast (that would be weird, and mean)
  • a group of Chromecasts 2nd generation, or all Chromecasts 2nd generation
  • a recent Chromecast firmware update (either affecting a specific generation, or all generations)
  • Chromecasts only, or other Cast-compatible devices (Android TV, etc.)

Thoughts?

Note: It would help if anyone with a Cast-enabled device could check their mDNS response, see if they see the same thing.

(@feross, you said in another issue that you have a Chromecast Audio).

Express.js not receiving player requests

I will definitely not claim to understand how this all works, but here is a few ways i tried it.

I have two routes.

/server-video/:id
-> This one streams buffers to my HTML5 video player. This works really well for my Video Tag! So far everything besides the Chromecast aspect of this is fantastic! I thought i would have to send this buffer stream to the Chromecast.

and

/download-video/:id
-> This is a straight out download res.

router.get('/download-video/:id', function(req, res, next){
	var file = PATH +'/public/videos/test.mp4';
	console.log(file);
  	res.sendFile(file); // Set disposition and send it.res.download()
}); 

This works great when i just go to my browser and hit that URL. However, when i fire off this call.

var options = { title: movie_name, type: 'video/mp4' };

chromecasts.players[list['The Highway TV']].play("http://localhost:3000/video-play/"+req.params.id, options);
chromecasts.players[list['The Highway TV']].play("http://localhost:3000/download-video/"+req.params.id, options);

This causes my chromecast called "The Highway TV" (I made a mapping for the names to Indexes) flicker with the proper title...but i never actually receive a request of any type to my express instance. I was hoping to dig a bit more, but i can't seem to find anything which points to why that request wouldn't be making it through.

Any ideas? I am hoping to use this repo with my repo! So far, this is the best one i have found (It actually allowed me to see my chromecasts. So that was huge by itself!)

Keee player and chromecast almost synced

Hi everyone,
I have a player playing a video. I push a button and the video is sent to chromecast, with actual time so it starts the video at the same time (the player is still playing it). Chromecast get some seconds to start and in the meanwhile video on the player continues to play. So when both are playing there is a big difference in time of what player and chromecast are playing.
E.g. player is at 1:10 and Chromecast is at 1:00. I'd like to reduce this gap.
What I was thinking to do is.
When I push the button i send the video to chromecast and pause the video on the player.
When chromecast really starts playing the video I restart it also on the player... so player and chromecast are almost synced.

But I cannot find a way to understand when chromecast starts playing. I tried to get the chromecast status but I cannot. Maybe related to #22, But I'm not getting undefined.
The command I use is chromecasts.players[0].status() (player[0] is the chromecast I'm using)
I'm getting this error:

Uncaught TypeError: callback is not a function at C:\Users\ivan\Desktop\Myapp\chromecast\node_modules\castv2-client\lib\controllers\media.js:41 at fn.onmessage (C:\Users\ivan\Desktop\Myapp\chromecast\node_modules\castv2-client\lib\controllers\request-re…:27) at emitTwo (events.js:130) at fn.emit (events.js:213) at Channel.onmessage (C:\Users\ivan\Desktop\Myapp\chromecast\node_modules\castv2-client\lib\controllers\controller…:16) at emitTwo (events.js:125) at Channel.emit (events.js:213) at Client.onmessage (C:\Users\ivan\Desktop\Myapp\chromecast\node_modules\castv2\lib\channel.js:23) at emitMany (events.js:151) at Client.emit (events.js:223)

Any idea about this error? Or any other way to solve my sync "issue"?
Thank you!

Different Google Cast devices

Right now it seems that this library will show all Google Cast devices that have device.manufacturer = "Google Inc.".

As far as I know, the only way to know at discovery time if a Google Cast-compatible device (including Google's own devices) is audio-only is by matching the device.manufacturer and/or device. modelName to a list (I've pasted below the SSDP response for Google Home that is audio-only).

I'm also wondering if all Google Cast compatible devices (ex: NVIDIA Shield, Sony Bravia, etc.) will answer with device.manufacturer = "Google Inc." (I'm assuming they don't).

It would be great if this library could also returns device.modelName as a property, and potentially add an option to not filter Google Inc. as manufacturer and returns device.manufacturer as well so anyone with a more advanced use-case (and time on its hand) could offer a better experience.

Something that could be cool would be a property audioOnly that is true if we're sure it's an audio-only device, otherwise false (and a comprehensive list could be maintained in the lib, starting with the obvious Chromecast Audio and Google Home).

While I'm not sure I'm the right person for a PR, I'm definitely open to report back on any manufacturer/modelName I encounter in the wild. Maybe the folks at webtorrent-desktop knows more about this (@feross, @dcposch).

I've also find this if it helps:


{
   "$":{
      "xmlns":"urn:schemas-upnp-org:device-1-0"
   },
   "specVersion":{
      "major":"1",
      "minor":"0"
   },
   "URLBase":"http://10.0.0.37:8008",
   "device":{
      "deviceType":"urn:dial-multiscreen-org:device:dial:1",
      "friendlyName":"Living Room",
      "manufacturer":"Google Inc.",
      "modelName":"Google Home",
      "UDN":"uuid:fee5c0d9-7475-b74a-1a14-xxx",
      "iconList":{
         "icon":{
            "mimetype":"image/png",
            "width":"98",
            "height":"55",
            "depth":"32",
            "url":"/setup/icon.png"
         }
      },
      "serviceList":{
         "service":{
            "serviceType":"urn:dial-multiscreen-org:service:dial:1",
            "serviceId":"urn:dial-multiscreen-org:serviceId:dial",
            "controlURL":"/ssdp/notfound",
            "eventSubURL":"/ssdp/notfound"
         }
      }
   }
}

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.