55 lines
1.4 KiB
TypeScript
55 lines
1.4 KiB
TypeScript
import HttpServer from './http';
|
|
import TVWebSocket from './ws';
|
|
import Zap, { IZap } from './zap';
|
|
|
|
import * as readline from 'readline';
|
|
|
|
const HTTP_PORT = process.env.HTTP_PORT ? parseInt(process.env.HTTP_PORT, 10) : 8080;
|
|
const WS_PORT = process.env.WS_PORT ? parseInt(process.env.WS_PORT, 10) : 3001;
|
|
const STATIC_ROOT = process.cwd() + "/dist/static";
|
|
const TV_DEV_0 = process.env.TV_DEV_0 ?? '/dev/dvb/adapter0/dvr0'
|
|
const TV_DEV_1 = process.env.TV_DEV_1 ? '/dev/dvb/adapter0/dvr1' : null;
|
|
|
|
const zap = new Zap();
|
|
|
|
|
|
const tune = (reqChannel: string, reqAdapter?: number) => {
|
|
const adapter = reqAdapter === 0 || reqAdapter === 1 ? reqAdapter : 0;
|
|
zap.zapTo(reqChannel, adapter).then((zap: IZap) => {
|
|
console.log(`Tuned ${zap.adapter} to ${zap.channel}`)
|
|
}).catch((err: Error) => {
|
|
console.error(err.message);
|
|
});
|
|
}
|
|
|
|
const getChannels = () =>
|
|
zap.getChannels();
|
|
|
|
const httpServer = new HttpServer(HTTP_PORT, STATIC_ROOT, tune, getChannels);
|
|
const tvWebSocket = new TVWebSocket(WS_PORT);
|
|
httpServer.start();
|
|
|
|
|
|
process.stdin.setEncoding("utf8");
|
|
process.stdin.resume();
|
|
|
|
console.log("Enter Channel Name:");
|
|
|
|
process.stdin.on("data", async (data: string) => {
|
|
const input = data.trim();
|
|
console.log(`Received: "${input}"`);
|
|
await zap.zapTo(input).then((zap: IZap) => {
|
|
console.log(`Tuned ${zap.adapter} to ${zap.channel}`)
|
|
|
|
}).catch((err: Error) => {
|
|
console.error(err.message);
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|