Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
200c707
commit fac6a70
Showing
84 changed files
with
2,721 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,4 @@ typings/ | |
.env | ||
|
||
# next.js build output | ||
.next | ||
|
||
dist | ||
.next |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const caporal = require("caporal"); | ||
let cli = caporal; | ||
const appletv_1 = require("../lib/appletv"); | ||
const credentials_1 = require("../lib/credentials"); | ||
const scan_1 = require("./scan"); | ||
const pair_1 = require("./pair"); | ||
cli | ||
.version('1.0.0') | ||
.command('pair', 'Pair with an AppleTV') | ||
.action((args, options, logger) => { | ||
scan_1.scan(logger) | ||
.then(device => { | ||
device.on('debug', (message) => { | ||
logger.debug(message); | ||
}); | ||
device.on('error', (error) => { | ||
logger.error(error.message); | ||
logger.debug(error.stack); | ||
}); | ||
return pair_1.pair(device, logger) | ||
.then(keys => { | ||
logger.info("Success! Credentials: " + device.credentials.toString()); | ||
process.exit(); | ||
}); | ||
}) | ||
.catch(error => { | ||
logger.error(error.message); | ||
logger.debug(error.stack); | ||
process.exit(); | ||
}); | ||
}); | ||
cli | ||
.version('1.0.0') | ||
.command('command', 'Send a command to an AppleTV') | ||
.argument('<command>', 'The command to send', /^up|down|left|right|menu|play|pause|next|previous|suspend$/) | ||
.option('--credentials <credentials>', 'The device credentials from pairing', cli.STRING) | ||
.action((args, options, logger) => { | ||
if (!options.credentials) { | ||
logger.error("Credentials are required. Pair first."); | ||
process.exit(); | ||
} | ||
let credentials = credentials_1.Credentials.parse(options.credentials); | ||
scan_1.scan(logger, credentials.uniqueIdentifier) | ||
.then(device => { | ||
device.on('debug', (message) => { | ||
logger.debug(message); | ||
}); | ||
device.on('error', (error) => { | ||
logger.error(error.message); | ||
logger.debug(error.stack); | ||
}); | ||
return device | ||
.openConnection(credentials) | ||
.then(() => { | ||
return device | ||
.sendKeyCommand(appletv_1.AppleTV.key(args["command"])) | ||
.then(result => { | ||
logger.info("Success!"); | ||
process.exit(); | ||
}); | ||
}); | ||
}) | ||
.catch(error => { | ||
logger.error(error.message); | ||
logger.debug(error.stack); | ||
process.exit(); | ||
}); | ||
}); | ||
cli | ||
.version('1.0.0') | ||
.command('state', 'Logs the playback state from the AppleTV') | ||
.option('--credentials <credentials>', 'The device credentials from pairing', cli.STRING) | ||
.action((args, options, logger) => { | ||
if (!options.credentials) { | ||
logger.error("Credentials are required. Pair first."); | ||
process.exit(); | ||
} | ||
let credentials = credentials_1.Credentials.parse(options.credentials); | ||
scan_1.scan(logger, credentials.uniqueIdentifier) | ||
.then(device => { | ||
device.on('debug', (message) => { | ||
logger.debug(message); | ||
}); | ||
device.on('error', (error) => { | ||
logger.error(error.message); | ||
logger.debug(error.stack); | ||
}); | ||
return device | ||
.openConnection(credentials); | ||
}) | ||
.then(device => { | ||
device.on('nowPlaying', (info) => { | ||
logger.info(info.toString()); | ||
}); | ||
}) | ||
.catch(error => { | ||
logger.error(error.message); | ||
logger.debug(error.stack); | ||
process.exit(); | ||
}); | ||
}); | ||
cli | ||
.version('1.0.0') | ||
.command('supportedCommands', 'Logs the playback state from the AppleTV') | ||
.option('--credentials <credentials>', 'The device credentials from pairing', cli.STRING) | ||
.action((args, options, logger) => { | ||
if (!options.credentials) { | ||
logger.error("Credentials are required. Pair first."); | ||
process.exit(); | ||
} | ||
let credentials = credentials_1.Credentials.parse(options.credentials); | ||
scan_1.scan(logger, credentials.uniqueIdentifier) | ||
.then(device => { | ||
device.on('debug', (message) => { | ||
logger.debug(message); | ||
}); | ||
device.on('error', (error) => { | ||
logger.error(error.message); | ||
logger.debug(error.stack); | ||
}); | ||
return device | ||
.openConnection(credentials); | ||
}) | ||
.then(device => { | ||
device.on('supportedCommands', (info) => { | ||
logger.info(info); | ||
}); | ||
}) | ||
.catch(error => { | ||
logger.error(error.message); | ||
logger.debug(error.stack); | ||
process.exit(); | ||
}); | ||
}); | ||
cli | ||
.version('1.0.0') | ||
.command('queue', 'Request the playback state from the AppleTV') | ||
.option('--credentials <credentials>', 'The device credentials from pairing', cli.STRING) | ||
.option('--location <location>', 'The location in the queue', cli.INTEGER) | ||
.option('--length <length>', 'The length of the queue', cli.INTEGER) | ||
.option('--metadata', 'Include metadata', cli.BOOLEAN) | ||
.option('--lyrics', 'Include lyrics', cli.BOOLEAN) | ||
.option('--languages', 'Include language options', cli.BOOLEAN) | ||
.action((args, options, logger) => { | ||
if (!options.credentials) { | ||
logger.error("Credentials are required. Pair first."); | ||
process.exit(); | ||
} | ||
let credentials = credentials_1.Credentials.parse(options.credentials); | ||
scan_1.scan(logger, credentials.uniqueIdentifier) | ||
.then(device => { | ||
device.on('debug', (message) => { | ||
logger.debug(message); | ||
}); | ||
device.on('error', (error) => { | ||
logger.error(error.message); | ||
logger.debug(error.stack); | ||
}); | ||
return device | ||
.openConnection(credentials); | ||
}) | ||
.then(device => { | ||
return device | ||
.requestPlaybackQueue({ | ||
location: options.location || 0, | ||
length: options.length || 1, | ||
includeMetadata: options.metadata, | ||
includeLyrics: options.lyrics, | ||
includeLanguageOptions: options.languages | ||
}); | ||
}) | ||
.then(message => { | ||
logger.info(message); | ||
}) | ||
.catch(error => { | ||
logger.error(error.message); | ||
logger.debug(error.stack); | ||
process.exit(); | ||
}); | ||
}); | ||
cli | ||
.version('1.0.0') | ||
.command('messages', 'Log all messages sent from the AppleTV') | ||
.option('--credentials <credentials>', 'The device credentials from pairing', cli.STRING) | ||
.action((args, options, logger) => { | ||
if (!options.credentials) { | ||
logger.error("Credentials are required. Pair first."); | ||
process.exit(); | ||
} | ||
let credentials = credentials_1.Credentials.parse(options.credentials); | ||
scan_1.scan(logger, credentials.uniqueIdentifier) | ||
.then(device => { | ||
device.on('debug', (message) => { | ||
logger.debug(message); | ||
}); | ||
device.on('error', (error) => { | ||
logger.error(error.message); | ||
logger.debug(error.stack); | ||
}); | ||
return device | ||
.openConnection(credentials); | ||
}) | ||
.then(device => { | ||
device.on('message', (message) => { | ||
logger.info(JSON.stringify(message.toObject(), null, 2)); | ||
}); | ||
}) | ||
.catch(error => { | ||
logger.error(error.message); | ||
logger.debug(error.stack); | ||
process.exit(); | ||
}); | ||
}); | ||
cli.parse(process.argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { AppleTV } from '../lib/appletv'; | ||
export declare function pair(device: AppleTV, logger: Logger): Promise<AppleTV>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const prompt_1 = require("prompt"); | ||
const pairing_1 = require("../lib/pairing"); | ||
function pair(device, logger) { | ||
logger.info("Pairing with " + device.name + "."); | ||
return device | ||
.openConnection() | ||
.then(() => { | ||
let pairing = new pairing_1.Pairing(device); | ||
return pairing.initiatePair() | ||
.then(callback => { | ||
return new Promise((resolve, reject) => { | ||
prompt_1.get(['PIN'], (error, result) => { | ||
if (error) { | ||
reject(error); | ||
} | ||
else { | ||
resolve(result.PIN); | ||
} | ||
}); | ||
}) | ||
.then(pin => { | ||
return callback(pin); | ||
}); | ||
}); | ||
}); | ||
} | ||
exports.pair = pair; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import { AppleTV } from '../lib/appletv'; | ||
export declare function scan(logger: Logger, uniqueIdentifier?: string): Promise<AppleTV>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const prompt_1 = require("prompt"); | ||
const browser_1 = require("../lib/browser"); | ||
function scan(logger, uniqueIdentifier) { | ||
let browser = new browser_1.Browser(); | ||
return browser | ||
.scan(uniqueIdentifier) | ||
.then(devices => { | ||
if (devices.length == 1) { | ||
return devices[0]; | ||
} | ||
return new Promise((resolve, reject) => { | ||
if (devices.length == 0) { | ||
reject(new Error("No Apple TVs found on the network.")); | ||
} | ||
else { | ||
logger.info("Found " + devices.length + " Apple TVs:"); | ||
for (var i = 0; i < devices.length; i++) { | ||
let device = devices[i]; | ||
logger.info((i + 1) + ": " + device.name + " (" + device.address + ")"); | ||
} | ||
prompt_1.get(['Device'], (error, result) => { | ||
if (error) { | ||
reject(error); | ||
} | ||
else { | ||
resolve(devices[parseInt(result.Device) - 1]); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
exports.scan = scan; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Credentials } from './lib/credentials'; | ||
import { AppleTV } from './lib/appletv'; | ||
import { Browser } from './lib/browser'; | ||
import { NowPlayingInfo } from './lib/now-playing-info'; | ||
import { Message } from './lib/message'; | ||
import { SupportedCommand } from './lib/supported-command'; | ||
/** | ||
* A convenience function to scan 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. | ||
*/ | ||
export declare function scan(uniqueIdentifier?: string, timeout?: number): Promise<AppleTV[]>; | ||
/** | ||
* A convenience function to parse a credentials string into a Credentials object. | ||
* @param text The credentials string. | ||
* @returns A credentials object. | ||
*/ | ||
export declare function parseCredentials(text: string): Credentials; | ||
export { AppleTV, Browser, NowPlayingInfo, Credentials, Message, SupportedCommand }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const credentials_1 = require("./lib/credentials"); | ||
exports.Credentials = credentials_1.Credentials; | ||
const appletv_1 = require("./lib/appletv"); | ||
exports.AppleTV = appletv_1.AppleTV; | ||
const browser_1 = require("./lib/browser"); | ||
exports.Browser = browser_1.Browser; | ||
const now_playing_info_1 = require("./lib/now-playing-info"); | ||
exports.NowPlayingInfo = now_playing_info_1.NowPlayingInfo; | ||
const message_1 = require("./lib/message"); | ||
exports.Message = message_1.Message; | ||
const supported_command_1 = require("./lib/supported-command"); | ||
exports.SupportedCommand = supported_command_1.SupportedCommand; | ||
/** | ||
* A convenience function to scan 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. | ||
*/ | ||
function scan(uniqueIdentifier, timeout) { | ||
let browser = new browser_1.Browser(); | ||
return browser.scan(uniqueIdentifier, timeout); | ||
} | ||
exports.scan = scan; | ||
/** | ||
* A convenience function to parse a credentials string into a Credentials object. | ||
* @param text The credentials string. | ||
* @returns A credentials object. | ||
*/ | ||
function parseCredentials(text) { | ||
return credentials_1.Credentials.parse(text); | ||
} | ||
exports.parseCredentials = parseCredentials; |
Oops, something went wrong.