kageurufu/elm-websockets/1.0.0

NOTE: the latest version is 1.0.1

Rerouted (regenerated, verified). Same repository and tag, but GitHub now builds the zip with different bytes, so it no longer matches the SHA-1 package.elm-lang.org recorded. The Lamdera package server serves a copy recovered from https://github.com/kageurufu/elm-websockets.

What we checked: Tag 1.0.0 is still on github.com/kageurufu/elm-websockets; its commit be3d79f38887 is from 2024-02-19 19:14 UTC, before the version was published (2024-02-19 19:16 UTC); elm.json is byte-identical to package.elm-lang.org's; the exposed modules match docs.json; the zip's SHA-1 is not the published one (GitHub's zip no longer comes out byte for byte the same), so the contents were checked instead.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/kageurufu/elm-websockets/zipball/1.0.0/

Websockets

Simple interfaces for getting started with Websockets in Elm

Other modules are exposed for advanced usage.

Defining your Ports

{ command : CommandPort msg
, event : EventPort msg
}
-> Methods msg

Helper to wrap your Ports

type alias CommandPort msg =
Value -> Cmd msg

Port to send Commands to the Websocket

type alias EventPort msg =
(Value -> msg) -> Sub msg

Port for subscribing to income events

type alias Methods msg =
{ open : String -> String -> List ( String, Maybe String ) -> Cmd msg
, close : String -> Cmd msg
, send : String -> Value -> Cmd msg
, onEvent : EventHandlers msg -> Sub msg
}

Methods for using your sockets

Event data received from your Sockets

type alias EventHandlers msg =
{ onOpened : WebsocketOpened -> msg
, onClosed : WebsocketClosed -> msg
, onError : WebsocketError -> msg
, onMessage : WebsocketMessage -> msg
, onDecodeError : String -> msg
}

Event handlers for subscriptions

type alias WebsocketOpened =
{ name : Name
, meta : Meta
}

Record data when a socket is Opened

type alias WebsocketMessage =
{ name : Name
, meta : Meta
, data : String
}

Record data when a socket is Message

type alias WebsocketClosed =
{ name : Name
, meta : Meta
, reason : String
}

Record data when a socket is Closed

type alias WebsocketError =
{ name : Name
, meta : Meta
, error : Maybe String
}

Record data when a socket is Error