-
Notifications
You must be signed in to change notification settings - Fork 0
/
mini-chromecast
executable file
·70 lines (56 loc) · 1.64 KB
/
mini-chromecast
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/node
/*
* Simple script to return the Chromecast playing status
* Output: playing, paused and some other values I guess
* We can also use it for short commands like pause and play
*/
var host = process.argv[2] || null,
command = process.argv[3] || null;
if (!host || !command || (command !== "status" && command !== "pause" && command !== "play")) {
// Show help
console.log("Usage:");
console.log("./mini-chromecast host command");
console.log(" status: shows player status");
console.log(" pause: pauses running application");
console.log(" play: continues playing in running application");
process.exit();
}
var PS = require('castv2-client/lib/senders/platform');
var client = new PS();
client.connect(host, function() {
client.getSessions(function(err, apps) {
if (err) { output("unknown"); }
if (! apps.length) { output("stopped"); }
var session = apps[0];
var myApp = require("./classes/api");
client.join(session, myApp, function(err, player) {
if (command === "status") {
player.getStatus(function (err, status) {
output(status.playerState.toLowerCase());
});
}
if (command === "pause") {
player.pause(function() {
process.exit();
});
}
if (command === "play") {
player.play(function() {
process.exit();
});
}
/*
For when it keeps running
player.on('status', function(status) {
output(status.playerState.toLowerCase());
});
*/
});
});
});
function output(status) {
if (command === "status") {
console.log(status);
}
process.exit();
}