mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-15 16:19:30 -07:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13f08b62cc | ||
|
|
eacd82b4f4 | ||
|
|
91f669e828 | ||
|
|
cdbe3d968f | ||
|
|
0a388cdb83 |
3
.vscode/launch.json
vendored
3
.vscode/launch.json
vendored
@@ -15,6 +15,9 @@
|
||||
"**/*.min.js",
|
||||
"**/vendor/**"
|
||||
],
|
||||
"runtimeArgs": [
|
||||
"--autoplay-policy=no-user-gesture-required"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Data:stations",
|
||||
|
||||
@@ -129,6 +129,7 @@ Thanks to the WeatherStar community for providing these discussions to further e
|
||||
|
||||
* [Stream as FFMPEG](https://github.com/netbymatt/ws4kp/issues/37#issuecomment-2008491948)
|
||||
* [Weather like it's 1999](https://blog.scottlabs.io/2024/02/weather-like-its-1999/) Raspberry pi, streaming, music and CRT all combined into a complete solution.
|
||||
* [ws4channels](https://github.com/rice9797/ws4channels) A Dockerized Node.js application to stream WeatherStar 4000 data into Channels DVR using Puppeteer and FFmpeg.
|
||||
|
||||
## Customization
|
||||
A hook is provided as `/server/scripts/custom.js` to allow customizations to your own fork of this project, without accidentally pushing your customizations back upstream to the git repository. An sample file is provided at `/server/scripts/custom.sample.js` and should be renamed to `custom.js` activate it.
|
||||
|
||||
@@ -1150,7 +1150,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"city": "Tucsan",
|
||||
"city": "Tucson",
|
||||
"lat": 32.2216,
|
||||
"lon": -110.9698,
|
||||
"point": {
|
||||
|
||||
@@ -575,7 +575,7 @@
|
||||
"lon": -77.9447
|
||||
},
|
||||
{
|
||||
"city": "Tucsan",
|
||||
"city": "Tucson",
|
||||
"lat": 32.2216,
|
||||
"lon": -110.9698
|
||||
}
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "ws4kp",
|
||||
"version": "5.16.4",
|
||||
"version": "5.16.5",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "ws4kp",
|
||||
"version": "5.16.4",
|
||||
"version": "5.16.5",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"ejs": "^3.1.5",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ws4kp",
|
||||
"version": "5.16.4",
|
||||
"version": "5.16.5",
|
||||
"description": "Welcome to the WeatherStar 4000+ project page!",
|
||||
"main": "index.mjs",
|
||||
"type": "module",
|
||||
|
||||
@@ -1151,7 +1151,7 @@ const RegionalCities = [
|
||||
}
|
||||
},
|
||||
{
|
||||
"city": "Tucsan",
|
||||
"city": "Tucson",
|
||||
"lat": 32.2216,
|
||||
"lon": -110.9698,
|
||||
"point": {
|
||||
|
||||
@@ -130,6 +130,8 @@ class CurrentWeather extends WeatherDisplay {
|
||||
// make data available outside this class
|
||||
// promise allows for data to be requested before it is available
|
||||
async getCurrentWeather(stillWaiting) {
|
||||
// an external caller has requested data, set up auto reload
|
||||
this.setAutoReload();
|
||||
if (stillWaiting) this.stillWaitingCallbacks.push(stillWaiting);
|
||||
return new Promise((resolve) => {
|
||||
if (this.data) resolve(this.data);
|
||||
|
||||
@@ -139,6 +139,8 @@ class Hourly extends WeatherDisplay {
|
||||
// promise allows for data to be requested before it is available
|
||||
async getCurrentData(stillWaiting) {
|
||||
if (stillWaiting) this.stillWaitingCallbacks.push(stillWaiting);
|
||||
// an external caller has requested data, set up auto reload
|
||||
this.setAutoReload();
|
||||
return new Promise((resolve) => {
|
||||
if (this.data) resolve(this.data);
|
||||
// data not available, put it into the data callback queue
|
||||
|
||||
@@ -5,7 +5,12 @@ let playlist;
|
||||
let currentTrack = 0;
|
||||
let player;
|
||||
|
||||
const mediaPlaying = new Setting('mediaPlaying', 'Media Playing', 'boolean', false, null, true);
|
||||
const mediaPlaying = new Setting('mediaPlaying', {
|
||||
name: 'Media Playing',
|
||||
type: 'boolean',
|
||||
defaultValue: false,
|
||||
sticky: true,
|
||||
});
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// add the event handler to the page
|
||||
|
||||
@@ -8,27 +8,54 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const settings = { speed: { value: 1.0 } };
|
||||
|
||||
const init = () => {
|
||||
// create settings
|
||||
settings.wide = new Setting('wide', 'Widescreen', 'checkbox', false, wideScreenChange, true);
|
||||
settings.kiosk = new Setting('kiosk', 'Kiosk', 'checkbox', false, kioskChange, false);
|
||||
settings.speed = new Setting('speed', 'Speed', 'select', 1.0, null, true, [
|
||||
[0.5, 'Very Fast'],
|
||||
[0.75, 'Fast'],
|
||||
[1.0, 'Normal'],
|
||||
[1.25, 'Slow'],
|
||||
[1.5, 'Very Slow'],
|
||||
]);
|
||||
settings.units = new Setting('units', 'Units', 'select', 'us', unitChange, true, [
|
||||
['us', 'US'],
|
||||
['si', 'Metric'],
|
||||
]);
|
||||
settings.refreshTime = new Setting('refreshTime', 'Refresh Time', 'select', 600_000, null, false, [
|
||||
[30_000, 'TESTING'],
|
||||
[300_000, '5 minutes'],
|
||||
[600_000, '10 minutes'],
|
||||
[900_000, '15 minutes'],
|
||||
[1_800_000, '30 minutes'],
|
||||
]);
|
||||
// create settings see setting.mjs for defaults
|
||||
settings.wide = new Setting('wide', {
|
||||
name: 'Widescreen',
|
||||
defaultValue: false,
|
||||
changeAction: wideScreenChange,
|
||||
sticky: true,
|
||||
});
|
||||
settings.kiosk = new Setting('kiosk', {
|
||||
name: 'Kiosk',
|
||||
defaultValue: false,
|
||||
changeAction: kioskChange,
|
||||
sticky: false,
|
||||
});
|
||||
settings.speed = new Setting('speed', {
|
||||
name: 'Speed',
|
||||
type: 'select',
|
||||
defaultValue: 1.0,
|
||||
values: [
|
||||
[0.5, 'Very Fast'],
|
||||
[0.75, 'Fast'],
|
||||
[1.0, 'Normal'],
|
||||
[1.25, 'Slow'],
|
||||
[1.5, 'Very Slow'],
|
||||
],
|
||||
});
|
||||
settings.units = new Setting('units', {
|
||||
name: 'Units',
|
||||
type: 'select',
|
||||
defaultValue: 'us',
|
||||
changeAction: unitChange,
|
||||
values: [
|
||||
['us', 'US'],
|
||||
['si', 'Metric'],
|
||||
],
|
||||
});
|
||||
settings.refreshTime = new Setting('refreshTime', {
|
||||
type: 'select',
|
||||
defaultValue: 600_000,
|
||||
sticky: false,
|
||||
values: [
|
||||
[30_000, 'TESTING'],
|
||||
[300_000, '5 minutes'],
|
||||
[600_000, '10 minutes'],
|
||||
[900_000, '15 minutes'],
|
||||
[1_800_000, '30 minutes'],
|
||||
],
|
||||
visible: false,
|
||||
});
|
||||
|
||||
// generate html objects
|
||||
const settingHtml = Object.values(settings).map((d) => d.generate());
|
||||
|
||||
@@ -2,41 +2,58 @@ import { parseQueryString } from '../share.mjs';
|
||||
|
||||
const SETTINGS_KEY = 'Settings';
|
||||
|
||||
const DEFAULTS = {
|
||||
shortName: undefined,
|
||||
name: undefined,
|
||||
type: 'checkbox',
|
||||
defaultValue: undefined,
|
||||
changeAction: () => { },
|
||||
sticky: true,
|
||||
values: [],
|
||||
visible: true,
|
||||
};
|
||||
|
||||
class Setting {
|
||||
constructor(shortName, name, type, defaultValue, changeAction, sticky, values) {
|
||||
// store values
|
||||
constructor(shortName, _options) {
|
||||
if (shortName === undefined) {
|
||||
throw new Error('No name provided for setting');
|
||||
}
|
||||
// merge options with defaults
|
||||
const options = { ...DEFAULTS, ...(_options ?? {}) };
|
||||
|
||||
// store values and combine with defaults
|
||||
this.shortName = shortName;
|
||||
this.name = name;
|
||||
this.defaultValue = defaultValue;
|
||||
this.myValue = defaultValue;
|
||||
this.type = type ?? 'checkbox';
|
||||
this.sticky = sticky;
|
||||
this.values = values;
|
||||
// a default blank change function is provided
|
||||
this.changeAction = changeAction ?? (() => { });
|
||||
this.name = options.name ?? shortName;
|
||||
this.defaultValue = options.defaultValue;
|
||||
this.myValue = this.defaultValue;
|
||||
this.type = options?.type;
|
||||
this.sticky = options.sticky;
|
||||
this.values = options.values;
|
||||
this.visible = options.visible;
|
||||
this.changeAction = options.changeAction;
|
||||
|
||||
// get value from url
|
||||
const urlValue = parseQueryString()?.[`settings-${shortName}-${type}`];
|
||||
const urlValue = parseQueryString()?.[`settings-${shortName}-${this.type}`];
|
||||
let urlState;
|
||||
if (type === 'checkbox' && urlValue !== undefined) {
|
||||
if (this.type === 'checkbox' && urlValue !== undefined) {
|
||||
urlState = urlValue === 'true';
|
||||
}
|
||||
if (type === 'select' && urlValue !== undefined) {
|
||||
if (this.type === 'select' && urlValue !== undefined) {
|
||||
urlState = parseFloat(urlValue);
|
||||
}
|
||||
if (type === 'select' && urlValue !== undefined && Number.isNaN(urlState)) {
|
||||
if (this.type === 'select' && urlValue !== undefined && Number.isNaN(urlState)) {
|
||||
// couldn't parse as a float, store as a string
|
||||
urlState = urlValue;
|
||||
}
|
||||
|
||||
// get existing value if present
|
||||
const storedValue = urlState ?? this.getFromLocalStorage();
|
||||
if (sticky && storedValue !== null) {
|
||||
if ((this.sticky || urlValue !== undefined) && storedValue !== null) {
|
||||
this.myValue = storedValue;
|
||||
}
|
||||
|
||||
// call the change function on startup
|
||||
switch (type) {
|
||||
switch (this.type) {
|
||||
case 'select':
|
||||
this.selectChange({ target: { value: this.myValue } });
|
||||
break;
|
||||
@@ -142,6 +159,7 @@ class Setting {
|
||||
if (storedValue !== undefined) {
|
||||
switch (this.type) {
|
||||
case 'boolean':
|
||||
case 'checkbox':
|
||||
return storedValue;
|
||||
case 'select':
|
||||
return storedValue;
|
||||
@@ -187,6 +205,9 @@ class Setting {
|
||||
}
|
||||
|
||||
generate() {
|
||||
// don't generate a control for not visible items
|
||||
if (!this.visible) return '';
|
||||
// call the appropriate control generator
|
||||
switch (this.type) {
|
||||
case 'select':
|
||||
return this.generateSelect();
|
||||
|
||||
@@ -134,10 +134,9 @@ class WeatherDisplay {
|
||||
// refresh doesn't delete existing data, and is reused if the silent refresh fails
|
||||
if (!refresh) {
|
||||
this.data = undefined;
|
||||
// clear any refresh timers
|
||||
this.clearAutoReload();
|
||||
}
|
||||
// clear any refresh timers
|
||||
clearTimeout(this.autoRefreshHandle);
|
||||
this.autoRefreshHandle = null;
|
||||
|
||||
// store weatherParameters locally in case we need them later
|
||||
if (weatherParameters) this.weatherParameters = weatherParameters;
|
||||
@@ -150,8 +149,8 @@ class WeatherDisplay {
|
||||
return false;
|
||||
}
|
||||
|
||||
// set up auto reload
|
||||
this.autoRefreshHandle = setTimeout(() => this.getData(false, true), settings.refreshTime.value);
|
||||
// set up auto reload if necessary
|
||||
this.setAutoReload();
|
||||
|
||||
// recalculate navigation timing (in case it was modified in the constructor)
|
||||
this.calcNavTiming();
|
||||
@@ -435,6 +434,15 @@ class WeatherDisplay {
|
||||
this.stillWaitingCallbacks.forEach((callback) => callback());
|
||||
this.stillWaitingCallbacks = [];
|
||||
}
|
||||
|
||||
clearAutoReload() {
|
||||
clearInterval(this.autoRefreshHandle);
|
||||
this.autoRefreshHandle = null;
|
||||
}
|
||||
|
||||
setAutoReload() {
|
||||
this.autoRefreshHandle = this.autoRefreshHandle ?? setInterval(() => this.getData(false, true), settings.refreshTime.value);
|
||||
}
|
||||
}
|
||||
|
||||
export default WeatherDisplay;
|
||||
|
||||
Reference in New Issue
Block a user