Notify when another player plays a card
Add an opt-in bell to the game HUD: the first click asks for the browser's notification permission, and the choice is remembered per device. A play by any other seat then raises a desktop notification with the player's name, the card and the next player, while the page is in the background and the viewer is actually seated in the game. Detect the newest play across the game families: scopone and scopa report it in last_move, while briscola and briscola chiamata only expose the trick, which mid-trick or once completed ends with the card just played. The first snapshot after every (re)connection is a resync baseline, so reconnects and the initial load never replay old moves; so are the viewer's own plays and the server's auto-plays. Deliver through the service worker registration (installed PWAs on Android reject page-context notifications), falling back to a page notification when no worker is active, under a per-game tag that replaces the previous move. sw.js now focuses the game window when a notification is clicked.
This commit is contained in:
@@ -81,10 +81,10 @@ sees a "game not started yet" waiting room.
|
||||
|
||||
The frontend is an installable PWA: `web/manifest.webmanifest` describes
|
||||
the app (standalone display, felt theme colors, PNG icons), and `web/sw.js`
|
||||
is an install-only service worker — it deliberately caches nothing, since
|
||||
is a caching-free service worker — it deliberately caches nothing, since
|
||||
live state always comes from the server and hashed asset names change every
|
||||
build. Browsers offer to install Tavolo over HTTPS (or on localhost in
|
||||
development).
|
||||
build — that also handles clicks on move notifications. Browsers offer to
|
||||
install Tavolo over HTTPS (or on localhost in development).
|
||||
|
||||
Both files must be served from the site root, or the worker's scope and the
|
||||
manifest's `start_url` could not cover the app: Granian only serves
|
||||
@@ -94,6 +94,20 @@ same build directory as the shell. Icons are committed under
|
||||
`web/assets/icons/`; `web/make-icons.sh` regenerates them with
|
||||
`rsvg-convert` after editing the vector sources.
|
||||
|
||||
## Move notifications
|
||||
|
||||
Players can opt into desktop notifications for the other players' card
|
||||
plays with the bell in the game HUD (the first click asks for the browser
|
||||
permission; the preference is stored per device and applies to every
|
||||
game). Notifications only appear while the game tab is in the background
|
||||
or its window is unfocused — never while the player is watching the table
|
||||
— and only for games the viewer is seated in, never for their own plays.
|
||||
They are delivered through the service worker (so installed PWAs get them
|
||||
too) under a per-game tag, which replaces the previous move instead of
|
||||
stacking one notification per play; clicking one focuses the game tab.
|
||||
The game page must stay open to receive them, since that is where the
|
||||
live-play websocket lives.
|
||||
|
||||
## Development
|
||||
|
||||
Backend (from `server/`):
|
||||
|
||||
Reference in New Issue
Block a user