57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import HttpServer from './http';
|
|
import TVWebSocket from './ws';
|
|
import Zap, { IZap } from './zap';
|
|
|
|
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/adapter1/dvr0';
|
|
|
|
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 getSignal = (adapter: number) =>
|
|
zap.getSignal(adapter)
|
|
|
|
const httpServer = new HttpServer(HTTP_PORT, STATIC_ROOT, tune, getChannels, getSignal);
|
|
const tvWebSocket0 = new TVWebSocket(WS_PORT, TV_DEV_0);
|
|
const tvWebSocket1 = new TVWebSocket(WS_PORT + 1, TV_DEV_1);
|
|
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);
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|