Types and helpers for a cowboy_websocket Websockets callback module

See Erl.Cowboy.Handlers.


_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 = ...


data InitResult t0


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

Init handler to upgrade to cowboy_websocket -- init()


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


type FrameHandler s = EffectFn2 InFrame s (CallResult s)

Main frame handler - websocket_handle()


data InFrame




outFrame :: Frame -> OutFrame

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


data CallResult t0


okResult :: forall s. s -> CallResult s


hibernateResult :: forall s. s -> CallResult s


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



stopResult :: forall s. s -> CallResult s


type WSInitHandler s = EffectFn1 s (CallResult s)

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


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

Handler for erlang info messages - websocket_info()



newtype CloseCode

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



data RawTerminateReason

This is different from other callback modules terminate reasons


data PartialReq

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


type CowboyWebsocketBehaviour = Behaviour "cowboy_websocket"


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