Socket

HTML & web

Mount typed channels on a websocket path.

connect runs during the HTTP upgrade and decides who may open a socket. Pass the resulting Mount list to supervised under Server.application.

On the SPA, treat three messages separately: socket status (Connection), topic admission (Result refusal reply), and the channel’s own down values. See examples/05_chat.

Types

Refusal

type Refusal
= NoSession
| Forbidden
| Invalid

Why a socket or join was refused.

Examples

NoSession
Forbidden
Invalid

Connection

type Connection
= Connecting
| Open
| Reconnecting Int
| Unauthorized Refusal
| Stale

Lifecycle of a browser socket connection.

Examples

Connecting
Open
Reconnecting 1

Mount

type Mount session = Mount

A websocket mount point waiting to be supervised.

Examples

mount "/socket"
    { connect = \_ -> Ok ()
    , channels = [ channel chat ]
    }

Mounted

type Mounted topic up down reply state msg = Mounted

A channel attached to a mount, ready for clients to join.

Examples

channel chat

Values

channel

channel : Channel topic up down reply state msg -> Mounted topic up down reply state msg

Attach a Channel so clients can join its topics on this socket.

Examples

channel chat

mount

mount : String -> { connect : Request -> Result Refusal session , channels : List (Mounted topic up down reply state msg) } -> Mount session

Declare a websocket path, an upgrade connect check, and the channels on it.

Examples

mount "/socket"
    { connect = \_ -> Ok ()
    , channels = [ channel chat ]
    }

supervised

supervised : List (Mount session) -> ChildSpecification ()

Run one or more mounts as supervised children of the server.

Examples

supervised [ mount "/socket" { connect = connect, channels = [ channel chat ] } ]