Channel

Processes

Typed realtime rooms shared by the server and the browser.

A channel module declares the topic, the messages the browser sends (up), the messages the server pushes (down), and the join reply. The compiler derives the binary codecs. state and msg stay on the BEAM — the SPA never sees them.

For chunked uploads (rows, records, or wire-safe Bytes) with immediate error downs, call StreamUpload.handleIn from your channel handleIn. See examples/14_ws_books_upload.

See examples/05_chat and the Channels section of the Language docs.

Channel.define { join = join, handleIn = handleIn, update = update, subscriptions = subscriptions }

Types

Channel

type Channel topic up down reply state msg = Channel

Values

define

define : { join : session -> topic -> Result refusal (state, reply, Cmd msg) , handleIn : up -> state -> (state, Cmd msg) , update : msg -> state -> (state, Cmd msg) , subscriptions : state -> Sub msg } -> Channel topic up down reply state msg

Build a channel from join / handleIn / update / subscriptions.

join decides whether a client may enter a topic and returns the initial state, the reply sent back on success, and any commands. handleIn reacts to up messages from the browser. update and subscriptions are ordinary TEA for server-side work on that topic.

Examples

Channel.define
    { join = join
    , handleIn = handleIn
    , update = update
    , subscriptions = subscriptions
    }

broadcast

broadcast : Channel topic up down reply state msg -> topic -> down -> Cmd msg

Push a down message to every subscriber of topic.

Examples

Channel.broadcast channel topic (Said "hello")

broadcastFrom

broadcastFrom : Channel topic up down reply state msg -> topic -> down -> Cmd msg

Like broadcast, but skip the sender’s own socket.

Examples

Channel.broadcastFrom channel topic (Said "hello")

subscribe

subscribe : Channel topic up down reply state msg -> topic -> Cmd msg

Subscribe this channel process to topic so it receives matching traffic.

Examples

Channel.subscribe channel topic