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
| InvalidWhy a socket or join was refused.
Examples
NoSession
Forbidden
InvalidConnection
type Connection
= Connecting
| Open
| Reconnecting Int
| Unauthorized Refusal
| StaleLifecycle of a browser socket connection.
Examples
Connecting
Open
Reconnecting 1Mount
type Mount session = MountA websocket mount point waiting to be supervised.
Examples
mount "/socket"
{ connect = \_ -> Ok ()
, channels = [ channel chat ]
}Mounted
type Mounted topic up down reply state msg = MountedA channel attached to a mount, ready for clients to join.
Examples
channel chatValues
channel
channel : Channel topic up down reply state msg -> Mounted topic up down reply state msgAttach a Channel so clients can join its topics on this socket.
Examples
channel chatmount
mount : String -> { connect : Request -> Result Refusal session , channels : List (Mounted topic up down reply state msg) } -> Mount sessionDeclare 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 ] } ]