onelobby 0.5.0 → 0.7.0

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.
Files changed (109) hide show
  1. package/README.md +2 -2
  2. package/blueprint.schema.json +8 -1
  3. package/dist/blueprint.d.ts +4 -0
  4. package/dist/blueprint.js +5 -0
  5. package/dist/blueprint.js.map +1 -1
  6. package/dist/codec.d.ts +23 -0
  7. package/dist/codec.js +28 -0
  8. package/dist/codec.js.map +1 -1
  9. package/dist/direct/browser-host.d.ts +46 -0
  10. package/dist/direct/browser-host.js +93 -0
  11. package/dist/direct/browser-host.js.map +1 -0
  12. package/dist/direct/hub-host.d.ts +34 -23
  13. package/dist/direct/hub-host.js +75 -59
  14. package/dist/direct/hub-host.js.map +1 -1
  15. package/dist/direct/hub-local.d.ts +22 -0
  16. package/dist/direct/hub-local.js +46 -0
  17. package/dist/direct/hub-local.js.map +1 -0
  18. package/dist/direct/hub.d.ts +39 -10
  19. package/dist/direct/hub.js +134 -24
  20. package/dist/direct/hub.js.map +1 -1
  21. package/dist/direct/index.d.ts +36 -3
  22. package/dist/direct/index.js +146 -20
  23. package/dist/direct/index.js.map +1 -1
  24. package/dist/direct/metrics.d.ts +12 -0
  25. package/dist/direct/metrics.js +45 -0
  26. package/dist/direct/metrics.js.map +1 -0
  27. package/dist/direct/portmap.d.ts +9 -2
  28. package/dist/direct/portmap.js +7 -2
  29. package/dist/direct/portmap.js.map +1 -1
  30. package/dist/direct/sha1.d.ts +16 -0
  31. package/dist/direct/sha1.js +111 -0
  32. package/dist/direct/sha1.js.map +1 -0
  33. package/dist/direct-address.d.ts +2 -2
  34. package/dist/direct-address.js.map +1 -1
  35. package/dist/friendly.d.ts +24 -0
  36. package/dist/friendly.js +30 -0
  37. package/dist/friendly.js.map +1 -1
  38. package/dist/index.d.ts +8 -4
  39. package/dist/index.js +6 -4
  40. package/dist/index.js.map +1 -1
  41. package/dist/internals.d.ts +9 -0
  42. package/dist/internals.js +9 -0
  43. package/dist/internals.js.map +1 -1
  44. package/dist/join-code-kind.d.ts +10 -0
  45. package/dist/join-code-kind.js +10 -0
  46. package/dist/join-code-kind.js.map +1 -0
  47. package/dist/joincode.d.ts +10 -1
  48. package/dist/joincode.js +23 -3
  49. package/dist/joincode.js.map +1 -1
  50. package/dist/lobby.d.ts +94 -5
  51. package/dist/lobby.js +177 -18
  52. package/dist/lobby.js.map +1 -1
  53. package/dist/lockstep.d.ts +8 -0
  54. package/dist/lockstep.js +23 -2
  55. package/dist/lockstep.js.map +1 -1
  56. package/dist/nostr/crypto.d.ts +20 -0
  57. package/dist/nostr/crypto.js +78 -0
  58. package/dist/nostr/crypto.js.map +1 -0
  59. package/dist/nostr/host.d.ts +66 -0
  60. package/dist/nostr/host.js +196 -0
  61. package/dist/nostr/host.js.map +1 -0
  62. package/dist/nostr/limits.d.ts +33 -0
  63. package/dist/nostr/limits.js +38 -0
  64. package/dist/nostr/limits.js.map +1 -0
  65. package/dist/nostr/link.d.ts +70 -0
  66. package/dist/nostr/link.js +180 -0
  67. package/dist/nostr/link.js.map +1 -0
  68. package/dist/nostr/relays.d.ts +79 -0
  69. package/dist/nostr/relays.js +325 -0
  70. package/dist/nostr/relays.js.map +1 -0
  71. package/dist/nostr/room.d.ts +43 -0
  72. package/dist/nostr/room.js +104 -0
  73. package/dist/nostr/room.js.map +1 -0
  74. package/dist/nostr/secp256k1.d.ts +10 -0
  75. package/dist/nostr/secp256k1.js +171 -0
  76. package/dist/nostr/secp256k1.js.map +1 -0
  77. package/dist/nostr/socket.d.ts +48 -0
  78. package/dist/nostr/socket.js +141 -0
  79. package/dist/nostr/socket.js.map +1 -0
  80. package/dist/onelobby.bundle.js +146 -0
  81. package/dist/onelobby.bundle.js.map +7 -0
  82. package/dist/onelobby.bundle.mjs +11 -5
  83. package/dist/onelobby.bundle.mjs.map +4 -4
  84. package/dist/onelobby.d.ts +31 -3
  85. package/dist/onelobby.global.js +2673 -60
  86. package/dist/onelobby.global.js.map +4 -4
  87. package/dist/onelobby.global.min.js +11 -5
  88. package/dist/onelobby.global.min.js.map +4 -4
  89. package/dist/onelobby.js +77 -14
  90. package/dist/onelobby.js.map +1 -1
  91. package/dist/pause.d.ts +85 -0
  92. package/dist/pause.js +160 -0
  93. package/dist/pause.js.map +1 -0
  94. package/dist/signaling.d.ts +2 -0
  95. package/dist/signaling.js.map +1 -1
  96. package/dist/socket.d.ts +15 -6
  97. package/dist/socket.js.map +1 -1
  98. package/dist/testing.d.ts +2 -0
  99. package/dist/testing.js +18 -2
  100. package/dist/testing.js.map +1 -1
  101. package/dist/transport.d.ts +5 -1
  102. package/dist/transport.js.map +1 -1
  103. package/dist/webrtc.d.ts +6 -0
  104. package/dist/webrtc.js +27 -3
  105. package/dist/webrtc.js.map +1 -1
  106. package/package.json +1 -1
  107. package/dist/deprecated.d.ts +0 -18
  108. package/dist/deprecated.js +0 -11
  109. package/dist/deprecated.js.map +0 -1
@@ -4,9 +4,11 @@ import { Lobby, type RateLimit } from "./lobby.js";
4
4
  import { type LobbySummary } from "./signaling.js";
5
5
  import { type LinkFactory, type SocketFactory } from "./transport.js";
6
6
  import type { VoiceCodec, FrameSource, AudioSink } from "./voice-types.js";
7
+ import { type RelayConnect } from "./nostr/relays.js";
7
8
  import { type Blueprint } from "./blueprint.js";
9
+ import { type BrowserHostOptions } from "./direct/browser-host.js";
8
10
  export declare const LIB_NAME = "onelobby";
9
- export declare const LIB_VERSION = "0.5.0";
11
+ export declare const LIB_VERSION = "0.7.0";
10
12
  /** Where `rememberSeat` keeps the resume token: the subset of the Web Storage API it uses. */
11
13
  export interface SeatStorage {
12
14
  getItem(key: string): string | null;
@@ -26,6 +28,8 @@ export interface AdvancedOptions {
26
28
  createSink?: (() => AudioSink) | null;
27
29
  /** Storage for `rememberSeat`; defaults to `sessionStorage` when the page has one. null disables it. */
28
30
  storage?: SeatStorage | null;
31
+ /** WebSocket to a Nostr relay (default: the runtime's `WebSocket`); for Node older than 22 or tests. */
32
+ nostrConnect?: RelayConnect;
29
33
  }
30
34
  export interface OneLobbyOptions {
31
35
  gameId: string;
@@ -105,10 +109,14 @@ export interface ListOptions {
105
109
  export interface JoinDirectOptions {
106
110
  /** The host's password, if it set one; a wrong one fails with `bad_password`. */
107
111
  password?: string;
108
- /** Port for an address typed without one (default 47810, docs/direct-ip.md s.2). */
112
+ /** Port for an address typed without one (default 47810, docs/design/direct-ip.md s.2). */
109
113
  defaultPort?: number;
110
114
  /** No answer on the host's TCP port within this long fails with `direct_unreachable` (default 5000). */
111
115
  connectTimeoutMs?: number;
116
+ /** Nostr relays for a Nostr code (version 1); default the blueprint's `hosting.nostrRelays`, else the library list. */
117
+ nostrRelays?: string[];
118
+ /** STUN servers for a Nostr code when the host offers none; default Google's and Cloudflare's public ones. */
119
+ stun?: string[];
112
120
  }
113
121
  /** @internal How onelobby/direct makes a host lobby: its own socket and link factory, and direct mode. */
114
122
  export interface DirectLobbyHooks {
@@ -131,6 +139,7 @@ export declare class OneLobby extends Emitter<OneLobbyEvents> {
131
139
  private createMic;
132
140
  private createSink;
133
141
  private storage;
142
+ private nostrConnectFn;
134
143
  /** The validated, frozen onelobby.json this kit was built from (`OneLobby.fromConfig`); undefined for `new OneLobby`. */
135
144
  readonly blueprint?: Blueprint;
136
145
  /**
@@ -162,7 +171,7 @@ export declare class OneLobby extends Emitter<OneLobbyEvents> {
162
171
  host(opts?: Partial<HostOptions>): Promise<Lobby>;
163
172
  join(code: string): Promise<Lobby>;
164
173
  /**
165
- * Join a direct-IP host (docs/direct-ip.md): a join code from the host's screen (`6B01-RGFE-P2B`, any case, spaces
174
+ * Join a direct-IP host (docs/design/direct-ip.md): a join code from the host's screen (`6B01-RGFE-P2B`, any case, spaces
166
175
  * or hyphens) or, advanced, an address (`ip`, `ip:port`, `[v6]:port`). No lobby server is involved: the code is
167
176
  * the host's address. A mistyped code fails at once with `bad_code`; nobody listening is `direct_unreachable`.
168
177
  * The address is also given to ICE as the host's UDP candidate. When the host leaves, `sessionEnded("host_left")`.
@@ -174,9 +183,28 @@ export declare class OneLobby extends Emitter<OneLobbyEvents> {
174
183
  * same peer id comes back. Rejects with `invalid_token` when the seat is gone: offer `joinDirect` then.
175
184
  */
176
185
  rejoinDirect(codeOrAddress: string, resumeToken: string, opts?: JoinDirectOptions): Promise<Lobby>;
186
+ private nostrFactory;
187
+ /** Opens the signaling socket of a direct target: TCP to the host's address, or Nostr relays for a version 1 code. */
188
+ private connectDirect;
189
+ /** A Nostr joiner needs STUN; take the host's list (it comes in `welcome`), else the public defaults. */
190
+ private withStun;
177
191
  private directTarget;
192
+ /** @internal onelobby/direct's Nostr host: the relay seam and the kit's clocks. */
193
+ nostrHostEnv(): {
194
+ connect: RelayConnect | undefined;
195
+ clock: Clock;
196
+ wall: () => number;
197
+ };
178
198
  /** @internal onelobby/direct's host: create the one lobby on the embedded hub, in direct mode. */
179
199
  hostDirectWith(h: HostOptions, hooks: DirectLobbyHooks): Promise<Lobby>;
200
+ /**
201
+ * Host a direct lobby from this browser tab (or any runtime with WebSocket and WebRTC): no Node process, no port.
202
+ * The hub runs in the page and joiners find it through Nostr relays with `lobby.joinCode` (a dc1 version 1 code,
203
+ * `joinCodeKind` "nostr"); they use `kit.joinDirect(code)`. Rejects with `direct_unreachable` when no relay answers
204
+ * within 10 s (a browser has no IP fallback) and `nostr_disabled` when the blueprint has `hosting.nostr` false.
205
+ * Keep the tab visible: hidden tabs are throttled (`lobby.hostHidden`, event `hostHiddenChanged`).
206
+ */
207
+ hostNostr(opts?: BrowserHostOptions): Promise<Lobby>;
180
208
  rejoin(resumeToken: string): Promise<Lobby>;
181
209
  private resumeAt;
182
210
  list(opts?: ListOptions): Promise<LobbySummary[]>;