Loading…
Docs
Quickstart
1An account. Your hawkesgen.ai account (making one is free). 2A project. Make one on your Projects page: its id is what your game passes as project. 3The SDK. One ES module for the web and Babylon, a package for Unity WebGL. Every room runs on our relay, and each project's page shows its players, rooms and tickets live.
A game with no server: shared rooms
import { lobby } from 'https://net.hawkesgen.ai/sdk/hawkes-net@1.mjs';
const lob = lobby({ project: 'your-project', liveHosts: ['mygame.com'], name: 'Ada' });
lob.on('chat', (text, from) => show(from.name, text));
lob.onPose((peer, s) => moveAvatar(peer, s.p, s.y));
lob.when('status', ({ status }) => hud(status)); // connecting, online, reconnecting, offline, full
lob.join('level-1'); // everyone in level 1 plays together
lob.pose([x, y, z], yaw); // every frame
lob.send('chat', 'hello');
List your game's sites in the project's Settings: pages there join with no key. Localhost always may, in test rooms (t-…): free and apart from your players. A lobby is one shared room per area, kept joined: past a room's size it moves on to level-1.2, and it joins again by itself after a dropped connection. ?room=abc on the page puts it in its own test room.
A game with a server: tickets
Decide who may join which room (your logins, your matchmaking), then ask for a ticket with your API key and hand it to the page.
// Node (Express); the same in any language: one HTTPS POST with your key.
app.post('/ticket', async (req, res) => {
const r = await fetch('https://hawkesgen.ai/v1/net/rooms/ticket', {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.HAWKESGEN_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ project: 'your-project', room: req.body.room, name: req.user.name, sub: req.user.id }),
});
res.status(r.status).json(await r.json());
});
// The page
import { join } from 'https://net.hawkesgen.ai/sdk/hawkes-net@1.mjs';
const ticket = () => fetch('/ticket', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ room: 'match-7' }) }).then((r) => r.json());
const net = await join('match-7', { ticket });
Keep the key on your server. sub is your own id for the player: the same person reconnecting keeps their place, and the project's Rooms tab can put them out by it.
Unity
Package Manager > + > Add package from git URL: https://github.com/jgriffith3433/hawkesnet-unity.git?path=/Packages/com.hawkes.net#v0.5.1 (or the tarball, com.hawkes.net.tgz, with Add package from tarball). Source and docs: github.com/jgriffith3433/hawkesnet-unity (MIT); the Asset Store listing is in review. The same lobby in C#:
var lobby = new HawkesNetLobby(new HawkesNetOptions { project = "your-project", name = "Ada" }, "mygame.com");
lobby.PeerJoined += (id, name) => Spawn(id, name);
lobby.PoseChanged += (id, pose) => Move(id, pose.position, pose.yaw);
lobby.Message += (kind, data, from) => { if (kind == "chat") Show(from, data); };
lobby.Join("level-1");
void Update() { lobby.Room?.Pose(player.position, player.eulerAngles.y); }
Or drop HawkesNetAvatars on a GameObject with a prefab per player (Package Manager > Hawkes Net > Samples > Avatars). With a server: ticketUrl instead of project. WebGL builds run the web SDK in the page; the Editor and desktop builds join the same rooms with the package's managed client (in the Editor, your project's test rooms with no key: press Play).
Babylon.js
Hawkes Net for Babylon.js (MIT): everyone else as avatars played back smoothly on the room's clock, shared moving things, players in the background shown as away.
import * as BABYLON from '@babylonjs/core';
import { multiplayer } from '@hawkesgen/net-babylon';
const mp = multiplayer(scene, { babylon: BABYLON, project: 'your-project', name: 'Ada', player: playerMesh, liveHosts: ['mygame.com'] });
mp.share(crate, 'crate-1'); // the host simulates it; everyone sees it move
Messages and avatars
| Call | What it does |
|---|---|
net.send(kind, data, opt?) | To everyone. Reliable by default (once, in order, across reconnects). { reliable: false } may drop; { to: peerId } sends to one; { self: true } includes you. |
net.on(kind, (data, from, meta) => …) | Messages of one kind; '*' for all. |
net.pose([x, y, z], yaw, extra?) | Your avatar. Call it every frame; the relay sends near players often and far ones less. |
net.onPose((peer, state, at) => …) | Everyone else's avatar: state.p, state.y and your extras. |
net.when(event, fn) | status, ready, peer:join, peer:leave, host, problem. |
net.now() | The room's shared clock, in milliseconds. |
net.sync | Shared things: push what you simulate, onThing others', claim/hold/release ownership, state for shared documents. |
Types: hawkes-net.d.ts. Prefer a copy of the SDK? Save hawkes-net.mjs and hawkes-net-core.mjs side by side.
Limits and pricing
- Free account: projects, the dashboard and the SDK; your game on localhost in test rooms; up to 3 rooms, 16 players and 8 a room per project.
- Paid account (credits or a plan on hawkesgen.ai): your own sites and server tickets; up to 64 players a room, 200 rooms, 2,000 players a project.
- Every room runs on our relay. Peer to peer (players linked to a host) is a project setting, off unless you turn it on.
- While we set prices, using it costs no credits. Each project's page counts player-minutes and relay data, so you see what you'd pay before you pay anything.