# gizapp/netplay

the players of a networked game on its own server. Each player opens a WebSocket at /net (the subprotocol giz-net); its first message is its Giz sign-in token, which the server checks with the account (gizlang/signin accountOf), or "" for a guest when the game takes guests. The room is the game's seats (gizgame Net.Seats): they seat players, take their messages and, at their fixed tick, give the messages to send; what a message means is the game's. This file moves bytes. The seats live on a thread of their own (hub), their one owner: the sockets of any serving thread reach them only through its inbox, and each socket gets what they send it in an outbox of its own.

```gizlang
import * as Netplay from "gizapp/netplay";
```

## Types

### `Hub`

```gizlang
type Hub = { inbox: Task.Channel<Event>; sockets: Task.Atomic; }
```

The room's owner: the inbox of its thread, and the count that names each socket.

- `inbox`: `gizlang_task.Channel<M130.Event>`
- `sockets`: `gizlang_task.Atomic`

## Functions

### `hub`

```gizlang
function hub(make: fn () => Net.Seats): Hub
```

The room that MAKE gives, on a thread of its own that ticks it at its rate. MAKE is a plain function: the room is
made on that thread and nothing else holds it.

Effects: fail, read, write, console, io, alloc.

### `players`

```gizlang
function players(hub: Hub): (request: Http.Request) => Http.ReplyPlan
```

The handler of HUB's sockets: a request to PATH opens a player's socket.

Effects: fail, alloc.

## Constants

### `PATH`

```gizlang
const PATH = "/net"
```

The path of the players' sockets.

