Browser entry
Host a room from a web page served by a Ball2D deployment.
import { createRoom } from 'ball2d' is the browser entry. It exposes the same room API as ball2d/node, but starts rooms differently.
ball2d/node | ball2d | |
|---|---|---|
| Runs in | Node.js 24+ | A browser page |
| Starts a room with | Your API key | The browser admission policy |
| Talks to | serviceOrigin (default https://ball2d.com) | The page's own origin |
| Room limits | Your account's limits | Per-address limits of the deployment |
Requirements
The browser entry uses the service, physics engine and stadium files of the page's own origin. The page must be served by a Ball2D deployment that provides them: the service rejects room requests from other origins. It is not a way to host rooms on ball2d.com from your own website.
Never use an API key in the browser
The browser entry does not accept an apiKey, and passing one fails as an unknown setting. Anything in a browser bundle can be read by anyone who loads the page; keep API keys on servers only.
When to use it
Use ball2d/node for rooms you run and control. The browser entry exists for pages that are part of a Ball2D deployment itself, where the room runs in a visitor's browser under the deployment's anonymous play policy.