-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.js
executable file
·100 lines (79 loc) · 1.89 KB
/
app.js
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
93
94
95
96
97
98
99
100
#!/usr/bin/env node
const fs = require('fs');
const cliCursor = require('cli-cursor');
const parseArgs = require('minimist');
const playercast = require('./lib/index');
const terminal = require('./lib/terminal');
cliCursor.hide();
const opts = {
boolean: [
'quiet', 'cec-alt-remote', 'cec-force-switch', 'disable-cec',
'attach', 'create-service', 'remove-service', 'disable-scan', 'help'
],
string: ['subs', 'name', 'player', 'cwd', 'port', 'cec-end-hdmi'],
alias: { q: 'quiet', a: 'attach', s: 'subs', n: 'name', p: 'player' },
default: { p: (process.platform === 'win32') ? 'vlc' : 'mpv' },
unknown: (option) => onUnknown(option)
};
const WIN_DIRS = {
vlc: 'C:\\Program Files\\VideoLAN\\VLC'
};
const args = process.argv.slice(2);
var argv = parseArgs(args, opts);
init();
function init()
{
if(argv.help || !checkArgvStrings())
return terminal.showHelp();
argv.listen = getIsReceiverMode();
if(
argv.listen
&& !argv.cwd
&& process.platform === 'win32'
&& WIN_DIRS[argv.player]
&& fs.existsSync(WIN_DIRS[argv.player])
) {
argv.cwd = WIN_DIRS[argv.player];
}
const app = playercast(argv);
}
function onUnknown(option)
{
if(!option.startsWith('-')) return;
terminal.showHelp();
process.exit(1);
}
function checkArgvStrings()
{
if(
argv.hasOwnProperty('cec-end-hdmi')
&& (isNaN(argv['cec-end-hdmi']) || argv['cec-end-hdmi'] < 0)
)
return false;
if(
argv.hasOwnProperty('port')
&& (isNaN(argv.port) || argv.port < 1 || argv.port > 65535)
)
return false;
for(var key of opts.string)
if(argv[key] === '') return false;
return true;
}
function getIsReceiverMode()
{
if(!argv._.length)
return true;
else if(argv._.length > 1)
return false;
const ip = argv._[0].split(':')[0].split('.');
if(ip.length === 1 && ip[0] === 'localhost')
return true;
if(ip.length !== 4)
return false;
for(var addr of ip)
{
if(isNaN(addr))
return false;
}
return true;
}