mirror of
https://github.com/smittix/intercept.git
synced 2026-07-13 03:58:10 -07:00
Delay welcome page GPS and voice streams
This commit is contained in:
@@ -8,6 +8,7 @@ const VoiceAlerts = (function () {
|
|||||||
let _queue = [];
|
let _queue = [];
|
||||||
let _speaking = false;
|
let _speaking = false;
|
||||||
let _sources = {};
|
let _sources = {};
|
||||||
|
let _streamStartTimer = null;
|
||||||
const STORAGE_KEY = 'intercept-voice-muted';
|
const STORAGE_KEY = 'intercept-voice-muted';
|
||||||
const CONFIG_KEY = 'intercept-voice-config';
|
const CONFIG_KEY = 'intercept-voice-config';
|
||||||
const RATE_MIN = 0.5;
|
const RATE_MIN = 0.5;
|
||||||
@@ -132,7 +133,12 @@ const VoiceAlerts = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _startStreams() {
|
function _startStreams() {
|
||||||
|
if (_streamStartTimer) {
|
||||||
|
clearTimeout(_streamStartTimer);
|
||||||
|
_streamStartTimer = null;
|
||||||
|
}
|
||||||
if (!_enabled) return;
|
if (!_enabled) return;
|
||||||
|
if (Object.keys(_sources).length > 0) return;
|
||||||
|
|
||||||
// Pager stream
|
// Pager stream
|
||||||
if (_config.streams.pager) {
|
if (_config.streams.pager) {
|
||||||
@@ -173,17 +179,32 @@ const VoiceAlerts = (function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function _stopStreams() {
|
function _stopStreams() {
|
||||||
|
if (_streamStartTimer) {
|
||||||
|
clearTimeout(_streamStartTimer);
|
||||||
|
_streamStartTimer = null;
|
||||||
|
}
|
||||||
Object.values(_sources).forEach(es => { try { es.close(); } catch (_) {} });
|
Object.values(_sources).forEach(es => { try { es.close(); } catch (_) {} });
|
||||||
_sources = {};
|
_sources = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init(options) {
|
||||||
|
const opts = options || {};
|
||||||
_loadConfig();
|
_loadConfig();
|
||||||
if (_isSpeechSupported()) {
|
if (_isSpeechSupported()) {
|
||||||
// Prime voices list early so user-triggered test calls are less likely to be silent.
|
// Prime voices list early so user-triggered test calls are less likely to be silent.
|
||||||
speechSynthesis.getVoices();
|
speechSynthesis.getVoices();
|
||||||
}
|
}
|
||||||
_startStreams();
|
if (opts.startStreams !== false) {
|
||||||
|
_startStreams();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function scheduleStreamStart(delayMs) {
|
||||||
|
if (_streamStartTimer || Object.keys(_sources).length > 0 || !_enabled) return;
|
||||||
|
_streamStartTimer = window.setTimeout(() => {
|
||||||
|
_streamStartTimer = null;
|
||||||
|
_startStreams();
|
||||||
|
}, Number(delayMs) > 0 ? Number(delayMs) : 20000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setEnabled(val) {
|
function setEnabled(val) {
|
||||||
@@ -255,7 +276,7 @@ const VoiceAlerts = (function () {
|
|||||||
}, 1200);
|
}, 1200);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { init, speak, toggleMute, setEnabled, getConfig, setConfig, getAvailableVoices, testVoice, PRIORITY };
|
return { init, scheduleStreamStart, speak, toggleMute, setEnabled, getConfig, setConfig, getAvailableVoices, testVoice, PRIORITY };
|
||||||
})();
|
})();
|
||||||
|
|
||||||
window.VoiceAlerts = VoiceAlerts;
|
window.VoiceAlerts = VoiceAlerts;
|
||||||
|
|||||||
+51
-21
@@ -3892,6 +3892,8 @@
|
|||||||
// GPS Dongle state
|
// GPS Dongle state
|
||||||
let gpsConnected = false;
|
let gpsConnected = false;
|
||||||
let gpsEventSource = null;
|
let gpsEventSource = null;
|
||||||
|
let gpsAutoConnectTimer = null;
|
||||||
|
let gpsAutoConnectInFlight = null;
|
||||||
let gpsLastPosition = null;
|
let gpsLastPosition = null;
|
||||||
|
|
||||||
// Satellite state
|
// Satellite state
|
||||||
@@ -4090,8 +4092,8 @@
|
|||||||
if (obsLatInput) obsLatInput.value = observerLocation.lat.toFixed(4);
|
if (obsLatInput) obsLatInput.value = observerLocation.lat.toFixed(4);
|
||||||
if (obsLonInput) obsLonInput.value = observerLocation.lon.toFixed(4);
|
if (obsLonInput) obsLonInput.value = observerLocation.lon.toFixed(4);
|
||||||
|
|
||||||
// Auto-connect to gpsd if available
|
// Defer GPS auto-connect so it doesn't compete with initial dashboard navigation.
|
||||||
autoConnectGps();
|
scheduleGpsAutoConnect();
|
||||||
|
|
||||||
// Load pager message filters
|
// Load pager message filters
|
||||||
loadPagerFilters();
|
loadPagerFilters();
|
||||||
@@ -10851,26 +10853,51 @@
|
|||||||
// GPS FUNCTIONS (gpsd auto-connect)
|
// GPS FUNCTIONS (gpsd auto-connect)
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
async function autoConnectGps() {
|
function scheduleGpsAutoConnect(delayMs = 20000) {
|
||||||
// Automatically try to connect to gpsd on page load
|
if (gpsConnected || gpsAutoConnectInFlight || gpsAutoConnectTimer) return;
|
||||||
try {
|
gpsAutoConnectTimer = setTimeout(() => {
|
||||||
const response = await fetch('/gps/auto-connect', { method: 'POST' });
|
gpsAutoConnectTimer = null;
|
||||||
const data = await response.json();
|
autoConnectGps();
|
||||||
|
}, delayMs);
|
||||||
|
}
|
||||||
|
|
||||||
if (data.status === 'connected') {
|
async function autoConnectGps() {
|
||||||
gpsConnected = true;
|
if (gpsConnected) return true;
|
||||||
startGpsStream();
|
if (gpsAutoConnectTimer) {
|
||||||
showGpsIndicator(true);
|
clearTimeout(gpsAutoConnectTimer);
|
||||||
console.log('GPS: Auto-connected to gpsd');
|
gpsAutoConnectTimer = null;
|
||||||
if (data.position) {
|
|
||||||
updateLocationFromGps(data.position);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log('GPS: gpsd not available -', data.message);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.log('GPS: Auto-connect failed -', e.message);
|
|
||||||
}
|
}
|
||||||
|
if (gpsAutoConnectInFlight) {
|
||||||
|
return gpsAutoConnectInFlight;
|
||||||
|
}
|
||||||
|
|
||||||
|
gpsAutoConnectInFlight = (async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/gps/auto-connect', { method: 'POST' });
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data.status === 'connected') {
|
||||||
|
gpsConnected = true;
|
||||||
|
startGpsStream();
|
||||||
|
showGpsIndicator(true);
|
||||||
|
console.log('GPS: Auto-connected to gpsd');
|
||||||
|
if (data.position) {
|
||||||
|
updateLocationFromGps(data.position);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('GPS: gpsd not available -', data.message);
|
||||||
|
return false;
|
||||||
|
} catch (e) {
|
||||||
|
console.log('GPS: Auto-connect failed -', e.message);
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
gpsAutoConnectInFlight = null;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
return gpsAutoConnectInFlight;
|
||||||
}
|
}
|
||||||
|
|
||||||
let gpsReconnectTimeout = null;
|
let gpsReconnectTimeout = null;
|
||||||
@@ -16367,7 +16394,10 @@
|
|||||||
<script>
|
<script>
|
||||||
// Initialize global core modules after page load
|
// Initialize global core modules after page load
|
||||||
window.addEventListener('DOMContentLoaded', () => {
|
window.addEventListener('DOMContentLoaded', () => {
|
||||||
if (typeof VoiceAlerts !== 'undefined') VoiceAlerts.init();
|
if (typeof VoiceAlerts !== 'undefined') {
|
||||||
|
VoiceAlerts.init({ startStreams: false });
|
||||||
|
VoiceAlerts.scheduleStreamStart(20000);
|
||||||
|
}
|
||||||
if (typeof KeyboardShortcuts !== 'undefined') KeyboardShortcuts.init();
|
if (typeof KeyboardShortcuts !== 'undefined') KeyboardShortcuts.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user