Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions web/src/lib/pwa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ export function registerServiceWorker() {
})
}

/**
* Looks for a new version now. The room socket calls it when it connects
* again: a deploy restarts the server and drops every socket, so a box
* (which takes new versions by itself) is up to date within moments,
* not an hour later.
*/
export function checkForUpdate() {
if (!import.meta.env.PROD || !('serviceWorker' in navigator)) return
void navigator.serviceWorker
.getRegistration()
.then((reg) => reg?.update())
.catch(() => {})
}

/** Chromium's install prompt event, which TypeScript's DOM types lack. */
type InstallPromptEvent = Event & { prompt(): Promise<void>; userChoice: Promise<{ outcome: 'accepted' | 'dismissed' }> }

Expand Down
5 changes: 5 additions & 0 deletions web/src/lib/room-socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { gameRoundQuery, gameScoresQuery, type GameRound, type GameScores } from
import { guestPassQuery, guestsQuery } from './guests'
import { crown, heartsQuery, nightsQuery, type Hearts, type Night } from './nights'
import { newer, playbackQuery, type Playback } from './playback'
import { checkForUpdate } from './pwa'
import { putQueueGame, queueGamesQuery, type QueueGame } from './queue-games'
import { addReaction, type Reaction } from './reactions'
import { leaveRoom, queueQuery, roomsQuery, type QueueSnapshot, type Room } from './room'
Expand Down Expand Up @@ -68,6 +69,7 @@ export function useRoomSocket(roomId: string | undefined, { display = false, onS
let retry: ReturnType<typeof setTimeout> | undefined
let attempt = 0
let closed = false
let opened = false
live.set({ roomId, status: 'connecting', members: [] })

const connect = () => {
Expand All @@ -93,6 +95,9 @@ export function useRoomSocket(roomId: string | undefined, { display = false, onS
// as soon as it's connected, and whenever boxd says something new.
sock.onopen = () => {
if (reportBox && box.info) sendBoxStatus(sock, box.info)
// Back after a drop, maybe a deploy: there may be a new version.
if (opened) checkForUpdate()
opened = true
}
sock.onmessage = (e) => {
attempt = 0
Expand Down
Loading