Add randomized client identifier to reduce chance of grabbing the incorrect subscription ID

This commit is contained in:
G.Ambatte
2026-10-11 12:46:30 +13:00
parent 05a7750bd0
commit d7f579b308
3 changed files with 12 additions and 5 deletions
@@ -16,6 +16,7 @@ import request from '../../utils/request-middleware.js';
import { DEFAULT_BREW_LOAD } from '../../../../server/brewDefaults.js';
import { printCurrentBrew, fetchThemeBundle } from '@shared/helpers.js';
import { nanoid } from 'nanoid';
const SharePage = (props)=>{
const { disableMeta = false } = props;
@@ -53,14 +54,19 @@ const SharePage = (props)=>{
document.addEventListener('keydown', handleControlKeys);
fetchThemeBundle(undefined, setThemeBundle, currentBrew.renderer, currentBrew.theme);
// generate unique fingerprint
const clientFingerprint = nanoid(24);
// listen for changes in the brew version
const eventSource = new EventSource(`/api/stream/${props.brew.shareId}`);
const eventSource = new EventSource(`/api/stream/${props.brew.shareId}?client=${clientFingerprint}`);
let subId = '';
eventSource.addEventListener('subscribe', (evt)=>{
const messageData = JSON.parse(evt.data);
subId = messageData.id;
if(messageData.client == clientFingerprint){
subId = messageData.id;
}
});
eventSource.addEventListener('brewUpdated', (evt)=>{