IHP Api Reference
Copyright(c) digitally induced GmbH 2020
Safe HaskellSafe-Inferred

IHP.WebSocket

Description

 
Synopsis

Documentation

class WSApp state where Source #

Minimal complete definition

initialState

Methods

initialState :: state Source #

run :: (?state :: IORef state, ?context :: ControllerContext, ?applicationContext :: ApplicationContext, ?modelContext :: ModelContext, ?connection :: Connection) => IO () Source #

onPing :: (?state :: IORef state, ?context :: ControllerContext, ?applicationContext :: ApplicationContext, ?modelContext :: ModelContext, ?connection :: Connection) => IO () Source #

onClose :: (?state :: IORef state, ?context :: ControllerContext, ?applicationContext :: ApplicationContext, ?modelContext :: ModelContext, ?connection :: Connection) => IO () Source #

connectionOptions :: ConnectionOptions Source #

Provide WebSocket Connection Options

See All Config Options Here https://hackage.haskell.org/package/websockets/docs/Network-WebSockets-Connection.html#t:ConnectionOptions

Example: Enable default permessage-deflate compression

connectionOptions =
    WebSocket.defaultConnectionOptions {
        WebSocket.connectionCompressionOptions =
            WebSocket.PermessageDeflateCompression WebSocket.defaultPermessageDeflate
    }

startWSApp :: forall state. (WSApp state, ?applicationContext :: ApplicationContext, ?requestContext :: RequestContext, ?context :: ControllerContext, ?modelContext :: ModelContext) => Connection -> IO () Source #

setState :: (?state :: IORef state) => state -> IO () Source #

getState :: (?state :: IORef state) => IO state Source #

receiveData :: (?connection :: Connection, WebSocketsData a) => IO a Source #

receiveDataMessage :: (?connection :: Connection) => IO DataMessage Source #

sendTextData :: (?connection :: Connection, WebSocketsData text) => text -> IO () Source #

sendJSON :: (?connection :: Connection, ToJSON value) => value -> IO () Source #

Json encode a payload and send it over the websocket wire

Example:

message <- Aeson.decode <$> receiveData @LByteString

case message of
    Just decodedMessage -> handleMessage decodedMessage
    Nothing -> sendJSON FailedToDecodeMessageError

Orphan instances

WebSocketsData UUID Source # 
Instance details

Methods

fromDataMessage :: DataMessage -> UUID

fromLazyByteString :: ByteString -> UUID

toLazyByteString :: UUID -> ByteString