Module

Erl.Cowboy.Handlers.WebSocket

Package
erl-cowboy
Repository
purerl/purescript-erl-cowboy

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 Source

data InitResult :: Type -> Type

#InitHandler Source

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

Init handler to upgrade to cowboy_websocket -- init()

#initResult Source

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

#FrameHandler Source

type FrameHandler s = EffectFn2 InFrame s (CallResult s)

Main frame handler - websocket_handle()

#InFrame Source

data InFrame :: Type

#decodeInFrame Source

#OutFrame Source

data OutFrame :: Type

#outFrame Source

outFrame :: Frame -> OutFrame

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

#CallResult Source

data CallResult :: Type -> Type

#okResult Source

okResult :: forall s. s -> CallResult s

#hibernateResult Source

hibernateResult :: forall s. s -> CallResult s

#replyResult Source

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

#replyAndHibernateResult Source

#stopResult Source

stopResult :: forall s. s -> CallResult s

#WSInitHandler Source

type WSInitHandler s = EffectFn1 s (CallResult s)

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

#InfoHandler Source

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

Handler for erlang info messages - websocket_info()

#RemotePayload Source

#CloseCode Source

newtype CloseCode

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

Constructors

#RawTerminateReason Source

data RawTerminateReason :: Type

This is different from other callback modules terminate reasons

#PartialReq Source

data PartialReq :: Type

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

#CowboyWebsocketBehaviour Source

type CowboyWebsocketBehaviour = Behaviour "cowboy_websocket"

#cowboyWebsocketBehaviour Source

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