V2.5 : VOICI LES MODIFICATIONS MAJEURS APPRTÉES DANS CETTE VERSION :
-> (BÉTA) : SYSTÈME D'ANNONCES EN GARE VIA UN MODEL IA DE SIMONE HERAULT. -> (BÉTA) : GÉNÉRATION AUTOMATIQUE DES ANNONCES POUR L'ENSEMBLE DES GARES EXISTANTES.
This commit is contained in:
1 parent
ad999aa44f
commit
0f7c271b1f
9 files changed
+52
-12
No files matched your search
@@ -1,16 +1,51 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import supabase from '../lib/supabase';
|
||||
|
||||
export default function useAnnonceSonoreRealtime(gareId) {
|
||||
// Helper pour normaliser le nom du quai pour comparaison robuste
|
||||
const normalizeQuai = (val) => {
|
||||
if (!val) return '';
|
||||
return String(val)
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, '')
|
||||
.replace(/voie/g, '')
|
||||
.replace(/quai/g, '');
|
||||
};
|
||||
|
||||
export default function useAnnonceSonoreRealtime(gareId, affType = null, quaiName = null) {
|
||||
const audioRef = useRef(null);
|
||||
const lastAnnonceIdRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!supabase || !gareId) return;
|
||||
|
||||
console.debug(`[useAnnonceSonoreRealtime] Setup for gareId: ${gareId}`);
|
||||
console.debug(`[useAnnonceSonoreRealtime] Setup for gareId: ${gareId}, type: ${affType}, quai: ${quaiName}`);
|
||||
|
||||
const playAnnonce = (newRecord) => {
|
||||
// 1. Déterminer les afficheurs cibles
|
||||
const variables = newRecord.annonce?.variables_values || {};
|
||||
const targetAfficheurs = variables.afficheurs || [];
|
||||
const trainQuai = variables.quai || '';
|
||||
|
||||
// Si targetAfficheurs est renseigné, filtrer
|
||||
if (affType && targetAfficheurs.length > 0) {
|
||||
const isTargeted = targetAfficheurs.includes(affType);
|
||||
if (!isTargeted) {
|
||||
console.debug(`[useAnnonceSonoreRealtime] Ignoré : cet afficheur (${affType}) n'est pas ciblé par l'annonce.`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Si l'afficheur est de type "Quais" (se termine par "Quais"), on vérifie la voie/quai
|
||||
const isQuaiDisplay = affType.toLowerCase().endsWith('quais');
|
||||
if (isQuaiDisplay && quaiName && trainQuai) {
|
||||
const normDisplayQuai = normalizeQuai(quaiName);
|
||||
const normTrainQuai = normalizeQuai(trainQuai);
|
||||
if (normDisplayQuai !== normTrainQuai) {
|
||||
console.debug(`[useAnnonceSonoreRealtime] Ignoré : voie non correspondante (Afficheur: ${quaiName}, Train: ${trainQuai})`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 1. Couper l'audio en cours de lecture
|
||||
if (audioRef.current) {
|
||||
try { audioRef.current.pause(); } catch (e) {}
|
||||
@@ -59,7 +94,12 @@ export default function useAnnonceSonoreRealtime(gareId) {
|
||||
try {
|
||||
const { data, error } = await supabase
|
||||
.from('annonces_diffusions')
|
||||
.select('*')
|
||||
.select(`
|
||||
*,
|
||||
annonce:annonces_enregistrees(
|
||||
variables_values
|
||||
)
|
||||
`)
|
||||
.eq('gare_id', gareId)
|
||||
.order('created_at', { ascending: false })
|
||||
.limit(1);
|
||||
@@ -106,5 +146,5 @@ export default function useAnnonceSonoreRealtime(gareId) {
|
||||
try { window.speechSynthesis.cancel(); } catch (e) {}
|
||||
}
|
||||
};
|
||||
}, [gareId]);
|
||||
}, [gareId, affType, quaiName]);
|
||||
}
|
||||
Reference in new issue
Block a user