feat: host-declared controller URL for rooms - #14
Merged
Conversation
A host can pass a `url` template on `create`, e.g. "https://play.example.com/{room}?instance={instance}". The relay resolves {room} (the code) and {instance} (the holding machine) once at create time and returns the URL in `created`, every `joined`, and `GET /room/:code`, so a generic controller that only has the room code can discover which page to load and where to connect. Templates are validated on create: https-only, at most 512 bytes, no spaces or control characters, balanced braces, and only the {room}/{instance} placeholders. Substituted values are percent-encoded. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Bm9uqStLTmcFSMSJStqPU3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an optional
urltemplate tocreateso a host can tell a generic controller what to load for a room:{ "type": "create", "clientId": "...", "maxClients": 4, "url": "https://play.example.com/{room}?instance={instance}" }The relay resolves
{room}(the code) and{instance}(the holding machine) once at create time and returns the finished URL increated, everyjoined, andGET /room/:code. A native controller that only has the room code can then discover which page to load and where to connect.Why
Enables a general controller app: the user types a room code, and the room itself carries the URL to render, so the app needs no per-game hard-coding. The code and instance aren't known until create, so the host ships a template and the relay fills the values it owns.
Validation
Templates are checked on
createand rejected otherwise:https:only (nojavascript:/file:/custom schemes){room}/{instance}placeholdersSubstituted values are percent-encoded. Rooms without a
urlare unchanged (the field is simply absent, so existing clients and the/room/:codeshape are unaffected).Tests
+9 tests: fill, static URL, omitted, non-https, unknown placeholder, control chars, unclosed brace, UTF-8 byte cap, and the reclaim/reconnect join path.
bun test: 91 pass / 8 skip / 0 fail.Follow-up (not in this PR)
ALLOWED_CONTROLLER_ORIGINSallowlist: a shared relay currently accepts anyhttps:origin, which a generic native shell would then load. Gating loadable origins server-side is a policy decision left open;https:-only + validation are the baseline.Also fixes a pre-existing mermaid render error in the README: two sequence-diagram Notes contained
;, which mermaid treats as a statement separator.🤖 Generated with Claude Code
https://claude.ai/code/session_01Bm9uqStLTmcFSMSJStqPU3