-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | This library provides an implementation of Socket.io protocol -- (version 1). It builds on top of Engine.IO, allowing Socket.io to work -- with both long polling XHR requests, and seamlessly upgrading them to -- HTML 5 web sockets. @package socket-io @version 1.0.1 module Network.SocketIO -- | This computation initializes a Socket.IO server and returns a -- computation that you should call whenever a request comes in to the -- socket.io path. For example, in a Snap application, -- you might do: -- --
-- handler <- initialize snapAPI mkRoutes
-- quickHttpServe $ route [("/socket.io", handler)]
--
--
-- The second argument to this function is an action to build up the
-- routing table, which determines what happens when clients emit events.
-- It is also an action that is called every time a client connects, so
-- you can mutate state by taking advantage of the MonadIO
-- instance. You can build a routing table by using the convenience
-- on family of functions.
initialize :: MonadIO m => ServerAPI m -> StateT RoutingTable m a -> IO (m ())
-- | A per-connection routing table. This table determines what actions to
-- invoke when events are received.
data RoutingTable
-- | When an event with a given name is received, and its arguments can be
-- decoded by a FromJSON instance, run the associated function
-- after decoding the event arguments.
on :: (MonadState RoutingTable m, FromJSON arg, Applicative m) => Text -> (arg -> EventHandler a) -> m ()
-- | When an event is received with a given name and no arguments, run the
-- associated EventHandler.
on_ :: (MonadState RoutingTable m, Applicative m) => Text -> EventHandler a -> m ()
-- | When an event with a given name is received, call the associated
-- function with the array of JSON arguments.
onJSON :: (MonadState RoutingTable m, Applicative m) => Text -> (Array -> EventHandler a) -> m ()
-- | Run the given IO action when a client disconnects, along with any
-- other previously register disconnect handlers.
appendDisconnectHandler :: MonadState RoutingTable m => (SocketId -> IO ()) -> m ()
type EventHandler a = ReaderT Socket IO a
-- | Emit an event and argument data to a Socket. If called from
-- within on, this will be the client that emitted the original
-- event.
emit :: (ToJSON a, MonadReader Socket m, MonadIO m) => Text -> a -> m ()
-- | Emit an event with a specific array of JSON arguments.
emitJSON :: (MonadReader Socket m, MonadIO m) => Text -> Array -> m ()
-- | Emit an event to specific Socket.
emitTo :: (ToJSON a, MonadIO m) => Socket -> Text -> a -> m ()
-- | Emit an event with a specific array of JSON arguments to a
-- specific Socket.
emitJSONTo :: MonadIO m => Socket -> Text -> Array -> m ()
-- | Broadcast an event to all other Sockets.
broadcast :: (ToJSON a, MonadReader Socket m, MonadIO m) => Text -> a -> m ()
-- | Broadcast an event with an array of JSON arguments to all other
-- Sockets.
broadcastJSON :: (MonadReader Socket m, MonadIO m) => Text -> Array -> m ()
-- | A Socket.IO socket (not to be confused with an Engine.IO
-- Socket).
data Socket
-- | Retrieve the Engine.IO SocketId for a Socket.
socketId :: Socket -> SocketId
data PacketType
Connect :: PacketType
Disconnect :: PacketType
Event :: PacketType
Ack :: PacketType
Error :: PacketType
BinaryEvent :: PacketType
BinaryAck :: PacketType
parsePacketType :: Parser PacketType
encodePacketType :: PacketType -> Builder
data Packet
Packet :: !PacketType -> !(Maybe Int) -> !Text -> !(Maybe Int) -> !(Maybe Value) -> Packet
parsePacket :: Parser Packet
encodePacket :: Packet -> Builder
instance Bounded PacketType
instance Enum PacketType
instance Eq PacketType
instance Read PacketType
instance Show PacketType
instance Eq Packet
instance Show Packet
instance Ord Socket
instance Eq Socket