A socket declares to which endpoint a socket connection should be established.
PhoenixSocket msg
Representation of a Socket connection
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
.
heartbeatIntervalSeconds : Basics.Int -> Socket msg -> Socket msg
NOT YET IMPLEMENTED - The client regularly sends a heartbeat to the server. With this function you can specify the intervall in which the heartbeats are send. By default it_s 30 seconds.
init "ws://localhost:4000/socket/websocket"
|> heartbeatIntervallSeconds 60
withoutHeartbeat : Socket msg -> Socket msg
NOT YET IMPLEMENTED - The client regularly sends a heartbeat to the sever. With this function you can disable the heartbeat.
init "ws://localhost:4000/socket/websocket"
|> withoutHeartbeat
onAbnormalClose : (AbnormalClose -> msg) -> Socket msg -> Socket msg
NOT YET IMPLEMENTED - Set a callback which will be called if the socket connection got closed abnormal, i.e., if the server declined the socket authentication. So this callback is useful for updating query params like access tokens.
type Msg =
RefreshAccessToken | ...
init "ws://localhost:4000/socket/websocket"
|> withParams [ ( "accessToken", "abc123" ) ]
|> onAbnormalClose RefreshAccessToken
onNormalClose : msg -> Socket msg -> Socket msg
NOT YET IMPLEMENTED - Set a callback which will be called if the socket connection got closed normal. Useful if you have to do some additional clean up.
reconnectTimer : (Basics.Int -> Basics.Int) -> Socket msg -> Socket msg
NOT YET IMPLEMENTED - The effect manager will try to establish a socket connection. If it fails it will try again with a specified backoff. By default the effect manager will use the following exponential backoff strategy:
defaultReconnectTimer failedAttempts =
if backoff < 1 then
0
else
toFloat (10 * 2 ^ failedAttempts)
With this function you can specify a custom strategy.