Cool, didn't realize there was a
socket.io port.
I'm fairly new to Haskell (as in, did the intro thing a decade and a
half ago in college, was familiar with the syntax but am only
recently tackling understanding monads and the like.) Has anyone
gotten this working with Happstack? As in, plugged a
socket.io
server into the Happstack routing table?
There are so many moving parts that I'm not sure where to begin. At
the moment I'm doing something like:
main = do
updateGlobalLogger rootLoggerName (setLevel INFO)
simpleHTTP nullConf $ msum
[ dir "favicon.ico" $ notFound (toResponse ()),
serveDirectory DisableBrowsing [] "www",
implSite (pack "") (pack "/api") api,
implSite (pack "") (pack "") site
]
I'd like to put
socket.io under the /api site, but I'm not sure if
that's practical. There's an initialize function that looks like so:
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
=> EIO.ServerAPI m
-> StateT RoutingTable m a
-> IO (m ())
initialize api socketHandler = do
...
So I'm guessing something needs to be an instance of EIO.ServerAPI,
but I'm not sure if that's my API type for routes or something else.
I'm also guessing the result of the initialize call gets plugged
into the routing table like my other subsites, meaning it needs to
be an instance of some other type?
Anyhow, if anyone has gotten
socket.io glued to Happstack, it might
be easier for me to learn state monads and such by writing code to
statefully track user connects/disconnects than it is for me to
figure out how this goes together. :)