pusher-ws-0.1.0.0: Implementation of the Pusher WebSocket protocol

Copyright(c) 2016 Michael Walker
LicenseMIT
MaintainerMichael Walker <mike@barrucadu.co.uk>
Stabilityexperimental
PortabilityOverloadedStrings
Safe HaskellNone
LanguageHaskell2010

Network.Pusher.WebSockets.Event

Contents

Description

Functions for creating event handlers and triggering events.

Synopsis

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

data Binding Source

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.

bind Source

Arguments

:: Text

Event name.

-> Maybe Channel

Channel name: If Nothing, all events of that name are handled.

-> (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.