Skip to content

Relay admission (EXPERIMENTAL)

EXPERIMENTAL extension seam. This is a generic admission contract. The relay exposes the seam, but has no service integration and no dependency on a credential or authorization SDK.

Relay admission is intended to authorize a generic, application-defined credential in one frame while a WebSocket connection is still pending. A future adapter to an external service such as Freebird might implement the provider. Admission must complete before normal relay protocol behavior is enabled: before welcome, peer rosters, room operations, routing, or WebRTC signaling are sent or accepted.

Public seam

These are the public TypeScript shapes for the seam. They deliberately contain no service-specific transport API:

export interface RelayAdmissionContext {
  operation: "connect";
  connectionId: string;
  remoteAddress?: string;
}

export interface RelayAdmissionDecision {
  allowed: boolean;
  reason?: string;
}

export interface RelayAdmissionProvider {
  authorize(
    credential: unknown,
    context: RelayAdmissionContext,
  ): Promise<RelayAdmissionDecision>;
}

export interface UniversalRelayServerOptions {
  admissionProvider?: RelayAdmissionProvider;
  admissionTimeoutMs?: number;
  maxAdmissionFrameBytes?: number;
}

export interface PeerConnectionOptions {
  getAdmissionCredential?: () => Promise<unknown>;
}

The server-side provider receives the opaque one-frame credential and a connection context, and returns { allowed: true } or a denial decision. The client sends the first frame as an encoded { type: "admission", credential } message. When a provider is configured, provider errors and authorization timeouts fail closed: the connection is denied and normal relay protocol traffic is not enabled. This fail-closed rule applies only when admission is configured. With no provider, the default is the exact open legacy behavior: no admission check is added.

admissionTimeoutMs defaults to 5000 ms and maxAdmissionFrameBytes defaults to 16 KiB. The latter limits the raw first frame; it is not a credential format or a security guarantee.

The client callback is invoked afresh for each connection attempt, including each reconnect. Credentials are not cached by the transport. A credential is never placed in a URL, logs, a broadcast, peer state, room state, or application state. It is used only for the pending admission exchange.

The type: "admission" frame is reserved for this handshake and is consumed, never relayed, even when no provider is configured. Without a provider it does not authorize anything; the relay instead keeps its exact open legacy behavior. With no client callback, no admission frame is sent. A configured provider still requires the one-frame credential, so a client without a callback cannot complete that pending admission.

NON-RUNNABLE pseudocode

The following is deliberately NON-RUNNABLE pseudocode. It is an example of the boundary, not a complete runnable setup:

// NON-RUNNABLE PSEUDOCODE — illustrative setup; imports and lifecycle omitted.
const server = new UniversalRelayServer({
  admissionProvider: {
    authorize: async (credential, context) => ({
      allowed: await externalAuthorizer.check(credential, context),
    }),
  },
  admissionTimeoutMs: 2_000,
});

const client = new PeerConnection(relayUrl, null, {
  getAdmissionCredential: () => credentialStore.issueFreshCredential(),
});

Admission is not authentication of a human or player, and an allowed connection is not proof that its future messages are valid. Neither relay admission nor checkpoint attestation provides game-rule validation, player or human identity, peer-key or ECDH binding, secure transport or encrypted sync, room authorization, replay protection or key rotation, or fair play.

TLS/WSS remains a separate deployment requirement. Admission alone does not provide secure transport, confidentiality, integrity, or protection against a malicious authorized client.