Message when everyone is verified

This commit is contained in:
Frank
2026-01-08 15:34:43 +01:00
parent e4976e51fa
commit e42966e618
5 changed files with 70 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ import './styles/game1.css';
let sequenceFinished = false;
let stillPlayingSound = true;
function subscribeToMercure(mercurePublicUrl, topic) {
function subscribeToMercure(mercurePublicUrl, topic, myScreen) {
try {
const url = mercurePublicUrl + '?topic=' + encodeURIComponent(topic);
const es = new EventSource(url);
@@ -16,6 +16,13 @@ function subscribeToMercure(mercurePublicUrl, topic) {
// data is [sendTo, message]
if (Array.isArray(data) && data.length >= 2) {
const sendTo = parseInt(data[0]);
// Filter: 0 means everyone, otherwise must match myScreen
if (sendTo !== 0 && sendTo !== parseInt(myScreen)) {
console.log('[Mercure][game1] Message not for this player, skipping.');
return;
}
const messageContainer = document.getElementById('message-container');
if (messageContainer) {
const msgEl = document.createElement('div');
@@ -121,11 +128,12 @@ document.addEventListener('DOMContentLoaded', async () => {
const mercurePublicUrl = cfgEl.dataset.mercurePublicUrl;
const topic = cfgEl.dataset.topic;
const screen = cfgEl.dataset.screen;
const apiPingUrl = cfgEl.dataset.apiPingUrl;
const apiEchoUrl = cfgEl.dataset.apiEchoUrl;
if (mercurePublicUrl && topic) {
subscribeToMercure(mercurePublicUrl, topic);
subscribeToMercure(mercurePublicUrl, topic, screen);
} else {
console.warn('[Mercure][game1] Missing data attributes on #mercure-config');
}