Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4.0.0: NPM and NPX support, customizable config path, and slightly cleaner code #65

Merged
merged 10 commits into from
Jan 1, 2022
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ Right now, due to Docker networking issues, the best way to get this working is
To run it as a daemon:
`node index.js >/dev/null 2>&1 &`

## Run locally using NPX

`npx antennas --config foo/bar.yml` OR
`TVHEADEND_URL=http://admin:test@192.168.0.1:9981 ANTENNAS_URL=http://127.0.0.1:5004 TUNER_COUNT=6 DEVICE_UUID=2f70c0d7-90a3-4429-8275-cbeeee9cd605 npx antennas`

### Docker

Another way to get it running is to run it using Docker. Note that some functionality is currently not quite working when hosting this as a Docker container, namely, discovery from Plex. But with that warning, if you so choose to continue using Docker, the instructions are below.
Expand Down Expand Up @@ -74,6 +79,11 @@ Antennas will look for three values inside a `config/config.yml` file. They are:

If you want to set environment variables instead of modifying the config.yml, you can do so. The environment variable names are the same than the config.yml, except capitalized. So, `TVHEADEND_URL` and `TUNER_COUNT`.

#### CLI parameters

- `--config` followed by the config path, i.e. `--config foo/bar.yml` will allow you to set a custom path for the config file
- `--nologo` will disable the big ASCII art logo for a simple text one

## Contributing

1. Fork it ( https://github.com/thejf/antennas/fork )
Expand Down
12 changes: 12 additions & 0 deletions assets/logo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
:Qr `bX.
;Wg`~L. :s`^NN`
NW` MM` IYY: ;Wh iWv
EW. NM_ `:::! uWJ vWi
~MN~`; iEEEEEE!`\ [MK
.6\ !WH...~NM. `vI {>`
-MMQQQQQQMN` MW'
`NWt::::::nW@ NN[hQNNEr _EWWNEE 'xBNNNKv` ~NN\XNMNR; vN$vENMNZ. {dQQNNK1 .6QNNNR_
@WnssssssssZWD MWb. .QWv MW' YWd. :MM. ^WWu` |MW| aWM! `sWN `' `BWi KWn. ~
6WNssssssssssNWj MW' nWS MW' MWQ@@@@@MM= ^WW BW[ aWV ^WW .4QKbbbNWv .u#NMQ$^
rWV::::::::::::gW{ MW_ nWS NW{ `` sWD. `\ ^WW BW[ aWZ ^WW GWG .NWv >|` `aWN
'Nb `KN~ NN~ vNY ^bNNNI |SQNNNB9~ ~NN wN{ vNs ~NN `xQNNBGVNl `Y#NNNNG^
36 changes: 29 additions & 7 deletions index.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
#!/usr/bin/env node

const Koa = require('koa');
const serve = require('koa-static');
const logger = require('koa-logger');
const fs = require('fs');

const router = require('./src/router');
const config = require('./src/config');
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');
const argv = yargs(hideBin(process.argv)).argv;

// Version only comes in when run with NPM, so make this optional
let antennasVersion = process.env.npm_package_version ? `v${process.env.npm_package_version}` : '';
if (argv.nologo) {
console.log(`Antennas ${antennasVersion}`);
} else {
const logo = fs.readFileSync('./assets/logo.txt','utf8');
console.log('\x1b[34m%s\x1b[0m', logo, antennasVersion);
}
console.log(``)

// Load config
const configHandler = require('./src/configHandler');
const config = argv.config ? configHandler.loadConfig(argv.config) : configHandler.loadConfig();

// Setup Antenna components
const device = require('./src/device')(config);
const router = require('./src/router')(config, device);
const ssdp = require('./src/ssdp');

// TODO: Figure out the discovery protocol UDP thing on port 65001
Expand All @@ -15,8 +36,8 @@ const app = new Koa();
try {
app
.use(logger())
.use(router().routes())
.use(router().allowedMethods())
.use(router.routes())
.use(router.allowedMethods())
.use(serve('public', { extensions: true }))
.use(async function pageNotFound(ctx) {
ctx.status = 404;
Expand All @@ -25,10 +46,11 @@ try {
});

app.listen(5004);
console.log(`📡 Antennas are deployed! Proxying from ${config().antennas_url}`);
ssdp();

console.log(`📡 Antennas are deployed! Proxying from ${config.antennas_url}`);
ssdp.broadcastSSDP(device);
} catch (e) {
console.log('❌ Antennas failed to deploy! 😮 It could be missing a config file, or something is misconfigured. See below for details:');
console.log('❌ Antennas failed to deploy! 😮 It could be missing a config file, or something is misconfigured. See below for details:');
console.log(e);
}

Expand Down
Loading