watson / airplay-protocol

A low level protocol wrapper on top of the AirPlay HTTP API
MIT License
106 stars 12 forks source link

device discovery #2

Closed jaruba closed 8 years ago

jaruba commented 8 years ago

This seems to be missing airplay device discovery, is this planned for the future? Or is there a recommended discovery module?

OstlerDev commented 8 years ago

Just ping every single computer on the network until you get a response ;)

jaruba commented 8 years ago

@OstlerDev giphy

watson commented 8 years ago

@jaruba it's outside the scope of this module to perform discovery. It's simply a protocol wrapper. Discovery should be added in more high level modules. I've already made one module on top of this called airplayer. Currently it only works as a command line tool, but I'm working on a big update to it which allows you to use it programmatically as well. I hope to release it today or tomorrow

jaruba commented 8 years ago

@watson I see.. so just:

var AirPlay = require('airplay-protocol')
var bonjour = require('bonjour')()
var browser = bonjour.find({ type: 'airplay' }, function (tv) {
  browser.stop()
  var airplay = AirPlay(tv.host, tv.port)
  airplay.play([whatever])
})
jaruba commented 8 years ago

Me and @OstlerDev tried the code above, and although it works fine with aTV 3, it doesn't work with aTV 4.

airplay-protocol

(the logged object is the bonjour response, error is from airplay-protocol)

While the aTV errors saying that it requires a newer version of itunes.

watson commented 8 years ago

@jaruba I've used the airplayer module to steam a video to aTV 4 without any issues. That module does exactly what you are suggesting. Are you sure you are responding with the correct data when the Apple TV tries to fetch the video?

jaruba commented 8 years ago

@watson what do you mean by:

Are you sure you are responding with the correct data when the Apple TV tries to fetch the video?

I'm transcoding to HLS, making sure that the audio and video is transcoded to something that all aTV's support, then simply doing:

var AirPlay = require('airplay-protocol')
var bonjour = require('bonjour')()
var browser = bonjour.find({ type: 'airplay' }, function (tv) {
  browser.stop()
  var airplay = AirPlay(tv.host, tv.port)
  airplay.play([my-link], [callback])
})

This works fine on aTV 3 but not aTV 4 (which gives a 403 Forbidden error). Does aTV 4 need anything else that aTV 3 doesn't?

watson commented 8 years ago

@jaruba There are two ways to send a video back to an Apple TV when it's requesting video data:

  1. Wrap it in HLS
  2. Send raw video data

I haven't looked that much into HLS since the raw video is a lot simpler as long as you don't need to convert the video on the fly.

Check out how I respond to requests from the Apple TV in the http server I use in the command line version of airplayer: https://github.com/watson/airplayer/blob/c0979d0d1b397fbe9ce1f66c82d1e30be1e6c324/bin.js#L40-L53

That works fine. You can try and install airplayer globally and give it a video file that's supported by the Apple TV v4 (e.g. mpeg4) and see how it streams it just fine.

jaruba commented 8 years ago

@watson I'm wrapping in HLS as I need to transcode on the fly. :))

watson commented 8 years ago

@jaruba Ah yes, then you need it of cause. Unfortunately I haven't worked much with that.

If I were you, I'd check out beamer and see if that app works with aTV 4. They serve the video using HLS. I would try and reverse-engineer what they are doing.

In any case, it should be an issue with the video server that the Apple TV connects to, not this module as it's just acting as a kind of "remote control" to the Apple TV.

I'm going to implement transcoding at some point my self, so I might get to this down the line, but I don't know when.

jaruba commented 8 years ago

Interesting, I wouldn't of thought that HLS was the issue.. the same transcoding parameters work fine with aTV 3 and Chromecast...

jaruba commented 8 years ago

And as far as I know, there haven't been any changes to the supported video / audio encodings in aTV 4, just the api changed (according to some articles), I'll give it a go with a non-HLS video that it should support out of the box and report back.

jaruba commented 8 years ago

I'm closing this as I think there might of been something wrong with ostlerdev's aTV 4, I bought an aTV 3 and aTV 4 y-day to test with. I initially tried to use your bonjour module for discovery as I was hoping to test casting with airplay-protocol, but bonjour never found any aTV, only found my own laptop.

I'm on Windows though so that might of influenced it somehow, I ended up using airplay-js like everyone else, and it worked fine with both aTV 3 and aTV 4.

Thanks for your help.