add stations and an Auto tab following each station's band
Parse N1MM RadioInfo packets, map sender IPs to configured stations, and let the front-end auto-select the rotator for the selected station's current band. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+149
-18
@@ -97,11 +97,48 @@
|
||||
.turned-by .source {
|
||||
color: #e0e040;
|
||||
}
|
||||
.station-bar {
|
||||
display: none;
|
||||
gap: 8px;
|
||||
padding: 8px 12px;
|
||||
background: #0a0a0a;
|
||||
border-bottom: 1px solid #222;
|
||||
flex-wrap: wrap;
|
||||
user-select: none;
|
||||
}
|
||||
.station-bar.visible {
|
||||
display: flex;
|
||||
}
|
||||
.station-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 5px 12px;
|
||||
border: 2px solid #333;
|
||||
border-radius: 16px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
color: #888;
|
||||
transition: border-color 0.15s;
|
||||
}
|
||||
.station-pill:hover { border-color: #666; }
|
||||
.station-pill.selected { color: #fff; }
|
||||
.station-pill .dot {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
.station-pill .freq {
|
||||
color: #666;
|
||||
font-size: 12px;
|
||||
}
|
||||
.station-pill.selected .freq { color: #aaa; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="tab-bar" id="tab-bar"></div>
|
||||
<div class="station-bar" id="station-bar"></div>
|
||||
<div class="rotators" id="rotators"></div>
|
||||
|
||||
<script>
|
||||
@@ -472,17 +509,26 @@
|
||||
constructor() {
|
||||
this.rotators = {};
|
||||
this.labels = [];
|
||||
this.stations = {};
|
||||
this.stationPills = {};
|
||||
this.container = document.getElementById('rotators');
|
||||
this.tabBar = document.getElementById('tab-bar');
|
||||
this.stationBar = document.getElementById('station-bar');
|
||||
this.websocket = null;
|
||||
this.tiled = false;
|
||||
this.activeTab = null;
|
||||
this.autoMode = false;
|
||||
this.selectedStation = null;
|
||||
this.stationRadio = {};
|
||||
}
|
||||
|
||||
async initialize() {
|
||||
const initState = await this.startWs();
|
||||
const init = await this.startWs();
|
||||
|
||||
for (const [label, clientState] of Object.entries(initState)) {
|
||||
this.stations = init.stations || {};
|
||||
this.stationRadio = init.stationRadio || {};
|
||||
this.selectedStation = init.clientStation || null;
|
||||
|
||||
for (const [label, clientState] of Object.entries(init.rotators)) {
|
||||
const state = new RotatorState();
|
||||
|
||||
if (clientState.initData) {
|
||||
@@ -505,6 +551,7 @@
|
||||
}
|
||||
|
||||
this.buildTabBar();
|
||||
this.buildStationBar();
|
||||
this.applyHash();
|
||||
window.addEventListener('hashchange', () => this.applyHash());
|
||||
|
||||
@@ -514,6 +561,12 @@
|
||||
}
|
||||
|
||||
buildTabBar() {
|
||||
this.autoTab = document.createElement('div');
|
||||
this.autoTab.className = 'tab';
|
||||
this.autoTab.textContent = 'Auto';
|
||||
this.autoTab.addEventListener('click', () => { location.hash = 'auto'; });
|
||||
this.tabBar.appendChild(this.autoTab);
|
||||
|
||||
for (const label of this.labels) {
|
||||
const tab = document.createElement('div');
|
||||
tab.className = 'tab';
|
||||
@@ -528,50 +581,123 @@
|
||||
this.allTab = document.createElement('div');
|
||||
this.allTab.className = 'tab';
|
||||
this.allTab.textContent = 'All';
|
||||
this.allTab.addEventListener('click', () => {
|
||||
location.hash = 'all';
|
||||
});
|
||||
this.allTab.addEventListener('click', () => { location.hash = 'all'; });
|
||||
this.tabBar.appendChild(this.allTab);
|
||||
}
|
||||
|
||||
buildStationBar() {
|
||||
for (const [name, cfg] of Object.entries(this.stations)) {
|
||||
const pill = document.createElement('div');
|
||||
pill.className = 'station-pill';
|
||||
pill.style.borderColor = this.selectedStation === name ? cfg.color : '';
|
||||
|
||||
const dot = document.createElement('span');
|
||||
dot.className = 'dot';
|
||||
dot.style.background = cfg.color;
|
||||
pill.appendChild(dot);
|
||||
|
||||
const nameSpan = document.createElement('span');
|
||||
nameSpan.textContent = name;
|
||||
pill.appendChild(nameSpan);
|
||||
|
||||
const freq = document.createElement('span');
|
||||
freq.className = 'freq';
|
||||
const radio = this.stationRadio[name];
|
||||
freq.textContent = radio ? this.formatFreq(radio.freq) : '';
|
||||
pill.appendChild(freq);
|
||||
|
||||
pill.addEventListener('click', () => {
|
||||
this.selectedStation = name;
|
||||
this.updateStationSelection();
|
||||
this.applyAutoTab();
|
||||
});
|
||||
|
||||
this.stationBar.appendChild(pill);
|
||||
this.stationPills[name] = { el: pill, freqEl: freq };
|
||||
}
|
||||
this.updateStationSelection();
|
||||
}
|
||||
|
||||
updateStationSelection() {
|
||||
for (const [name, pill] of Object.entries(this.stationPills)) {
|
||||
const selected = name === this.selectedStation;
|
||||
const color = this.stations[name].color;
|
||||
pill.el.classList.toggle('selected', selected);
|
||||
pill.el.style.borderColor = selected ? color : '';
|
||||
}
|
||||
}
|
||||
|
||||
formatFreq(freq) {
|
||||
return (freq / 100000).toFixed(3) + ' MHz';
|
||||
}
|
||||
|
||||
applyHash() {
|
||||
const hash = decodeURIComponent(location.hash.slice(1));
|
||||
this.autoMode = false;
|
||||
|
||||
if (hash === 'all' || (hash === '' && this.labels.length <= 1)) {
|
||||
this.tiled = true;
|
||||
if (hash === 'auto' || hash === '') {
|
||||
this.autoMode = true;
|
||||
this.applyAutoTab();
|
||||
} else if (hash === 'all') {
|
||||
this.showAll();
|
||||
} else if (this.rotators[hash]) {
|
||||
this.tiled = false;
|
||||
this.showTab(hash);
|
||||
} else {
|
||||
// default: first tab, or all if single rotator
|
||||
this.tiled = false;
|
||||
this.showTab(this.labels[0]);
|
||||
this.autoMode = true;
|
||||
this.applyAutoTab();
|
||||
}
|
||||
|
||||
this.allTab.classList.toggle('active', this.tiled);
|
||||
this.stationBar.classList.toggle('visible', this.autoMode);
|
||||
this.autoTab.classList.toggle('active', this.autoMode);
|
||||
this.allTab.classList.toggle('active', hash === 'all');
|
||||
}
|
||||
|
||||
showTab(label) {
|
||||
applyAutoTab() {
|
||||
const radio = this.selectedStation ? this.stationRadio[this.selectedStation] : null;
|
||||
const match = radio ? this.findRotatorForBand(radio.band) : null;
|
||||
if (match) {
|
||||
this.showTab(match, true);
|
||||
} else {
|
||||
this.showAll(true);
|
||||
}
|
||||
}
|
||||
|
||||
findRotatorForBand(band) {
|
||||
for (const [label, rot] of Object.entries(this.rotators)) {
|
||||
if (rot.state.bands.includes(band)) return label;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
handleRadioInfo(station, band, freq) {
|
||||
this.stationRadio[station] = { band, freq };
|
||||
const pill = this.stationPills[station];
|
||||
if (pill) pill.freqEl.textContent = this.formatFreq(freq);
|
||||
if (this.autoMode && station === this.selectedStation) {
|
||||
this.applyAutoTab();
|
||||
}
|
||||
}
|
||||
|
||||
showTab(label, isAuto = false) {
|
||||
this.activeTab = label;
|
||||
for (const l of this.labels) {
|
||||
const rot = this.rotators[l];
|
||||
const visible = l === label;
|
||||
rot.ui.card.classList.toggle('visible', visible);
|
||||
rot.tab.classList.toggle('active', visible);
|
||||
rot.tab.classList.toggle('active', !isAuto && visible);
|
||||
}
|
||||
// re-render visible one (canvas may have been hidden)
|
||||
this.rotators[label].ui.renderer.render();
|
||||
}
|
||||
|
||||
showAll() {
|
||||
showAll(isAuto = false) {
|
||||
this.activeTab = null;
|
||||
for (const l of this.labels) {
|
||||
const rot = this.rotators[l];
|
||||
rot.ui.card.classList.add('visible');
|
||||
rot.tab.classList.remove('active');
|
||||
rot.tab.classList.toggle('active', false);
|
||||
rot.ui.renderer.render();
|
||||
}
|
||||
if (!isAuto) this.allTab.classList.add('active');
|
||||
}
|
||||
|
||||
async startWs() {
|
||||
@@ -593,6 +719,11 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.radioInfo) {
|
||||
this.handleRadioInfo(data.radioInfo.station, data.radioInfo.band, data.radioInfo.freq);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const [label, rotData] of Object.entries(data)) {
|
||||
const rot = this.rotators[label];
|
||||
if (!rot) continue;
|
||||
|
||||
Reference in New Issue
Block a user