Skip to content
This repository has been archived by the owner on Sep 17, 2020. It is now read-only.

Commit

Permalink
v1.0.13
Browse files Browse the repository at this point in the history
Fixed Docker execution
  • Loading branch information
stickpin committed Jan 17, 2020
1 parent 0117260 commit 3fbb68d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 38 deletions.
7 changes: 1 addition & 6 deletions dist/lib/appletv.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@ class AppleTV extends typed_events_1.default {
this.pairingId = uuid_1.v4();
this.service = service;
this.name = service.txtRecord.Name;
if (service.addresses.length > 1) {
this.address = service.addresses[1];
}
else {
this.address = service.addresses[0];
}
this.address = service.host;
this.port = service.port;
this.uid = service.txtRecord.UniqueIdentifier;
this.connection = new connection_1.Connection(this);
Expand Down
85 changes: 54 additions & 31 deletions dist/lib/browser.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,68 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
Object.defineProperty(exports, "__esModule", {
value: true
});
const mdns = require("mdns");
const mdnsResolver = require("mdns-resolver");
const appletv_1 = require("./appletv");
class Browser {
/**
* Creates a new Browser
* @param log An optional function that takes a string to provide verbose logging.
*/
* Creates a new Browser
* @param log An optional function that takes a string to provide verbose logging.
*/
constructor() {
let sequence = [
mdns.rst.DNSServiceResolve(),
'DNSServiceGetAddrInfo' in mdns.dns_sd ? mdns.rst.DNSServiceGetAddrInfo() : mdns.rst.getaddrinfo({ families: [4] }),
mdns.rst.makeAddressesUnique()
mdns.rst.DNSServiceResolve()
];
this.browser = mdns.createBrowser(mdns.tcp('mediaremotetv'), { resolverSequence: sequence });

this.browser = mdns.createBrowser(mdns.tcp('mediaremotetv'), {
resolverSequence: sequence
});
this.services = [];
this.devices = [];
let that = this;
this.browser.on('serviceUp', function (service) {
let device = new appletv_1.AppleTV(service);
if (that.uniqueIdentifier && device.uid == that.uniqueIdentifier) {
that.browser.stop();
that.onComplete([device]);
}
else {
if(that.devices.find(uuid => uuid == device.uid)) {
return;
} else {
that.devices.push(device.uid);
that.services.push(device);
}
}

mdnsResolver.resolve4(service.host)
.then(host => {
service.host = host;
return service;
})
.catch(e => {
console.log("Failed to resolve IPv4");
console.log("ERROR: " + e.message);
return mdnsResolver.resolve6(service.host)
.then(host => {
service.host = `[${host}]`;
return service;
});
})
.catch(e => {
console.log("Failed to resolve IPv4 and IPv6");
console.log("ERROR: " + e.message);
})
.then(service => {
let device = new appletv_1.AppleTV(service);
if (that.uniqueIdentifier && device.uid == that.uniqueIdentifier) {
that.browser.stop();
that.onComplete([device]);
} else {
if (that.devices.find(uuid => uuid == device.uid)) {
return;
} else {
that.devices.push(device.uid);
that.services.push(device);
}
}
});
});
}
/**
* Scans for AppleTVs on the local network.
* @param uniqueIdentifier An optional identifier for the AppleTV to scan for. The AppleTV advertises this via Bonjour.
* @param timeout An optional timeout value (in seconds) to give up the search after.
* @returns A promise that resolves to an array of AppleTV objects. If you provide a `uniqueIdentifier` the array is guaranteed to only contain one object.
*/
* Scans for AppleTVs on the local network.
* @param uniqueIdentifier An optional identifier for the AppleTV to scan for. The AppleTV advertises this via Bonjour.
* @param timeout An optional timeout value (in seconds) to give up the search after.
* @returns A promise that resolves to an array of AppleTV objects. If you provide a `uniqueIdentifier` the array is guaranteed to only contain one object.
*/
scan(uniqueIdentifier, timeout) {
this.services = [];
this.uniqueIdentifier = uniqueIdentifier;
Expand All @@ -52,15 +76,14 @@ class Browser {
that.browser.stop();
if (that.uniqueIdentifier) {
reject(new Error("Failed to locate specified AppleTV on the network"));
}
else {
} else {
resolve(that.services
.sort((a, b) => {
return a > b ? 1 : -1;
}));
return a > b ? 1 : -1;
}));
}
}, to * 1000);
});
}
}
exports.Browser = Browser;
exports.Browser = Browser;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-appletv-x",
"version": "1.0.12",
"version": "1.0.13",
"description": "A Node.js library for communicating with an Apple TV",
"homepage": "https://github.com/stickpin/node-appletv-x",
"bugs": "https://github.com/stickpin/node-appletv-x/issues",
Expand Down Expand Up @@ -35,6 +35,7 @@
"fast-srp-hap": "^1.0.1",
"inquirer": "^7.0.3",
"mdns": "^2.5.1",
"mdns-resolver": "^0.0.3",
"ora": "^4.0.3",
"protobufjs": "^6.8.8",
"snake-case": "^3.0.3",
Expand Down

0 comments on commit 3fbb68d

Please sign in to comment.