feat: wire sticker mode state and WebSocket plumbing
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -32,6 +32,8 @@ function Picker() {
|
|||||||
const [error, setError] = useState('');
|
const [error, setError] = useState('');
|
||||||
const [showPopularity, setShowPopularity] = useState(true);
|
const [showPopularity, setShowPopularity] = useState(true);
|
||||||
const [sessionEnded, setSessionEnded] = useState(false);
|
const [sessionEnded, setSessionEnded] = useState(false);
|
||||||
|
const [stickerMode, setStickerMode] = useState('auto');
|
||||||
|
const stickerSendRef = useRef(null);
|
||||||
|
|
||||||
// Filters
|
// Filters
|
||||||
const [playerCount, setPlayerCount] = useState('');
|
const [playerCount, setPlayerCount] = useState('');
|
||||||
@@ -1294,6 +1296,8 @@ function Picker() {
|
|||||||
pollStartedAtRef={pollStartedAtRef}
|
pollStartedAtRef={pollStartedAtRef}
|
||||||
setSelectedGame={setSelectedGame}
|
setSelectedGame={setSelectedGame}
|
||||||
setGameSource={setGameSource}
|
setGameSource={setGameSource}
|
||||||
|
setStickerMode={setStickerMode}
|
||||||
|
stickerSendRef={stickerSendRef}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1301,7 +1305,7 @@ function Picker() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function SessionInfo({ sessionId, onGamesUpdate, playingGame, setPlayingGame, setHasPlayedGames, setLeadingGame, setPollActive, pollActiveRef, setPollResult, setPollEndingAt, setShowEndPollOptions, pollStartedAtRef, setSelectedGame, setGameSource }) {
|
function SessionInfo({ sessionId, onGamesUpdate, playingGame, setPlayingGame, setHasPlayedGames, setLeadingGame, setPollActive, pollActiveRef, setPollResult, setPollEndingAt, setShowEndPollOptions, pollStartedAtRef, setSelectedGame, setGameSource, setStickerMode, stickerSendRef }) {
|
||||||
const { isAuthenticated, token } = useAuth();
|
const { isAuthenticated, token } = useAuth();
|
||||||
const [games, setGames] = useState([]);
|
const [games, setGames] = useState([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
@@ -1392,6 +1396,13 @@ function SessionInfo({ sessionId, onGamesUpdate, playingGame, setPlayingGame, se
|
|||||||
ws.send(JSON.stringify({ type: 'ping' }));
|
ws.send(JSON.stringify({ type: 'ping' }));
|
||||||
}
|
}
|
||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
||||||
|
stickerSendRef.current = (mode) => {
|
||||||
|
if (ws.readyState === WebSocket.OPEN) {
|
||||||
|
ws.send(JSON.stringify({ type: 'stickers.setMode', data: { mode } }));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1467,6 +1478,11 @@ function SessionInfo({ sessionId, onGamesUpdate, playingGame, setPlayingGame, se
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (message.type === 'stickers.mode') {
|
||||||
|
setStickerMode(message.mode);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (reloadEvents.includes(message.type)) {
|
if (reloadEvents.includes(message.type)) {
|
||||||
console.log(`[WebSocket] ${message.type}:`, message.data);
|
console.log(`[WebSocket] ${message.type}:`, message.data);
|
||||||
if (message.type === 'game.added') {
|
if (message.type === 'game.added') {
|
||||||
@@ -1487,6 +1503,7 @@ function SessionInfo({ sessionId, onGamesUpdate, playingGame, setPlayingGame, se
|
|||||||
ws.onclose = () => {
|
ws.onclose = () => {
|
||||||
console.log('[WebSocket] Disconnected, reconnecting in 3s...');
|
console.log('[WebSocket] Disconnected, reconnecting in 3s...');
|
||||||
clearInterval(pingIntervalRef.current);
|
clearInterval(pingIntervalRef.current);
|
||||||
|
stickerSendRef.current = null;
|
||||||
reconnectTimeoutRef.current = setTimeout(connectWs, 3000);
|
reconnectTimeoutRef.current = setTimeout(connectWs, 3000);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -1495,7 +1512,7 @@ function SessionInfo({ sessionId, onGamesUpdate, playingGame, setPlayingGame, se
|
|||||||
console.error('[WebSocket] Failed to connect:', error);
|
console.error('[WebSocket] Failed to connect:', error);
|
||||||
reconnectTimeoutRef.current = setTimeout(connectWs, 3000);
|
reconnectTimeoutRef.current = setTimeout(connectWs, 3000);
|
||||||
}
|
}
|
||||||
}, [sessionId, token, loadGames, setPollActive, setPollResult, setPollEndingAt, setShowEndPollOptions, setLeadingGame, pollActiveRef, pollStartedAtRef, setSelectedGame, setGameSource]);
|
}, [sessionId, token, loadGames, setPollActive, setPollResult, setPollEndingAt, setShowEndPollOptions, setLeadingGame, pollActiveRef, pollStartedAtRef, setSelectedGame, setGameSource, setStickerMode, stickerSendRef]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
connectWs();
|
connectWs();
|
||||||
|
|||||||
Reference in New Issue
Block a user