Skip to content

Commit

Permalink
Critical bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SphtKr committed Apr 23, 2016
1 parent b247c59 commit 7e5128b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Mainly, it makes it possible for you control your music system with Siri or via

This plugin requires a Mac running iTunes, and presently requires Homebridge to be running on that Mac. Already running Homebridge on a Raspberry Pi? No problem: remember that you can run more than one instance of Homebridge on a network, just install Node on your iTunes Mac and run Homebridge there, being sure to change the `"username"` field in `config.json` to be unique.

Node v4 or greater is required, and Homebridge v0.3 or higher.

## Quick Start

1. `sudo npm install -g homebridge`, See the [Homebridge](https://github.com/nfarina/homebridge) project site for more information, and to configure Homebridge
Expand Down
20 changes: 15 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,11 @@ ITunesPlatform.prototype.didFinishLaunching = function() {
}

ITunesPlatform.prototype.syncAccessories = function() {
clearTimeout(this.syncTimer);
this.syncTimer = setTimeout(this.syncAccessories.bind(this), 2000);
var syncAgainIn = function(msec){
clearTimeout(this.syncTimer);
this.syncTimer = setTimeout(this.syncAccessories.bind(this), msec);
}.bind(this);
syncAgainIn(2000);

// Update the primary accessory
var pa = this.primaryAccessory;
Expand All @@ -389,10 +392,11 @@ ITunesPlatform.prototype.syncAccessories = function() {
// erm...well this is awkward...Try again in a bit?
this.log(err);
this.log("ERROR: Failed creating iTunes main device, trying again in two seconds.");
clearTimeout(this.syncTimer);
this.syncTimer = setTimeout(this.syncAccessories.bind(this), 2000);
syncAgainIn(2000);
} else {
rtn = applescript.Parsers.parse(rtn);
// Messes up MAC addresses that start with a number >:-(
// The node-osascript parser is sufficient for this simple string.
//rtn = applescript.Parsers.parse(rtn);
this.addPrimaryAccessory(rtn);
}
}.bind(this));
Expand All @@ -401,6 +405,9 @@ ITunesPlatform.prototype.syncAccessories = function() {
osascript.execute('tell application "iTunes" to get {player state, sound volume}', function(err, rtn){
if (err) {
this.log(err);
this.log("ERROR: Failed syncing iTunes main device, trying again in two seconds.");
syncAgainIn(2000);
return;
}
rtn = applescript.Parsers.parse(rtn);
if (Array.isArray(rtn)) {
Expand Down Expand Up @@ -429,6 +436,9 @@ ITunesPlatform.prototype.syncAccessories = function() {
osascript.execute(tell, function(err, rtn) {
if (err) {
this.log(err);
this.log("ERROR: Failed getting AirPlay devices--iTunes may still be launching. Trying again in two seconds.");
syncAgainIn(2000);
return;
}
rtn = applescript.Parsers.parse(rtn);
if (Array.isArray(rtn)) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-itunes",
"version": "0.1.0",
"version": "0.1.1",
"description": "homebridge-plugin for iTunes control.",
"main": "index.js",
"scripts": {
Expand All @@ -19,8 +19,8 @@
"HomeKit"
],
"engines": {
"node": ">=0.12.0",
"homebridge": ">=0.2.5"
"node": ">=4.0.0",
"homebridge": ">=0.3.0"
},

"dependencies": {
Expand Down

0 comments on commit 7e5128b

Please sign in to comment.