Module

Erl.Cowboy.Handlers.WebSocket

Types and helpers for a cowboy_websocket Websockets callback module

See Erl.Cowboy.Handlers.

Example:

_behaviour :: CowboyWebsocketBehaviour
_behaviour = cowboyWebsocketBehaviour { init, websocket_handle, websocket_info }

data Config
data HandlerState

init :: InitHandler Config HandlerState
init = ...
websocket_handle :: FrameHandler HandlerState 
websocket_handle = ...
websocket_info :: InfoHandler HandlerState
websocket_info = ...

#InitResult

data InitResult t0

#InitHandler

type InitHandler c s = EffectFn2 Req c (InitResult s)

Init handler to upgrade to cowboy_websocket -- init()

#initResult

initResult :: forall a. a -> Req -> InitResult a

#FrameHandler

type FrameHandler s = EffectFn2 InFrame s (CallResult s)

Main frame handler - websocket_handle()

#InFrame

data InFrame

#decodeInFrame

#OutFrame

#outFrame

outFrame :: Frame -> OutFrame

TODO: Can also output iodata() versions, but input always binary

#CallResult

data CallResult t0

#okResult

okResult :: forall s. s -> CallResult s

#hibernateResult

hibernateResult :: forall s. s -> CallResult s

#replyResult

replyResult :: forall s. s -> List OutFrame -> CallResult s

#replyAndHibernateResult

#stopResult

stopResult :: forall s. s -> CallResult s

#WSInitHandler

type WSInitHandler s = EffectFn1 s (CallResult s)

Optional WS init handler (post-upgrade run in websocket process - websocket_init())

#InfoHandler

type InfoHandler a s = EffectFn2 a s (CallResult s)

Handler for erlang info messages - websocket_info()

#RemotePayload

#CloseCode

newtype CloseCode

ws:close_code() :: 1000..1003 | 1006..1011 | 3000..4999

Constructors

#RawTerminateReason

data RawTerminateReason

This is different from other callback modules terminate reasons

#PartialReq

data PartialReq

Cowboy does not provide the full Req object to terminate, so currently completely opaque

#CowboyWebsocketBehaviour

type CowboyWebsocketBehaviour = Behaviour "cowboy_websocket"

#cowboyWebsocketBehaviour

cowboyWebsocketBehaviour :: forall a i s. { init :: InitHandler a s, websocket_handle :: FrameHandler s, websocket_info :: InfoHandler i s } -> CowboyWebsocketBehaviour

Modules