onelobby 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +77 -2
- package/dist/chat.d.ts +60 -0
- package/dist/chat.js +163 -0
- package/dist/chat.js.map +1 -0
- package/dist/chunking.d.ts +17 -0
- package/dist/chunking.js +59 -0
- package/dist/chunking.js.map +1 -0
- package/dist/clock.d.ts +8 -0
- package/dist/clock.js +39 -0
- package/dist/clock.js.map +1 -0
- package/dist/codec.d.ts +141 -0
- package/dist/codec.js +308 -0
- package/dist/codec.js.map +1 -0
- package/dist/crockford.d.ts +14 -0
- package/dist/crockford.js +55 -0
- package/dist/crockford.js.map +1 -0
- package/dist/deflate.d.ts +4 -0
- package/dist/deflate.js +32 -0
- package/dist/deflate.js.map +1 -0
- package/dist/deprecated.d.ts +18 -0
- package/dist/deprecated.js +11 -0
- package/dist/deprecated.js.map +1 -0
- package/dist/direct/hub-host.d.ts +82 -0
- package/dist/direct/hub-host.js +393 -0
- package/dist/direct/hub-host.js.map +1 -0
- package/dist/direct/hub.d.ts +178 -0
- package/dist/direct/hub.js +862 -0
- package/dist/direct/hub.js.map +1 -0
- package/dist/direct/index.d.ts +57 -0
- package/dist/direct/index.js +71 -0
- package/dist/direct/index.js.map +1 -0
- package/dist/direct/portmap.d.ts +84 -0
- package/dist/direct/portmap.js +465 -0
- package/dist/direct/portmap.js.map +1 -0
- package/dist/direct-address.d.ts +20 -0
- package/dist/direct-address.js +61 -0
- package/dist/direct-address.js.map +1 -0
- package/dist/emitter.d.ts +9 -0
- package/dist/emitter.js +36 -0
- package/dist/emitter.js.map +1 -0
- package/dist/friendly.d.ts +20 -0
- package/dist/friendly.js +120 -0
- package/dist/friendly.js.map +1 -0
- package/dist/global.d.ts +8 -0
- package/dist/global.js +9 -0
- package/dist/global.js.map +1 -0
- package/dist/gridpaint.d.ts +27 -0
- package/dist/gridpaint.js +106 -0
- package/dist/gridpaint.js.map +1 -0
- package/dist/hub.d.ts +25 -0
- package/dist/hub.js +2 -0
- package/dist/hub.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/internals.d.ts +28 -0
- package/dist/internals.js +24 -0
- package/dist/internals.js.map +1 -0
- package/dist/joincode.d.ts +21 -0
- package/dist/joincode.js +84 -0
- package/dist/joincode.js.map +1 -0
- package/dist/lobby.d.ts +203 -0
- package/dist/lobby.js +840 -0
- package/dist/lobby.js.map +1 -0
- package/dist/lockstep.d.ts +132 -0
- package/dist/lockstep.js +471 -0
- package/dist/lockstep.js.map +1 -0
- package/dist/migration.d.ts +17 -0
- package/dist/migration.js +34 -0
- package/dist/migration.js.map +1 -0
- package/dist/onelobby.bundle.mjs +140 -0
- package/dist/onelobby.bundle.mjs.map +7 -0
- package/dist/onelobby.d.ts +151 -0
- package/dist/onelobby.global.js +3897 -0
- package/dist/onelobby.global.js.map +7 -0
- package/dist/onelobby.global.min.js +140 -0
- package/dist/onelobby.global.min.js.map +7 -0
- package/dist/onelobby.js +337 -0
- package/dist/onelobby.js.map +1 -0
- package/dist/signaling.d.ts +94 -0
- package/dist/signaling.js +134 -0
- package/dist/signaling.js.map +1 -0
- package/dist/socket.d.ts +63 -0
- package/dist/socket.js +142 -0
- package/dist/socket.js.map +1 -0
- package/dist/testing.d.ts +135 -0
- package/dist/testing.js +438 -0
- package/dist/testing.js.map +1 -0
- package/dist/transport.d.ts +80 -0
- package/dist/transport.js +7 -0
- package/dist/transport.js.map +1 -0
- package/dist/ui/controller.d.ts +137 -0
- package/dist/ui/controller.js +337 -0
- package/dist/ui/controller.js.map +1 -0
- package/dist/ui/element.d.ts +22 -0
- package/dist/ui/element.js +284 -0
- package/dist/ui/element.js.map +1 -0
- package/dist/ui/index.d.ts +5 -0
- package/dist/ui/index.js +9 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/server-url.d.ts +9 -0
- package/dist/ui/server-url.js +39 -0
- package/dist/ui/server-url.js.map +1 -0
- package/dist/ui/styles.d.ts +2 -0
- package/dist/ui/styles.js +70 -0
- package/dist/ui/styles.js.map +1 -0
- package/dist/voice-browser.d.ts +19 -0
- package/dist/voice-browser.js +151 -0
- package/dist/voice-browser.js.map +1 -0
- package/dist/voice-core.d.ts +98 -0
- package/dist/voice-core.js +233 -0
- package/dist/voice-core.js.map +1 -0
- package/dist/voice-types.d.ts +35 -0
- package/dist/voice-types.js +3 -0
- package/dist/voice-types.js.map +1 -0
- package/dist/voice.d.ts +68 -0
- package/dist/voice.js +223 -0
- package/dist/voice.js.map +1 -0
- package/dist/webrtc.d.ts +29 -0
- package/dist/webrtc.js +169 -0
- package/dist/webrtc.js.map +1 -0
- package/package.json +93 -4
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { type Clock } from "./clock.js";
|
|
2
|
+
import { Emitter } from "./emitter.js";
|
|
3
|
+
import { Lobby, type RateLimit } from "./lobby.js";
|
|
4
|
+
import { type LobbySummary } from "./signaling.js";
|
|
5
|
+
import { type LinkFactory, type SocketFactory } from "./transport.js";
|
|
6
|
+
import type { VoiceCodec, FrameSource, AudioSink } from "./voice-types.js";
|
|
7
|
+
export declare const LIB_NAME = "onelobby";
|
|
8
|
+
export declare const LIB_VERSION = "0.2.0";
|
|
9
|
+
/** Where `rememberSeat` keeps the resume token: the subset of the Web Storage API it uses. */
|
|
10
|
+
export interface SeatStorage {
|
|
11
|
+
getItem(key: string): string | null;
|
|
12
|
+
setItem(key: string, value: string): void;
|
|
13
|
+
removeItem(key: string): void;
|
|
14
|
+
}
|
|
15
|
+
/** Seams for tests, adapters and non-browser runtimes. Every default is the browser implementation. */
|
|
16
|
+
export interface AdvancedOptions {
|
|
17
|
+
socketFactory?: SocketFactory;
|
|
18
|
+
linkFactory?: LinkFactory;
|
|
19
|
+
clock?: Clock;
|
|
20
|
+
/** Wall clock in unix ms, stamps chat lines. */
|
|
21
|
+
wallClock?: () => number;
|
|
22
|
+
/** Opus codec; defaults to WebCodecs when available. Provide a WASM-backed one elsewhere. */
|
|
23
|
+
voiceCodec?: VoiceCodec | null;
|
|
24
|
+
createMic?: (() => FrameSource) | null;
|
|
25
|
+
createSink?: (() => AudioSink) | null;
|
|
26
|
+
/** Storage for `rememberSeat`; defaults to `sessionStorage` when the page has one. null disables it. */
|
|
27
|
+
storage?: SeatStorage | null;
|
|
28
|
+
}
|
|
29
|
+
export interface OneLobbyOptions {
|
|
30
|
+
gameId: string;
|
|
31
|
+
netVersion: string;
|
|
32
|
+
/** `ws://` / `wss://` URL of a onelobby-server. */
|
|
33
|
+
lobbyServer: string;
|
|
34
|
+
mode?: "lockstep" | "raw";
|
|
35
|
+
tickRate?: number;
|
|
36
|
+
/** Default: tickRate (once a second). */
|
|
37
|
+
hashEveryTicks?: number;
|
|
38
|
+
/** The player's name. Empty (the default): other players see "Player N", N being the seat number. */
|
|
39
|
+
displayName?: string;
|
|
40
|
+
relayOnly?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Joiners give up on reaching the host after this many ms: `lobby.ready` rejects with code `ice_failed`, the kit
|
|
43
|
+
* emits `error`, and the lobby is left. Half the time goes to a relay-only retry when the server offers TURN.
|
|
44
|
+
* Default 15000; 0 waits forever.
|
|
45
|
+
*/
|
|
46
|
+
readyTimeoutMs?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Treat a peer as gone after this many ms of silence. Joiners ping the host every 2 s and the host answers, so the
|
|
49
|
+
* host drops a silent joiner (`peerLeft`, "timeout") and a joiner handles a silent host as lost (a direct lobby
|
|
50
|
+
* ends with "host_left"). Default 0 (off): a silently dead peer then surfaces when its link or signaling socket
|
|
51
|
+
* times out, within about 30 s. Values under 6000 are raised to 6000.
|
|
52
|
+
*/
|
|
53
|
+
peerTimeoutMs?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Keep this tab's seat across a page reload (sessionStorage): `join(code)` and `resume()` take the seat back
|
|
56
|
+
* instead of joining as a new player. Cleared when the session ends. Default true where sessionStorage exists.
|
|
57
|
+
*/
|
|
58
|
+
rememberSeat?: boolean;
|
|
59
|
+
/** Test and runtime seams (see AdvancedOptions). */
|
|
60
|
+
advanced?: AdvancedOptions;
|
|
61
|
+
/** @deprecated use `advanced.socketFactory` */
|
|
62
|
+
socketFactory?: SocketFactory;
|
|
63
|
+
/** @deprecated use `advanced.linkFactory` */
|
|
64
|
+
linkFactory?: LinkFactory;
|
|
65
|
+
/** @deprecated use `advanced.clock` */
|
|
66
|
+
clock?: Clock;
|
|
67
|
+
/** @deprecated use `advanced.wallClock` */
|
|
68
|
+
wallClock?: () => number;
|
|
69
|
+
/** @deprecated use `advanced.voiceCodec` */
|
|
70
|
+
voiceCodec?: VoiceCodec | null;
|
|
71
|
+
/** @deprecated use `advanced.createMic` */
|
|
72
|
+
createMic?: (() => FrameSource) | null;
|
|
73
|
+
/** @deprecated use `advanced.createSink` */
|
|
74
|
+
createSink?: (() => AudioSink) | null;
|
|
75
|
+
}
|
|
76
|
+
export interface HostOptions {
|
|
77
|
+
name: string;
|
|
78
|
+
maxPlayers: number;
|
|
79
|
+
/**
|
|
80
|
+
* "unlisted" (default): anyone with the code or link can join, but the lobby is not in `list()`.
|
|
81
|
+
* "public": also listed. "private": the host approves each join.
|
|
82
|
+
*/
|
|
83
|
+
visibility?: "public" | "unlisted" | "private";
|
|
84
|
+
lateJoin?: boolean;
|
|
85
|
+
meta?: Record<string, string>;
|
|
86
|
+
/** Per-joiner cap on incoming raw messages, e.g. `{ messages: 60, perMs: 1000 }`; the excess is dropped before `message` fires or is relayed. */
|
|
87
|
+
rateLimit?: RateLimit;
|
|
88
|
+
}
|
|
89
|
+
export interface ListOptions {
|
|
90
|
+
meta?: Record<string, string>;
|
|
91
|
+
limit?: number;
|
|
92
|
+
cursor?: string;
|
|
93
|
+
}
|
|
94
|
+
export interface JoinDirectOptions {
|
|
95
|
+
/** The host's password, if it set one; a wrong one fails with `bad_password`. */
|
|
96
|
+
password?: string;
|
|
97
|
+
/** Port for an address typed without one (default 47810, docs/direct-ip.md s.2). */
|
|
98
|
+
defaultPort?: number;
|
|
99
|
+
/** No answer on the host's TCP port within this long fails with `direct_unreachable` (default 5000). */
|
|
100
|
+
connectTimeoutMs?: number;
|
|
101
|
+
}
|
|
102
|
+
/** @internal How onelobby/direct makes a host lobby: its own socket and link factory, and direct mode. */
|
|
103
|
+
export interface DirectLobbyHooks {
|
|
104
|
+
socketFactory: SocketFactory;
|
|
105
|
+
/** Wraps the kit's own link factory (port pin, no ICE servers). */
|
|
106
|
+
wrapLinks: (inner: LinkFactory) => LinkFactory;
|
|
107
|
+
}
|
|
108
|
+
export type OneLobbyEvents = {
|
|
109
|
+
error: [Error];
|
|
110
|
+
};
|
|
111
|
+
export declare const DEFAULT_READY_TIMEOUT_MS = 15000;
|
|
112
|
+
/** Entry point (DESIGN s.11.2). */
|
|
113
|
+
export declare class OneLobby extends Emitter<OneLobbyEvents> {
|
|
114
|
+
readonly options: Required<Pick<OneLobbyOptions, "gameId" | "netVersion" | "lobbyServer" | "mode" | "tickRate" | "hashEveryTicks" | "displayName" | "relayOnly" | "readyTimeoutMs" | "peerTimeoutMs">>;
|
|
115
|
+
private socketFactory;
|
|
116
|
+
private linkFactory;
|
|
117
|
+
private clock;
|
|
118
|
+
private wall;
|
|
119
|
+
private voiceCodec;
|
|
120
|
+
private createMic;
|
|
121
|
+
private createSink;
|
|
122
|
+
private storage;
|
|
123
|
+
constructor(o: OneLobbyOptions);
|
|
124
|
+
private get seatKey();
|
|
125
|
+
private loadSeat;
|
|
126
|
+
private saveSeat;
|
|
127
|
+
private clearSeat;
|
|
128
|
+
/** The lobby code of the seat this tab can take back (rememberSeat), or null. */
|
|
129
|
+
get rememberedCode(): string | null;
|
|
130
|
+
/**
|
|
131
|
+
* Take back the seat remembered from before a page reload (host or joiner). Resolves null when there is none
|
|
132
|
+
* or the server no longer holds it (the seat is forgotten then).
|
|
133
|
+
*/
|
|
134
|
+
resume(): Promise<Lobby | null>;
|
|
135
|
+
private helloMsg;
|
|
136
|
+
private connect;
|
|
137
|
+
private makeLobby;
|
|
138
|
+
host(h: HostOptions): Promise<Lobby>;
|
|
139
|
+
join(code: string): Promise<Lobby>;
|
|
140
|
+
/**
|
|
141
|
+
* Join a direct-IP host (docs/direct-ip.md): a join code from the host's screen (`6B01-RGFE-P2B`, any case, spaces
|
|
142
|
+
* or hyphens) or, advanced, an address (`ip`, `ip:port`, `[v6]:port`). No lobby server is involved: the code is
|
|
143
|
+
* the host's address. A mistyped code fails at once with `bad_code`; nobody listening is `direct_unreachable`.
|
|
144
|
+
* The address is also given to ICE as the host's UDP candidate. When the host leaves, `sessionEnded("host_left")`.
|
|
145
|
+
*/
|
|
146
|
+
joinDirect(codeOrAddress: string, opts?: JoinDirectOptions): Promise<Lobby>;
|
|
147
|
+
/** @internal onelobby/direct's host: create the one lobby on the embedded hub, in direct mode. */
|
|
148
|
+
hostDirectWith(h: HostOptions, hooks: DirectLobbyHooks): Promise<Lobby>;
|
|
149
|
+
rejoin(resumeToken: string): Promise<Lobby>;
|
|
150
|
+
list(opts?: ListOptions): Promise<LobbySummary[]>;
|
|
151
|
+
}
|