Hosting your page

A game’s page is static files, and its rooms don’t care where they’re served from. An IRT site, itch.io, GitHub Pages and a domain of your own are equal ways to host it: the client connects to the same room URLs from any of them, and the router accepts connections from a page on any origin, with nothing to configure or allow.

What a page needs is to know its project, which it says in one of two ways. The first is a meta tag in the <head> of each HTML page that connects:

<meta name="irt-project" content="https://rooms.irt.io/dots/">

Room URLs can then be relative, connect("lobby"), and createRoom, joinByCode, listPublic, quickJoin, dataClient and the UI kit find the project by themselves. The second is absolute URLs, with no tag: connect takes the room’s whole URL, and the rest take the project URL as project:

// absolute.ts
import { connect, createRoom } from "@irtio/client";

const project = "https://rooms.irt.io/dots/";
const { url } = await createRoom({ project, joinCode: true });
const room = await connect(url);
console.log(room.url === `${project}${room.id}`);

A relative room URL with neither throws a TypeError, as new URL("lobby") does with no base.

An IRT site

A build’s site is served at https://<project>.irt-serve.com, and IRT adds the meta tag to every HTML file that doesn’t have one, as irt dev does locally with the local server’s URL. Its files go live with the room code they were built against, so a page and its rooms never disagree. Nothing else to set up.

itch.io

Upload the page’s files as an HTML5 game: a zip with index.html at its top, with the meta tag written in it, or the files the butler CLI pushes. itch.io shows the game in a frame on its own domain, which is fine for connecting. Two things follow from the frame:

  • A share link built from the page’s URL, as <irt-invite> builds it, opens the game alone, outside its itch.io page. It still works; to keep players on the itch.io page, share the join code instead.
  • Guests are kept in the frame’s localStorage, which browsers keep apart for each site that frames it, so a guest is one player on your itch.io page but a new one if the same game is framed elsewhere.

GitHub Pages

Commit the page with the meta tag in it, or the output of your bundler with the tag in its index.html, and publish it. A page at https://<user>.github.io/<repo>/ resolves room URLs against the tag, not against its own address, so the repository path doesn’t matter.

Your own domain

Any static host or CDN serves the page as it is. If the domain sends a Content-Security-Policy, allow the client’s connections and, for a page with no build step, its script:

connect-src https://rooms.irt.io wss://rooms.irt.io
script-src https://irt.io

Guests are kept per origin, so moving a game to a new domain makes its players new guests there; games with accounts sign player tokens and keep their players anywhere.

Deploying the page with its build

A client and the room it connects to must be built from the same schema, or the connection closes with 4004. After a deploy, a page that connects to a room on the new build calls reloadForNewBuild(), which reloads whatever page is open, wherever it’s hosted, at most once:

// reload.ts
import { connect, defineSchema, IrtError, reloadForNewBuild } from "@irtio/client";

const schema = defineSchema({});

try {
  await connect("lobby", { schema });
} catch (e) {
  if (e instanceof IrtError && e.name === "VersionError" && reloadForNewBuild()) {
    // The page is reloading.
  } else {
    throw e;
  }
}

The reload helps only if the host serves files that match the live build by then. An IRT site does, since its files are part of the build. A page hosted elsewhere gets the same guarantee when its files are deployed with every build: in the same CI job, right after npx irt deploy, such as butler push dist my-studio/dots:html5. Until its new files are live, its players get 4004. A page that connects with no schema to native rooms with none, as Start with a script tag does, is never refused for this.

A room URL is for connecting, not for players: opened in a browser, https://rooms.irt.io/dots/forest-7 is an error page, not the game. Share the game’s own page with the room in its query, which is what <irt-invite> builds from the page’s own URL on any host: ?code=K7M2QX for a room with a join code, else ?room=forest-7. The page reads them back when it opens:

// join-from-link.ts
import { connect, joinByCode } from "@irtio/client";

const params = new URLSearchParams(location.search);
const code = params.get("code");
const room = await connect(code ? await joinByCode(code) : (params.get("room") ?? "lobby"));
console.log("in", room.url);

<irt-invite> and <irt-room-panel> read the same parameters themselves.