eco-pro / elm-phoenix-ports / Phoenix.Socket

A socket declares to which endpoint a socket connection should be established.

Definition


type alias Socket msg =
PhoenixSocket msg

Representation of a Socket connection

Helpers

init : String -> Socket msg

Initialize a Socket connection with an endpoint.

init "ws://localhost:4000/socket/websocket"

withParams : List ( String, String ) -> Socket msg -> Socket msg

Attach parameters to the socket connecton. You can use this to do authentication on the socket level. This will be the first argument (as a map) in your connect/2 callback on the server.

init "ws://localhost:4000/socket/websocket"
    |> withParams [ ( "token", "GYMXZwXzKFzfxyGntVkYt7uAJnscVnFJ" ) ]

onOpen : msg -> Socket msg -> Socket msg

Set a callback which will be called if the socket connection gets open.

onClose : ({ code : Basics.Int, reason : String, wasClean : Basics.Bool } -> msg) -> Socket msg -> Socket msg

Set a callback which will be called if the socket connection got closed. You can learn more about the code here.

map : (a -> b) -> Socket a -> Socket b

Composes each callback with the function a -> b.