Created
July 28, 2012 18:40
-
-
Save scan/3194365 to your computer and use it in GitHub Desktop.
app.hs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
application :: MVar ServerState -> WS.Request -> WS.WebSockets WS.Hybi10 () | |
application state rq = do | |
WS.acceptRequest rq | |
WS.getVersion >>= liftIO . putStrLn . ("Client version: " ++) | |
sink <- WS.getSink | |
msg <- WS.receiveData | |
clients <- liftIO $ readMVar state | |
url <- liftIO fbUrl | |
let prefix = "Facebook code " | |
let code = T.unpack $ T.drop (T.length prefix) msg | |
e <- liftIO $ fbEmail $ (\(x,y) -> (C.pack x, C.pack y)) ("code", code) | |
case e of | |
Nothing -> WS.sendTextData ("Facebook login " `mappend` url :: Text) | |
Just e -> do | |
let client = (e, sink) | |
if clientExists client clients | |
then WS.sendTextData ("User already exists" :: Text) | |
else do | |
liftIO $ modifyMVar_ state $ \s -> do | |
let s' = addClient client s | |
WS.sendSink sink $ WS.textData $ | |
"Welcome! Users: " `mappend` | |
T.intercalate ", " (map fst s) | |
broadcast (fst client `mappend` " joined") s' | |
return s' | |
talk state client |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment