socketio-0.1.0.0: Socket.IO server

Safe HaskellNone

Web.SocketIO

Contents

Synopsis

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

server :: Port -> HandlerM () -> IO ()Source

Run a socket.io application, build on top of Warp.

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 Transport Source

Now only xhr-polling is supported.

Constructors

XHRPolling 

Sending and receiving events

class Subscriber m whereSource

Receiving events.

Methods

onSource

Arguments

:: Event

event to listen to

-> CallbackM ()

callback

-> m () 

Instances

class Publisher m whereSource

Sending events

Methods

emitSource

Arguments

:: Event

event to trigger

-> [Text]

message to carry with

-> m () 

Sends a message to the socket that starts it.

 emit "launch" ["missile", "nuke"] 

broadcastSource

Arguments

:: 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

type Event = TextSource

Special events

On disconnection

 on "disconnect" $ do
     liftIO $ print "client disconnected"

Types

data HandlerM a Source

Capable of both sending and receiving events.

Use liftIO if you wanna do some IO here.

data CallbackM a Source

Capable of only sending events.

Use liftIO if you wanna do some IO here.