GithubHelp home page GithubHelp logo

node-airplay's Introduction

node-airplay -- AirPlay client library for node.js

node-airplay is a client library for Apple's AirPlay remote playback protocol. It implements a simple AirPlay device browser using mdns and command interface.

Currently supported features:

  • AirPlay device discovery
  • Support for audio and video playback

Coming soon (maybe):

  • Photo playback
  • Robust error handling
  • Better device information formatting (supported features/etc)

Quickstart

npm install airplay
node
> var browser = require('airplay').createBrowser();
> browser.on('deviceOnline', function(device) {
    device.play('http://host/somevideo.mp4', 0);
  });
> browser.start();

Installation

With npm:

npm install airplay

From source:

cd ~
git clone https://[email protected]/benvanik/node-airplay.git
npm link node-airplay/

node-airplay depends on both node-plist and node_mdns. Unfortunately node_mdns is woefully out of date and has required many tweaks to get working, resulting in a fork.

If you're running node on FreeBSD (or maybe Linux) you may get errors during install about a missing dns_sd.h file. If so, install the Apple mDNS SDK:

wget http://www.opensource.apple.com/tarballs/mDNSResponder/mDNSResponder-522.1.11.tar.gz
tar zxvf mDNSResponder-522.11.tar.gz
cd mDNSResponder-333.10/mDNSPosix/
sudo gmake os=freebsd install

API

Browser

The browser is a discovery service that can be run to automatically detect the AirPlay-compatiable devices on the local network(s). Try only to create one browser per node instance, and if it's no longer needed stop it.

Create a browser using the createBrowser method:

var browser = require('airplay').createBrowser();

Attach to the browser events to track device discovery:

browser.on('deviceOnline', function(device) {
  console.log('device online: ' + device.id);
});
browser.on('deviceOffline', function(device) {
  console.log('device offline: ' + device.id);
});

Start or stop the discovery process:

browser.start();
browser.stop();

If you are running a server you can use the built-in device list instead of maintaining your own via the events:

function myHandler() {
  var devices = browser.getDevices();
  console.log(devices);
}

Device

A device instance represents a single AirPlay device on the local network. Devices are created either through the discovery process or by direct connection. Each device has only a single control channel, and all methods are asynchronous.

Obtain devices using the browser API:

// Get all ready devices
var allDevices = browser.getDevices();
// Grab a device to play with
var device = allDevices[0];

TODO At some point, you'll be able to connect directly:

var device = require('airplay').connect(deviceHost);
device.on('ready', function() {
  // Ready to accept commands
});

If you are done with the device, close the connection (note that this will stop any playback):

device.close();

Issue various device control calls. All calls are asynchronous and have an optional callback that provides the result - for most, it's an empty object if the call was successful and null if the call failed.

// Get the current playback status
device.getStatus(function(res) {
  // res = {
  //   duration: number, -- in seconds
  //   position: number, -- in seconds
  //   rate: number, -- 0 = paused, 1 = playing
  //   ...
  // }
  // or, if nothing is playing, res = {}
});

// Play the given content (audio/video/etc)
var content = 'http://host/content.mp4';
var startPosition = 0; // in seconds
device.play(content, startPosition, function(res) {
  if (res) {
    // playing
  } else {
    // failed to start playback
  }
});

// Stop playback and return to the main menu
device.stop();

// Seek to the given offset in the media (if seek is supported)
var position = 500; // in seconds
device.scrub(position);

// Reverse playback direction (rewind)
// NOTE: may not be supported
device.reverse();

// Change the playback rate
// NOTE: only 0 and 1 seem to be supported for most media types
var rate = 0; // 0 = pause, 1 = resume
device.rate(rate);

// Adjust playback volume
// NOTE: may not be supported
device.volume(value);

node-airplay's People

Contributors

benvanik avatar cadesalaberry avatar chalkers 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

node-airplay's Issues

dns problem

hi

just tried ytour node module

error:

"Uncaught Error: /tmp/.org.chromium.Chromium.0EEQU7/node_modules/airplay/node_modules/mdns/build/Release/dns_sd_bindings.node: undefined symbol: _ZN2v816FunctionTemplate3NewEPFNS_6HandleINS_5ValueEEERKNS_9ArgumentsEES3_NS1_INS_9SignatureEEE", source: /tmp/.org.chromium.Chromium.0EEQU7/node_modules/airplay/node_modules/mdns/lib/dns_sd.js (35)

thx

++

Error: This socket has been ended by the other party.

step:

  1. play a video and wait for play-end.
  2. play another video, then error occurred.

And we could found "device.client_.socket_.destroyed" is "true". socket connection has lost but we seems not be informed and has no method to reconnect it.

If someone could provide

  1. lost connection notify.
  2. a method to sockets reconnect will be good.

Thanks.

no browsing

I get this error:

var b = require('airplay').createBrowser();
undefined
console.log(b.getDevices());
[]
undefined
b.start();
undefined

events.js:72
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer as oncomplete

I have both an airport Express and an AppleTV, so something should be there. I also tried node_airtunes, which only gave me "tick" in the speakers. For that to work, I needed the IP address for the airport express. Is there a way to test airtunes with an IP address?

Passwords

Seems like password support isn't enabled yet - any plans to add that in?

Dropped video playback

It would appear that the video will on play for a few seconds before dropping. I have tested on OSX and Ubuntu with multiple files and sources.

Do you have any idea why this happening?

var browser = require('airplay').createBrowser();

browser.on('deviceOnline', function(device) {
    console.log('device online: ' + device.id);
    device.play('http://www.wowza.com/_h264/BigBuckBunny_115k.mov', 0);
});

browser.start();

browser.getDevices() doesn't find my Airport Express

Hi,

I have bought a Airport Express to be able to listen to music from my computer in my living room. So naturally I wanted to play a bit with it too and I found this project. I installed the airplay module and tried the example code but even if I can play music on the Airport Express from iTunes, node-airplay doesn't discover my Airport Express:

> var browser = require('airplay').createBrowser();
undefined
> console.log(browser.getDevices());
[]
undefined

I just get an empty array. What am I doing wrong?

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.