Initial app + gitea action #1

Merged
david merged 15 commits from dev into main 2025-04-03 21:32:59 -07:00
6 changed files with 82 additions and 26 deletions
Showing only changes of commit 15f73327ee - Show all commits

View File

@ -8,7 +8,7 @@ export default class HttpServer {
private httpServer: http.Server;
private port: number;
private root: string;
public constructor(port: number, root: string, tune: (ch: string, adp?: number) => void, getChannels: ()=>string[]) {
public constructor(port: number, root: string, tune: (ch: string, adp?: number) => void, getChannels: ()=>string[], getSignal: (adapter:number)=>object) {
this.port = port;
this.root = root;
this.httpServer = http.createServer((req, res) => {
@ -27,6 +27,11 @@ export default class HttpServer {
body = JSON.stringify(getChannels());
status = 200;
break;
case "signal":
const adapter = parseInt(url.searchParams.get('adapter'));
body = JSON.stringify(getSignal(adapter));
status = 200;
break;
}
break;

View File

@ -23,7 +23,10 @@ const tune = (reqChannel: string, reqAdapter?: number) => {
const getChannels = () =>
zap.getChannels();
const httpServer = new HttpServer(HTTP_PORT, STATIC_ROOT, tune, 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();

View File

@ -26,6 +26,8 @@ body {
display: flex;
flex-direction: column;
text-align: center;
align-items: center;
justify-content: center;
h1 {}
p {}
@ -35,7 +37,7 @@ body {
}
.content{
display: flex;
flex-direction: column;
flex-direction: row;
gap: 1em;
.player{

View File

@ -18,12 +18,17 @@
<video id="video0" autoplay playsinline controls></video>
<div id="channel-container-0" class="channel-group"></div>
<button onClick="tune(0)">Tune</button>
<p id="signal-0">N/A</p>
<button onClick="getSignal(0)">Get Signal</button>
</div>
<div class="player">
<video id="video1" autoplay playsinline controls></video>
<div id="channel-container-1" class="channel-group"></div>
<button onClick="tune(1)">Tune</button>
<p id="signal-1">N/A</p>
<button onClick="getSignal(1)">Get Signal</button>
</div>
</main>
</div>

View File

@ -12,26 +12,22 @@ const populateChannels = (players:number) => {
}
radioGroup.innerHTML = ''
channelNames.forEach((channelName, _) => {
const id = `radio-${channelName}`;
const id = `radio-${i}-${channelName}`;
const input = document.createElement('input');
input.type = "radio"
input.name = `channel-radio-${i}`;
input.value = channelName;
input.value = `${channelName}`;
input.id = id
const lbl = document.createElement("label");
lbl.htmlFor = id;
lbl.textContent = channelName;
// Wrap in a div or line
const wrapper = document.createElement("div");
wrapper.appendChild(input);
wrapper.appendChild(lbl);
radioGroup.appendChild(wrapper)
})
}
@ -50,4 +46,16 @@ const tune = (adapter=0) =>{
}
const getSignal = (adapter = 0) => {
const signalElement = document.getElementById(`signal-${adapter}`);
if (!signalElement) {
return;
}
fetch(`/api/signal?adapter=${adapter}`).then(res =>
res.json()
).then((strength: any) => {
signalElement.innerHTML = `Signal: ${strength.signal} C/N: ${strength.cn}`
})
}
populateChannels(PLAYERS);

View File

@ -5,6 +5,10 @@ export interface IZap {
process: ChildProcessWithoutNullStreams | null,
channel: string,
adapter: 0 | 1
strength: {
signal: string;
cn: string;
},
}
export default class Zap {
@ -12,16 +16,28 @@ export default class Zap {
private zap1: IZap;
private channelNameList: string[];
private fileName: string;
private regex = /Signal=\s*(-?\d+(\.\d+)?dBm)\s+C\/N=\s*(\d+(\.\d+)?dB)/;
public constructor(fileName = "dvb_channel.conf", channel = "ION") {
const zap0: IZap = {
process: null,
channel,
adapter: 0
adapter: 0,
strength: {
signal: "None",
cn: "None"
}
}
const zap1: IZap = {
process: null,
channel,
adapter: 1
adapter: 1,
strength: {
signal: "None",
cn: "None"
}
}
this.zap0 = zap0;
this.zap1 = zap1;
@ -37,6 +53,18 @@ export default class Zap {
return this.channelNameList;
}
public getSignal(adapter: number) {
if(adapter == 0){
return this.zap0.strength;
}
else if (adapter == 1){
return this.zap1.strength;
}
else {
return {signal: 'N/A', cn: 'N/A'}
}
}
private nextChannel(channel: string) :string {
const size = this.channelNameList.length;
const currentIndex = this.channelNameList.indexOf(channel);
@ -108,7 +136,12 @@ export default class Zap {
if (/Lock/.test(output)) {
clearTimeout(lockTimer);
const match = output.match(this.regex);
zap.channel = verifiedChannel;
zap.strength = {
signal: match[1],
cn: match[3]
}
resolve(zap);
}