Safe Haskell | None |
---|
- server :: Port -> HandlerM () -> IO ()
- serverConfig :: Port -> Configuration -> HandlerM () -> IO ()
- defaultConfig :: Configuration
- data Configuration = Configuration {
- transports :: [Transport]
- logLevel :: Int
- heartbeats :: Bool
- closeTimeout :: Int
- heartbeatTimeout :: Int
- heartbeatInterval :: Int
- pollingDuration :: Int
- type Port = Int
- data Transport = XHRPolling
- class Subscriber m where
- class Publisher m where
- reply :: CallbackM [Text]
- type Event = Text
- data HandlerM a
- data CallbackM a
How to use this module
Note that most of the string literals below are of type Text.
{-\# LANGUAGE OverloadedStrings \#-} import Web.SocketIO -- listens to port 4000 main = server 4000 $ do -- send something to the client emit "some event" ["hey"] -- ping-pong on "ping" $ do emit "pong" [] -- do some IO on "Kim Jong-Un" $ liftIO launchMissile
Running a standalone server
serverConfig :: Port -> Configuration -> HandlerM () -> IO ()Source
Run a socket.io application with configurations applied.
defaultConfig :: ConfigurationSource
Default configurations to be overridden.
defaultConfig :: Configuration defaultConfig = Configuration { transports = [XHRPolling] , logLevel = 3 , closeTimeout = 60 , pollingDuration = 20 , heartbeats = True , heartbeatTimeout = 60 , heartbeatInterval = 25 }
data Configuration Source
Configuration | |
|
Sending and receiving events
class Subscriber m whereSource
Receiving events.
Sending events
:: Event | event to trigger |
-> [Text] | message to carry with |
-> m () |
Sends a message to the socket that starts it.
emit
"launch" ["missile", "nuke"]
:: Event | event to trigger |
-> [Text] | message to carry with |
-> m () |
Sends a message to everyone else except for the socket that starts it.
broadcast
"hide" ["nukes coming!"]
reply :: CallbackM [Text]Source
messages carried with the event
on
"echo" $ do
messages <- reply
liftIO $ print messages
Special events
On disconnection
on
"disconnect" $ do
liftIO $ print "client disconnected"
Types
Capable of both sending and receiving events.
Use liftIO
if you wanna do some IO here.