npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

airplay

v0.0.3

Published

Apple AirPlay client library

Downloads

11

Readme

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 airplay = require('airplay');
> var browser = airplay.createBrowser();
> browser.on('deviceOnline', function(device) {
    device.play('http://host/somevideo.mp4', 0, function(res) {
      if (res) {
        console.log('playing!');
      } else {
        console.log('unable to play!');
      }
    });
  });
> 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_mdns and node-plist. Unfortunately neither stored in the npm repo work correctly, and as such the package points to forks I have made. Hopefully this will be resolved soon.

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('hostname', port);
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 seek 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);