Advertise the ACP server

parent 733efd44
......@@ -167,6 +167,11 @@
"integrity": "sha1-p5SvDAWrF1KEbudTofIRoFugxE8=",
"dev": true
},
"array-flatten": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-2.1.1.tgz",
"integrity": "sha1-Qmu52oQJDBg42BLIFQryCoMx4pY="
},
"array-initial": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/array-initial/-/array-initial-1.1.0.tgz",
......@@ -1030,6 +1035,19 @@
"integrity": "sha1-RqoXUftqL5PuXmibsQh9SxTGwgU=",
"dev": true
},
"bonjour": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/bonjour/-/bonjour-3.5.0.tgz",
"integrity": "sha1-jokKGD2O6aI5OzhExpGkK897yfU=",
"requires": {
"array-flatten": "2.1.1",
"deep-equal": "1.0.1",
"dns-equal": "1.0.0",
"dns-txt": "2.0.2",
"multicast-dns": "6.2.3",
"multicast-dns-service-types": "1.1.0"
}
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
......@@ -1100,6 +1118,11 @@
"integrity": "sha512-83apNb8KK0Se60UE1+4Ukbe3HbfELJ6UlI4ldtOGs7So4KD26orJM8hIY9lxdzP+UpItH1Yh/Y8GUvNFWFFRxA==",
"dev": true
},
"buffer-indexof": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/buffer-indexof/-/buffer-indexof-1.1.1.tgz",
"integrity": "sha512-4/rOEg86jivtPTeOUUT61jJO1Ya1TrR/OkqCSZDyq84WJh3LuuiphBYJN+fm5xufIk4XAFcEwte/8WzC8If/1g=="
},
"builtin-modules": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz",
......@@ -1463,6 +1486,11 @@
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=",
"dev": true
},
"deep-equal": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz",
"integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU="
},
"deep-is": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz",
......@@ -1573,6 +1601,28 @@
"repeating": "2.0.1"
}
},
"dns-equal": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/dns-equal/-/dns-equal-1.0.0.tgz",
"integrity": "sha1-s55/HabrCnW6nBcySzR1PEfgZU0="
},
"dns-packet": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-1.3.1.tgz",
"integrity": "sha512-0UxfQkMhYAUaZI+xrNZOz/as5KgDU0M/fQ9b6SpkyLbk3GEswDi6PADJVaYJradtRVsRIlF1zLyOodbcTCDzUg==",
"requires": {
"ip": "1.1.5",
"safe-buffer": "5.1.2"
}
},
"dns-txt": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/dns-txt/-/dns-txt-2.0.2.tgz",
"integrity": "sha1-uR2Ab10nGI5Ks+fRB9iBocxGQrY=",
"requires": {
"buffer-indexof": "1.1.1"
}
},
"doctrine": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz",
......@@ -3336,6 +3386,11 @@
"resolved": "https://registry.npmjs.org/invert-kv/-/invert-kv-2.0.0.tgz",
"integrity": "sha512-wPVv/y/QQ/Uiirj/vh3oP+1Ww+AWehmi1g5fFWGPF6IpCBCDVrhgHRMvrLfdYcwDh3QJbGXDW4JAuzxElLSqKA=="
},
"ip": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/ip/-/ip-1.1.5.tgz",
"integrity": "sha1-vd7XARQpCCjAoDnnLvJfWq7ENUo="
},
"is-absolute": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-absolute/-/is-absolute-1.0.0.tgz",
......@@ -3953,6 +4008,20 @@
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
"dev": true
},
"multicast-dns": {
"version": "6.2.3",
"resolved": "https://registry.npmjs.org/multicast-dns/-/multicast-dns-6.2.3.tgz",
"integrity": "sha512-ji6J5enbMyGRHIAkAOu3WdV8nggqviKCEKtXcOqfphZZtQrmHKycfynJ2V7eVPUA4NhJ6V7Wf4TmGbTwKE9B6g==",
"requires": {
"dns-packet": "1.3.1",
"thunky": "1.0.3"
}
},
"multicast-dns-service-types": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/multicast-dns-service-types/-/multicast-dns-service-types-1.1.0.tgz",
"integrity": "sha1-iZ8R2WhuXgXLkbNdXw5jt3PPyQE="
},
"mute-stdout": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/mute-stdout/-/mute-stdout-1.0.0.tgz",
......@@ -4861,8 +4930,7 @@
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
"dev": true
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
},
"safe-regex": {
"version": "1.1.0",
......@@ -5411,6 +5479,11 @@
"xtend": "4.0.1"
}
},
"thunky": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/thunky/-/thunky-1.0.3.tgz",
"integrity": "sha512-YwT8pjmNcAXBZqrubu22P4FYsh2D4dxRmnWBOL8Jk8bUcRUtc5326kx32tuTmFDAZtLOGEVNl8POAR8j896Iow=="
},
"time-stamp": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/time-stamp/-/time-stamp-1.1.0.tgz",
......
......@@ -20,6 +20,7 @@
],
"dependencies": {
"adler32": "^0.1.7",
"bonjour": "^3.5.0",
"yargs": "^12.0.2"
},
"devDependencies": {
......
......@@ -5,6 +5,7 @@ import Server from './server';
import Property from './property';
import yargs from 'yargs';
import bonjour from 'bonjour';
yargs.demandCommand();
yargs.help();
......@@ -12,7 +13,6 @@ yargs.help();
yargs.option('host', {
alias: 'h',
describe: 'The hostname/IP address of the AirPort device to connect to',
default: 'airport-base-station.local',
});
yargs.option('port', {
describe: 'The port of the AirPort device\'s acp daemon (you should only need to change this when you need to use port forwarding to access the device)',
......@@ -25,10 +25,28 @@ yargs.option('password', {
yargs.command('version', 'Shows the node-acp version', () => {}, argv => {
console.log('node-acp v' + require('../package').version);
console.log('https://gitlab.fancy.org.uk/samuel/node-acp');
});
yargs.command('server', 'Start the ACP server', yargs => {}, async argv => {
const server = new Server(argv.host, argv.port, argv.password);
yargs.command('server', 'Start the ACP server', yargs => {
yargs.option('advertise', {
describe: 'Whether to advertise the ACP server with DNS SD',
boolean: true,
});
yargs.option('advertise-name', {
describe: 'The name to advertise the service as',
default: 'node-acp',
});
yargs.option('advertise-network', {
describe: 'The network name to advertise',
default: 'node-acp',
});
yargs.option('advertise-address', {
describe: 'The MAC address to advertise',
default: '00-00-00-00-00-00',
});
}, async argv => {
const server = new Server(argv.host || '::', argv.port, argv.password);
try {
await server.listen();
......@@ -37,10 +55,36 @@ yargs.command('server', 'Start the ACP server', yargs => {}, async argv => {
}
// Leave the server to run
if (argv.advertise) {
const service = bonjour().publish({
name: argv['advertise-name'],
port: argv.port,
type: 'airport',
txt: {waMA: '00-00-00-00-00-00,' + Object.entries({
// waMA: '00-00-00-00-00-00', // Ethernet MAC address
raMA: argv['advertise-address'], // 5 GHz Wi-Fi MAC address - this is used to identify devices in AirPort Utility
raM2: '00-00-00-00-00-00', // 2.4 GHz Wi-Fi MAC address
raNm: argv['advertise-network'], // Network
raCh: 1, // 2.4 GHz channel
rCh2: 36, // 5 GHz channel
raSt: 0, // ?
raNA: 0, // ?
syFl: '0x820C', // ?
syAP: 115, // Model?
syVs: '7.8', // Version
srcv: '78000.12', // Build
bjSd: 43, // ?
// prob: '',
}).map(([k, v]) => `${k}=${v}`).join(',')},
});
console.log('Advertising service', service);
}
});
const commandHandler = handler => async argv => {
const client = new Client(argv.host, argv.port, argv.password);
const client = new Client(argv.host || 'airport-base-station.local', argv.port, argv.password);
try {
await client.connect();
......
......@@ -54,6 +54,8 @@ export default class Server {
const session = new Session(socket.remoteAddress, socket.remotePort, this.password);
session.socket = socket;
console.log('New connection from', session.host, session.port);
socket.on('data', data => {
console.debug(0, 'Receiving data', data, 'on connection', session.host + ' port ' + session.port);
if (session.reading) return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment