Aggiunta stili CSS per Kiosk, struttura HTML per la Mappa e Riferimenti ai Sensori
• Creato un nuovo file CSS per gli stili del chiosco (kiosk) con variabili, stili per le schede (card) e animazioni. • Aggiunto un file HTML per l'interfaccia della mappa utilizzando Mapbox, inclusi gli stili e il JavaScript per le funzionalità della mappa. • Introdotto un file JSON per i riferimenti ai sensori, definendo percorsi ed elementi per i dati di temperatura, vento, onde, posizione, batteria, motore e sistema. Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
50
plugin/cores/realtime/auth.js
Normal file
50
plugin/cores/realtime/auth.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const configManager = require('../../config/configManager.js');
|
||||
const REALTIME_URL = process.env.REALTIME_URL;
|
||||
|
||||
/**
|
||||
* Autentica il sensore per connetterlo al server.
|
||||
* Il token viene inviato al server, che restituisce un token temporaneo per la connessione websocket.
|
||||
* @returns {Promise<{socketToken: string, sensorId: string, expiresIn: number}|null>}
|
||||
*/
|
||||
async function authenticate() {
|
||||
const SENSOR_CODE = configManager.getSensorCode();
|
||||
const SENSOR_NAME = configManager.getSensorName();
|
||||
|
||||
if (!REALTIME_URL || !SENSOR_CODE || !SENSOR_NAME) {
|
||||
console.error('[REALTIME|AUTH] REALTIME_URL, SENSOR_CODE o SENSOR_NAME non configurati');
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${REALTIME_URL}/connect`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
name: SENSOR_NAME,
|
||||
code: SENSOR_CODE
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const err = await response.json().catch(() => ({}));
|
||||
console.error(`[REALTIME|AUTH] auth error (${response.status}):`, err.error || 'unknown');
|
||||
return null;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
// Server risponde { s: 'ok', t: token }
|
||||
if (data.s !== 'ok' || !data.t) {
|
||||
console.error('[REALTIME|AUTH] Risposta inattesa:', data);
|
||||
return null;
|
||||
}
|
||||
|
||||
console.log(`[REALTIME|AUTH] Autenticato: ${SENSOR_NAME}, token valido 5s`);
|
||||
return { socketToken: data.t };
|
||||
|
||||
} catch (error) {
|
||||
console.error(`[REALTIME|AUTH] error: ${error.message}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { authenticate };
|
||||
Reference in New Issue
Block a user