Copyright | (c) 2016 Michael Walker |
---|---|
License | MIT |
Maintainer | Michael Walker <mike@barrucadu.co.uk> |
Stability | experimental |
Portability | OverloadedStrings |
Safe Haskell | None |
Language | Haskell2010 |
Functions for creating event handlers and triggering events.
- eventType :: Value -> Text
- eventChannel :: Value -> Maybe Channel
- data Binding
- bind :: Text -> Maybe Channel -> (Value -> PusherClient ()) -> PusherClient Binding
- bindAll :: Maybe Channel -> (Value -> PusherClient ()) -> PusherClient Binding
- unbind :: Binding -> PusherClient ()
- triggerEvent :: Text -> Maybe Channel -> Value -> PusherClient ()
- localEvent :: Text -> Maybe Channel -> Value -> PusherClient ()
Documentation
eventType :: Value -> Text Source
Get the value of the "event" field.
If not present (which should never happen!), returns the empty string.
eventChannel :: Value -> Maybe Channel Source
Get the value of the "channel" field.
This will be Nothing
if the event was broadcast to all clients,
with no channel restriction.
Event Handlers
Event binding handle: a witness that we bound an event handler, and is used to unbind it.
If this is used after unbinding, nothing will happen.
:: Text | Event name. |
-> Maybe Channel | Channel name: If |
-> (Value -> PusherClient ()) | Event handler. |
-> PusherClient Binding |
Bind an event handler to an event type, optionally restricted to a channel.
Attempts to decode the "data" field of the event as stringified JSON; if that fails, it is left as a string.
If multiple handlers match a received event, all will be executed. The order is unspecified, and may not be consistent.
bindAll :: Maybe Channel -> (Value -> PusherClient ()) -> PusherClient Binding Source
Variant of bind
which binds to all events in the given channel;
or all events if no channel.
unbind :: Binding -> PusherClient () Source
Remove a binding
Client Events
triggerEvent :: Text -> Maybe Channel -> Value -> PusherClient () Source
Send an event with some JSON data. This does not trigger local event handlers.
localEvent :: Text -> Maybe Channel -> Value -> PusherClient () Source
Trigger local event handlers, but do not send the event over the network.