forked from RoonLabs/roon-connect-stream-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.mjs
92 lines (73 loc) · 2.56 KB
/
test.mjs
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import prompt from 'async-prompt';
import * as re from './lib.mjs';
function help() {
console.log(`Commands:
help, ?
print help
exit, quit, bye, ^C
exit
play <stream>
play the stream in roon -- must be one of the Roon-supported stream formats
stop
stop playback and release the zone back to Roon
vol up|down|<number>
change the volume up or down, or set it to a specific number
`);
}
const pmpt = `\nEnter command (? for help) > `;
const logger = (msg) => {
if (msg)
process.stdout.write("\n" + msg + pmpt);
process.stdout.write(pmpt);
}
const roon = re.init({
logger: logger,
enableProtocolTrace: false,
extensionOptions: {
extension_id: 'com.EpochAudio.connect_stream',
display_name: 'Epoch Audio Connect Stream',
display_version: "1.0.0",
publisher: '门耳朵制作',
email: 'sales@epochaudio.cn',
website: 'http://www.epochaudio.cn',
},
});
while (true) {
const argv = (await prompt(pmpt))?.split(/\s\s*/);
if (argv[0] == "") {
// do nothing
} else if (argv[0] == "exit" || argv[0] == "quit" || argv[0] == "bye") {
process.exit(0);
} else if (argv[0] == "?" || argv[0] == "help") {
help();
} else if (argv[0] == "stop") {
re.stop();
} else if (argv[0] == "play") {
const url = argv[1];
if (!url)
console.log(`error: play <url>`);
else
re.play({
url: url,
name: "My Brand",
line1: "来自门耳朵的中文在线广播",
icon: "/image/qrcode_for_gh_75032b7b381b_344-300x300.jpg",
});
} else if (argv[0] == "vol") {
if (argv[1] == "up") {
const vol = parseInt(argv[2], 10) || 1;
roon.core.services.RoonApiTransport.change_volume(roon.current_output_id, 'relative_step', vol);
} else if (argv[1] == "down") {
const vol = parseInt(argv[2], 10) || 1;
roon.core.services.RoonApiTransport.change_volume(roon.current_output_id, 'relative_step', vol * -1);
} else {
const vol = parseInt(argv[1], 10);
if (isNaN(vol))
console.log(`error: vol up|down|<number>`);
else
roon.core.services.RoonApiTransport.change_volume(roon.current_output_id, 'absolute', vol);
}
} else {
console.log(`error: unknown command: ${argv.join(" ")}`);
}
}