ball2d 0.0.2 → 0.1.1
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/README.md +144 -16
- package/dist/browser.js +4051 -0
- package/dist/core.wasm +0 -0
- package/dist/licenses/fflate.txt +21 -0
- package/dist/licenses/json5.txt +23 -0
- package/dist/licenses/native.json +236 -0
- package/dist/licenses/werift.txt +21 -0
- package/dist/node.js +43399 -0
- package/dist/stadiums/big.hbs +85 -0
- package/dist/stadiums/big_easy.hbs +85 -0
- package/dist/stadiums/big_hockey.hbs +87 -0
- package/dist/stadiums/big_rounded.hbs +100 -0
- package/dist/stadiums/classic.hbs +85 -0
- package/dist/stadiums/easy.hbs +85 -0
- package/dist/stadiums/hockey.hbs +87 -0
- package/dist/stadiums/huge.hbs +85 -0
- package/dist/stadiums/provenance.json +46 -0
- package/dist/stadiums/rounded.hbs +100 -0
- package/dist/stadiums/small.hbs +85 -0
- package/dist/types/client/announcement.d.ts +10 -0
- package/dist/types/client/connection-stats.d.ts +11 -0
- package/dist/types/client/headless.d.ts +130 -0
- package/dist/types/client/host-config.d.ts +11 -0
- package/dist/types/client/host-runtime.d.ts +10 -0
- package/dist/types/client/network-runtime.d.ts +8 -0
- package/dist/types/client/network.d.ts +91 -0
- package/dist/types/client/stadium-library.d.ts +4 -0
- package/dist/types/client/startup-scope.d.ts +6 -0
- package/dist/types/client/traffic.d.ts +9 -0
- package/dist/types/core/avatar.d.ts +2 -0
- package/dist/types/core/build-id.d.ts +2 -0
- package/dist/types/core/control.d.ts +5 -0
- package/dist/types/core/disc-properties.d.ts +7 -0
- package/dist/types/core/engine.d.ts +68 -0
- package/dist/types/core/host-types.d.ts +21 -0
- package/dist/types/core/match-state.d.ts +17 -0
- package/dist/types/core/protocol.d.ts +24 -0
- package/dist/types/core/replay-codec.d.ts +6 -0
- package/dist/types/core/replay-types.d.ts +41 -0
- package/dist/types/core/replay-wire.d.ts +5 -0
- package/dist/types/core/replay.d.ts +48 -0
- package/dist/types/core/stadium.d.ts +91 -0
- package/dist/types/core/team-colors.d.ts +8 -0
- package/dist/types/sdk/browser.d.ts +11 -0
- package/dist/types/sdk/command-queue.d.ts +11 -0
- package/dist/types/sdk/config.d.ts +6 -0
- package/dist/types/sdk/create-options.d.ts +4 -0
- package/dist/types/sdk/node-transport.d.ts +4 -0
- package/dist/types/sdk/node.d.ts +18 -0
- package/dist/types/sdk/replay.d.ts +4 -0
- package/dist/types/sdk/room.d.ts +7 -0
- package/dist/types/sdk/stadium.d.ts +9 -0
- package/dist/types/sdk/types.d.ts +78 -0
- package/dist/types/shared/room-link.d.ts +6 -0
- package/package.json +21 -13
package/README.md
CHANGED
|
@@ -1,27 +1,155 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Ball2D SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
```ts
|
|
4
|
+
import { createRoom, type RoomConfig } from 'ball2d';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
const config: RoomConfig = { roomName: 'My room', noPlayer: true };
|
|
7
|
+
const room = await createRoom(config);
|
|
8
|
+
room.onPlayerJoin = (player) => room.setPlayerTeam(player.id, 1);
|
|
9
|
+
await room.startGame();
|
|
10
|
+
// When the host is finished:
|
|
11
|
+
// room.close();
|
|
12
|
+
```
|
|
6
13
|
|
|
7
|
-
This
|
|
14
|
+
This initial entry runs in a browser on an origin serving the matching Ball2D
|
|
15
|
+
Worker API, WASM and stadium assets. The separate experimental `ball2d/node` entry provides native Node hosting. The
|
|
16
|
+
browser entry does not provide remote-origin hosting or an isolated plugin runtime.
|
|
17
|
+
Importing it does not register a window global or allocate a room. Creating a
|
|
18
|
+
room explicitly starts the existing browser host and its network lifecycle.
|
|
8
19
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
| npm package | [npmjs.com/package/ball2d](https://www.npmjs.com/package/ball2d) |
|
|
12
|
-
| Product website | [ball2d.com](https://ball2d.com) |
|
|
13
|
-
| Publisher | [Fillbyte](https://fillbyte.com) |
|
|
20
|
+
`RoomConfig`, `Room`, `HostPlayer`, `HostScores` and `HostDiscProperties` are exported
|
|
21
|
+
types. `readReplay` reads Ball2D recordings.
|
|
14
22
|
|
|
15
|
-
|
|
23
|
+
State-changing SDK commands return Promises and run in call order. A synchronous
|
|
24
|
+
getter immediately after a command still observes the earlier state; await the
|
|
25
|
+
command before reading its result. Inputs are copied at call time. Up to 256
|
|
26
|
+
commands may wait; overflow rejects without dropping accepted work. Live command
|
|
27
|
+
errors also reach `onError`; cancellation and calls after closure only reject their
|
|
28
|
+
Promises. `close()` immediately rejects pending SDK work and closes the
|
|
29
|
+
host; it does not undo operations already applied remotely. Getters and recording
|
|
30
|
+
start/stop remain synchronous. Chat filters must synchronously return false.
|
|
31
|
+
Callbacks receive the SDK facade as `this`; engine/network internals are not
|
|
32
|
+
part of that facade. This is an API boundary, not a sandbox for untrusted code.
|
|
16
33
|
|
|
17
|
-
|
|
34
|
+
`createRoom()` accepts omitted options. Defaults are a private room named
|
|
35
|
+
`Headless Room`, capacity 12, and an admin host player named `Host`. Set
|
|
36
|
+
`noPlayer: true` for an unattended playerless room and `public: true` to list it.
|
|
37
|
+
Integer capacity is clamped to 2–30; malformed numeric or privacy values reject
|
|
38
|
+
before engine/network allocation. Omitted/null optional default fields resolve
|
|
39
|
+
to defaults. The standalone `/headless` and `/headless.html` pages have been
|
|
40
|
+
retired; import the SDK instead. No `window.Ball2D` global is registered.
|
|
18
41
|
|
|
19
|
-
|
|
42
|
+
Version 0.1.0 is the first functional SDK release. For native hosting use Node.js
|
|
43
|
+
24 and the `ball2d/node` entry below. This is an early API; the native transport
|
|
44
|
+
remains experimental and the acceptance limits below still apply.
|
|
20
45
|
|
|
21
|
-
|
|
46
|
+
Validate a stadium before allocating a room:
|
|
22
47
|
|
|
23
|
-
|
|
48
|
+
```ts
|
|
49
|
+
import { validateStadium } from 'ball2d';
|
|
24
50
|
|
|
25
|
-
|
|
51
|
+
const report = validateStadium('{name:"Training", canBeStored:false}');
|
|
52
|
+
console.log(report.name, report.canBeStored, report.warnings);
|
|
53
|
+
```
|
|
26
54
|
|
|
27
|
-
|
|
55
|
+
`validateStadium(source)` is synchronous and works without browser globals,
|
|
56
|
+
network requests or a WASM instance. It uses the same parser and limits as room
|
|
57
|
+
creation. Malformed/unsupported input throws; ignored field names become bounded
|
|
58
|
+
warnings. The returned `StadiumValidation` and warning array are readonly and
|
|
59
|
+
frozen. No geometry or internal engine objects are exposed. Passing validation
|
|
60
|
+
means Ball2D can parse the source; it does not guarantee every gameplay outcome.
|
|
61
|
+
Use the separate `ball2d/node` entry for native room hosting.
|
|
62
|
+
|
|
63
|
+
`room.signal` is a readonly `AbortSignal` that aborts once when host closure
|
|
64
|
+
begins, including a fatal transport closure. Use it to cancel your own room-bound
|
|
65
|
+
work. It signals cancellation, not completion of every cleanup operation. Pending
|
|
66
|
+
SDK commands are cancelled from the same signal; cancellation never reenters the
|
|
67
|
+
room's error callback. A terminal transport error can still be reported once.
|
|
68
|
+
|
|
69
|
+
SDK `setScoreLimit` and `setTimeLimit` clamp integer arguments to 0–99 (goals
|
|
70
|
+
and minutes respectively); zero disables that limit. Await them before reading
|
|
71
|
+
updated state. Active-match calls remain no-ops. Non-integer or non-numeric
|
|
72
|
+
values reject when settings are editable. These commands use the same queued
|
|
73
|
+
contract in browser and native SDK hosts.
|
|
74
|
+
|
|
75
|
+
## Experimental native Node host
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
import { createRoom, type NodeRoom } from 'ball2d/node';
|
|
79
|
+
|
|
80
|
+
const room: NodeRoom = await createRoom({
|
|
81
|
+
serviceOrigin: 'http://127.0.0.1:8787', // A matching Ball2D deployment
|
|
82
|
+
roomName: 'Native room',
|
|
83
|
+
noPlayer: true,
|
|
84
|
+
});
|
|
85
|
+
room.onPlayerJoin = (player) => room.setPlayerTeam(player.id, 1);
|
|
86
|
+
await room.setDefaultStadium('Classic');
|
|
87
|
+
await room.startGame();
|
|
88
|
+
// Later:
|
|
89
|
+
room.close();
|
|
90
|
+
await room.closed; // Native peer cleanup finished; rejects on cleanup failure.
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Verified on Node 24.19.0 and Bun 1.4.2 on macOS arm64 with local Worker signaling
|
|
94
|
+
and real Chrome guests. Both use the same `ball2d/node` entry, runtime WebSocket
|
|
95
|
+
and bundled, patched werift 0.24.4; no
|
|
96
|
+
browser host, postinstall patching or external transport dependency is required.
|
|
97
|
+
WASM and default stadium files are included and the engine identity is checked.
|
|
98
|
+
`serviceOrigin` defaults to `https://ball2d.com`; the deployment's client/protocol
|
|
99
|
+
and engine must match this SDK version. Importing the package does not
|
|
100
|
+
open a room. Browser consumers continue to import from `ball2d`.
|
|
101
|
+
|
|
102
|
+
On a deployment with accounts and SDK keys configured, supply an account-owned
|
|
103
|
+
key from an environment variable:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
const apiKey = process.env.BALL2D_API_KEY;
|
|
107
|
+
if (!apiKey) throw new Error('Set BALL2D_API_KEY from your Ball2D account.');
|
|
108
|
+
const room = await createRoom({ roomName: 'My room host', noPlayer: true, apiKey });
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`apiKey` is optional for existing anonymous hosting. When supplied, it is sent
|
|
112
|
+
only in the authenticated room-creation request's Authorization header, never
|
|
113
|
+
in a URL or peer message. Keys currently authorize only `rooms:create`. New keys
|
|
114
|
+
expire after 90 days by default; the account page offers 7, 30, 90 or 365 days.
|
|
115
|
+
Expiry and revocation prevent new room creation without stopping an existing match. Never include this key in browser bundles or version control.
|
|
116
|
+
Account access depends on configured social providers and Worker bindings.
|
|
117
|
+
Anonymous room hosting is available without an API key.
|
|
118
|
+
|
|
119
|
+
The matching Worker limits room creation to 10 attempts per minute per
|
|
120
|
+
API key and 20 per minute across an account's keys, in addition to the IP gate.
|
|
121
|
+
HTTP rate-limit responses include `Retry-After: 60`; avoid immediate retry loops.
|
|
122
|
+
These are approximate, location-local abuse limits, not globally exact quotas.
|
|
123
|
+
Exhausting a creation budget does not interrupt an established match.
|
|
124
|
+
Node.js 24 is the primary supported development target; Bun uses the same entry
|
|
125
|
+
without a separate implementation.
|
|
126
|
+
|
|
127
|
+
Native room callbacks and commands use the same SDK facade. `signal` aborts when
|
|
128
|
+
close begins; `closed` settles after native cleanup. Neither is a confirmation
|
|
129
|
+
that every remote player has received a shutdown message. This is not yet WAN,
|
|
130
|
+
Linux, other Bun versions, automatic outage recovery, sustained churn or capacity acceptance.
|
|
131
|
+
Bundled dependency licenses are in
|
|
132
|
+
`dist/licenses`; the transport includes DCEP unordered-bit and ICE restart fixes.
|
|
133
|
+
|
|
134
|
+
TypeScript Node consumers can use `module: "NodeNext"`, `lib: ["ES2022"]` and
|
|
135
|
+
`types: ["node"]` with their Node type package. Public declarations do not require
|
|
136
|
+
DOM/WebRTC globals or `skipLibCheck`; browser runtime classes remain internal.
|
|
137
|
+
`Replay` is exported as a data type from both SDK entries.
|
|
138
|
+
|
|
139
|
+
Both SDK entries accept `createRoom(config, { signal })`. The optional
|
|
140
|
+
`AbortSignal` cancels startup only; aborting it after creation does not close the
|
|
141
|
+
room. Use `room.close()` for an active room. Startup has a 15-second overall
|
|
142
|
+
deadline for engine assets, HTTP admission/body and signaling, while the existing
|
|
143
|
+
12-second signaling timeout can fail earlier. Rejection preserves the caller's
|
|
144
|
+
abort reason; the overall deadline rejects with `TimeoutError`. In-flight asset
|
|
145
|
+
and admission requests receive the startup signal, and late results cannot
|
|
146
|
+
continue admission after cancellation.
|
|
147
|
+
|
|
148
|
+
## Install
|
|
149
|
+
|
|
150
|
+
```sh
|
|
151
|
+
npm install ball2d@0.1.1
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The application source remains private. The package retains its existing
|
|
155
|
+
UNLICENSED designation; bundled third-party notices are included separately.
|