@hadoku/game-ui 0.1.132 → 0.1.134

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,9 +19,8 @@
19
19
  *
20
20
  * A server-side close does not reconnect, so a taken tab never loops back into the room by itself.
21
21
  */
22
- import { io } from 'socket.io-client';
23
22
  import { SESSION_EVENTS, parseSessionAnswer, parseSessionTaken } from '@wolffm/rooms-protocol';
24
- import { socketOptions } from "./socket-options.js";
23
+ import { openSocket } from "./socket-options.js";
25
24
  import { settledTabId } from "./tab-id.js";
26
25
  export function roomSession(room, deps = {}) {
27
26
  const listeners = new Set();
@@ -58,7 +57,7 @@ export function roomSession(room, deps = {}) {
58
57
  if (closed)
59
58
  return;
60
59
  tabId = id;
61
- const s = (deps.connect ?? (() => io(socketOptions())))();
60
+ const s = (deps.connect ?? (() => openSocket()))();
62
61
  socket = s;
63
62
  s.on('connect', claim);
64
63
  s.on(SESSION_EVENTS.beat, (...args) => {
@@ -1,4 +1,5 @@
1
1
  import { type RoomSocketOptions } from '@wolffm/rooms-client';
2
+ import { type ManagerOptions, type Socket, type SocketOptions } from 'socket.io-client';
2
3
  /**
3
4
  * `/cardtable/` → `/cardtable/socket.io/`.
4
5
  *
@@ -15,3 +16,9 @@ export declare function defaultSocketPath(): string;
15
16
  * watchparty's sockets: `@wolffm/rooms-client`'s `roomSocketOptions`, whose header says why.
16
17
  */
17
18
  export declare function socketOptions(path?: string): RoomSocketOptions;
19
+ /**
20
+ * Every socket the page opens: socket.io's `io`, handed to the page's session watch
21
+ * (`@hadoku/ui-shell/session`), so a socket whose handshake the edge refuses because the session is
22
+ * gone stops reconnecting instead of trying every second forever. `url` omitted: same origin.
23
+ */
24
+ export declare function openSocket(settings?: Partial<ManagerOptions & SocketOptions>, url?: string): Socket;
@@ -1,9 +1,11 @@
1
1
  /*
2
- * How every socket on the page connects: its path under the bundle's base, and its transports and
3
- * reconnect pacing. Not any one game's: the draft, the match, the room feed and the room's session
4
- * claim all connect this way.
2
+ * How every socket on the page connects: its path under the bundle's base, its transports and
3
+ * reconnect pacing, and the page's session watch. Not any one game's: the draft, the match, the room
4
+ * feed, the room's session claim and a relay room all connect this way.
5
5
  */
6
6
  import { roomSocketOptions } from '@wolffm/rooms-client';
7
+ import { watchSocket } from '@wolffm/ui-shell/session';
8
+ import { io } from 'socket.io-client';
7
9
  /**
8
10
  * `/cardtable/` → `/cardtable/socket.io/`.
9
11
  *
@@ -28,3 +30,13 @@ export function defaultSocketPath() {
28
30
  export function socketOptions(path = defaultSocketPath()) {
29
31
  return roomSocketOptions(path);
30
32
  }
33
+ /**
34
+ * Every socket the page opens: socket.io's `io`, handed to the page's session watch
35
+ * (`@hadoku/ui-shell/session`), so a socket whose handshake the edge refuses because the session is
36
+ * gone stops reconnecting instead of trying every second forever. `url` omitted: same origin.
37
+ */
38
+ export function openSocket(settings = socketOptions(), url) {
39
+ const socket = url === undefined ? io(settings) : io(url, settings);
40
+ watchSocket(socket);
41
+ return socket;
42
+ }
@@ -19,10 +19,9 @@
19
19
  *
20
20
  * A hidden tab reads nothing. The server keeps the room offered meanwhile: the watch is presence.
21
21
  */
22
- import { io } from 'socket.io-client';
23
22
  import { ROOM_FEED_CHANNEL, parseRoomChanged } from '@wolffm/rooms-protocol';
24
23
  import { createFeedPings } from '@wolffm/rooms-client';
25
- import { socketOptions } from "../room/socket-options.js";
24
+ import { openSocket } from "../room/socket-options.js";
26
25
  import { documentVisibility, rereadWhileVisible } from "../visible.js";
27
26
  /**
28
27
  * How often a visible screen reads anyway. A lost ping costs at most this much staleness. Long,
@@ -51,7 +50,7 @@ let shared;
51
50
  function roomPings() {
52
51
  sharedPings ??= createFeedPings({
53
52
  wire: { channel: ROOM_FEED_CHANNEL, parseChanged: parseRoomChanged },
54
- connect: () => io(socketOptions()),
53
+ connect: () => openSocket(),
55
54
  });
56
55
  return sharedPings;
57
56
  }
@@ -15,8 +15,7 @@
15
15
  * out here too, but only because the SERVER drops it without an error — nothing here tracks
16
16
  * whether this socket holds a seat.
17
17
  */
18
- import { io } from 'socket.io-client';
19
- import { defaultSocketPath, socketOptions } from "../room/socket-options.js";
18
+ import { defaultSocketPath, openSocket, socketOptions } from "../room/socket-options.js";
20
19
  /**
21
20
  * Mirrors `packages/game-server/src/play/relay-socket.ts`'s own `RELAY_EVENTS`. The client has no package
22
21
  * of the server's to import these from (the server is not a dependency of the UI bundle), so the
@@ -36,7 +35,7 @@ function winnersOf(raw) {
36
35
  export function openRelayChannel(matchId, options = {}) {
37
36
  const path = options.path ?? defaultSocketPath();
38
37
  const settings = socketOptions(path);
39
- const socket = options.url === undefined ? io(settings) : io(options.url, settings);
38
+ const socket = openSocket(settings, options.url);
40
39
  const handlers = new Set();
41
40
  const endedHandlers = new Set();
42
41
  const resultHandlers = new Set();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hadoku/game-ui",
3
- "version": "0.1.132",
4
- "gitHead": "16eae682925e0213c00e296299605c51ac10ec45",
3
+ "version": "0.1.134",
4
+ "gitHead": "5ce3e147c511684342d92920c160be7aaa7a44d8",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "The browser parts any hosted game shares, above ui-shell: the room shell and session, seats and looks, the room route, the front page's generic pieces (gate, polls, gallery, patch notes), the bundle slot and relay channel a game's client mounts in, settings and trim screens, the HTTP and socket helpers, and the generic components (modal, popover, avatar, action button, radio cards). Knows no game; Magic's UI (games/magic/ui) plugs in, composed by the site (apps/ui). MIT; imports only react, react-dom, socket.io-client, @wolffm/* and the platform packages.",
@@ -54,8 +54,8 @@
54
54
  "react-dom": "^19.2.8"
55
55
  },
56
56
  "dependencies": {
57
- "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.136",
58
- "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.136",
57
+ "@wolffm/platform-wire": "npm:@hadoku/platform-wire@0.1.138",
58
+ "@wolffm/ui-shell": "npm:@hadoku/ui-shell@0.1.138",
59
59
  "@wolffm/prefs-client": "npm:@hadoku/prefs-client@^1.2.2",
60
60
  "@wolffm/rooms-client": "npm:@hadoku/rooms-client@^0.45.141",
61
61
  "@wolffm/rooms-protocol": "npm:@hadoku/rooms-protocol@^0.45.141",