| Copyright | (c) digitally induced GmbH 2020 |
|---|---|
| Safe Haskell | None |
| Language | GHC2021 |
IHP.AutoRefresh
Description
Synopsis
- globalAutoRefreshServerVar :: MVar (Maybe (IORef AutoRefreshServer))
- getOrCreateAutoRefreshServer :: (?request :: Request) => IO (IORef AutoRefreshServer)
- autoRefresh :: (?theAction :: action, Controller action, ?modelContext :: ModelContext, ?context :: ControllerContext, ?request :: Request, ?respond :: Respond) => ((?modelContext :: ModelContext, ?respond :: Respond, ?request :: Request) => IO ResponseReceived) -> IO ResponseReceived
- data AutoRefreshWSApp
- captureResponseBody :: Respond -> (Respond -> IO a) -> IO (a, Maybe LByteString)
- registerNotificationTrigger :: (?modelContext :: ModelContext, ?context :: ControllerContext) => IORef (Set Text) -> IORef AutoRefreshServer -> IO ()
- getAvailableSessions :: (?request :: Request) => IORef AutoRefreshServer -> IO [UUID]
- getSessionById :: IORef AutoRefreshServer -> UUID -> IO AutoRefreshSession
- updateSession :: IORef AutoRefreshServer -> UUID -> (AutoRefreshSession -> AutoRefreshSession) -> IO ()
- sessionResponseHasChanged :: IORef AutoRefreshServer -> UUID -> LByteString -> IO Bool
- gcSessions :: IORef AutoRefreshServer -> IO ()
- isSessionExpired :: UTCTime -> AutoRefreshSession -> Bool
- channelName :: Text -> ByteString
- notificationTriggerSQL :: Text -> Text
- autoRefreshStateVaultKey :: Key AutoRefreshState
Documentation
getOrCreateAutoRefreshServer :: (?request :: Request) => IO (IORef AutoRefreshServer) Source #
autoRefresh :: (?theAction :: action, Controller action, ?modelContext :: ModelContext, ?context :: ControllerContext, ?request :: Request, ?respond :: Respond) => ((?modelContext :: ModelContext, ?respond :: Respond, ?request :: Request) => IO ResponseReceived) -> IO ResponseReceived Source #
data AutoRefreshWSApp Source #
Constructors
| AwaitingSessionID | |
| AutoRefreshActive | |
Instances
| WSApp AutoRefreshWSApp Source # | |
Defined in IHP.AutoRefresh Methods | |
captureResponseBody :: Respond -> (Respond -> IO a) -> IO (a, Maybe LByteString) Source #
Runs an action while capturing the response body. Returns the action's result and the captured body (if it was a ResponseBuilder). Only captures ResponseBuilder responses (used by HSX/Blaze rendering).
registerNotificationTrigger :: (?modelContext :: ModelContext, ?context :: ControllerContext) => IORef (Set Text) -> IORef AutoRefreshServer -> IO () Source #
getAvailableSessions :: (?request :: Request) => IORef AutoRefreshServer -> IO [UUID] Source #
Returns the ids of all sessions available to the client based on what sessions are found in the session cookie
getSessionById :: IORef AutoRefreshServer -> UUID -> IO AutoRefreshSession Source #
Returns a session for a given session id. Errors in case the session does not exist.
updateSession :: IORef AutoRefreshServer -> UUID -> (AutoRefreshSession -> AutoRefreshSession) -> IO () Source #
Applies a update function to a session specified by its session id
sessionResponseHasChanged :: IORef AutoRefreshServer -> UUID -> LByteString -> IO Bool Source #
Returns True when the rendered html differs from the session's latest
known response.
This must read the current session state instead of comparing against a websocket-local snapshot, otherwise switching back to an earlier DOM state can be incorrectly suppressed as "unchanged".
gcSessions :: IORef AutoRefreshServer -> IO () Source #
Removes all expired sessions
This is useful to avoid dead sessions hanging around. This can happen when a websocket connection was never established after the initial request. Then the onClose of the websocket app is never called and thus the session will not be removed automatically.
isSessionExpired :: UTCTime -> AutoRefreshSession -> Bool Source #
A session is expired if it was not pinged in the last 60 seconds
channelName :: Text -> ByteString Source #
Returns the event name of the event that the pg notify trigger dispatches
notificationTriggerSQL :: Text -> Text Source #
Returns a SQL script to set up database notification triggers.
Wrapped in a DO $$ block with EXCEPTION handler because concurrent requests can race to CREATE OR REPLACE the same function, causing PostgreSQL to throw 'tuple concurrently updated' (SQLSTATE XX000). This is safe to ignore: the other connection's CREATE OR REPLACE will have succeeded.