Show live player presence and Captain/Gat roster badges
This commit is contained in:
@@ -26,6 +26,8 @@
|
||||
let playerId = params.pid;
|
||||
|
||||
let state = null;
|
||||
let onlinePlayerIds = null;
|
||||
$: rosterState = state ? { ...state, onlinePlayerIds } : null;
|
||||
let error = '';
|
||||
let intervalId;
|
||||
let ws = null;
|
||||
@@ -71,13 +73,18 @@
|
||||
// each ping triggers a refetch of the state blob.
|
||||
function connectSocket() {
|
||||
const proto = location.protocol === 'https:' ? 'wss' : 'ws';
|
||||
ws = new WebSocket(`${proto}://${location.host}/api/game/${gameId}/ws`);
|
||||
ws = new WebSocket(`${proto}://${location.host}/api/game/${gameId}/ws?player_id=${encodeURIComponent(playerId)}`);
|
||||
ws.onopen = () => {
|
||||
reconnectDelay = 1000;
|
||||
fetchState(); // catch up on anything missed while disconnected
|
||||
};
|
||||
ws.onmessage = () => fetchState();
|
||||
ws.onmessage = (event) => {
|
||||
const message = JSON.parse(event.data);
|
||||
if (message.type === 'presence') onlinePlayerIds = message.player_ids;
|
||||
else if (message.type === 'state_changed') fetchState();
|
||||
};
|
||||
ws.onclose = () => {
|
||||
onlinePlayerIds = null;
|
||||
if (destroyed || staleSession) return;
|
||||
reconnectTimer = setTimeout(connectSocket, reconnectDelay);
|
||||
reconnectDelay = Math.min(reconnectDelay * 2, 10000);
|
||||
@@ -224,10 +231,10 @@
|
||||
{#if state}
|
||||
<div class="dashboard-container {state.player.is_ghost ? 'ghost-world' : ''}">
|
||||
{#if state.game.phase === 'scene'}
|
||||
<ScenePhase {state} />
|
||||
<ScenePhase state={rosterState} />
|
||||
{:else}
|
||||
<div class="phase-view-layout" class:log-collapsed={!phaseLogOpen}>
|
||||
<CrewSidebar {state} />
|
||||
<CrewSidebar state={rosterState} />
|
||||
<main class="phase-main-column">
|
||||
{#if ['scene_setup', 'recruit_creation'].includes(state.game.phase) && (state.game.last_rank_up_player_id || state.game.current_scene_number > 1)}
|
||||
<div class="notice-banner" role="status">
|
||||
|
||||
Reference in New Issue
Block a user