aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorJasper Van der Jeugt2020-07-29 21:14:12 +0200
committerJasper Van der Jeugt2020-07-29 21:14:12 +0200
commit49b346b7ebe98051a618d88a39d9b02f13edf33c (patch)
tree41d126d23ed0d3bcc469622b510b67e71d273821 /server
parent057d954fe8d3265fc122f4a3066eab15eb7653d3 (diff)
Welcome Bye
Diffstat (limited to '')
-rw-r--r--server/cafp.cabal1
-rw-r--r--server/lib/Cafp/Main/GenerateElmTypes.hs9
-rw-r--r--server/lib/Cafp/Main/Server.hs5
-rw-r--r--server/lib/Cafp/Messages.hs6
4 files changed, 13 insertions, 8 deletions
diff --git a/server/cafp.cabal b/server/cafp.cabal
index f97f958..733c3e3 100644
--- a/server/cafp.cabal
+++ b/server/cafp.cabal
@@ -21,6 +21,7 @@ Library
Cafp.Main.Server
Build-depends:
+ aeson >= 1.4 && < 1.5,
base >= 4.9 && < 5,
elm-bridge >= 0.5 && < 0.6,
scotty >= 0.11 && < 0.12,
diff --git a/server/lib/Cafp/Main/GenerateElmTypes.hs b/server/lib/Cafp/Main/GenerateElmTypes.hs
index 0bd43c1..8d2c9c1 100644
--- a/server/lib/Cafp/Main/GenerateElmTypes.hs
+++ b/server/lib/Cafp/Main/GenerateElmTypes.hs
@@ -4,12 +4,9 @@ module Cafp.Main.GenerateElmTypes
( main
) where
-import Cafp.Messages
-import Elm.Derive
-import Elm.Module
-import Data.Proxy
-
-deriveBoth defaultOptions ''ServerMessage
+import Cafp.Messages
+import Data.Proxy
+import Elm.Module
main :: IO ()
main = putStrLn $ makeElmModule "Messages"
diff --git a/server/lib/Cafp/Main/Server.hs b/server/lib/Cafp/Main/Server.hs
index 6451e17..4b59135 100644
--- a/server/lib/Cafp/Main/Server.hs
+++ b/server/lib/Cafp/Main/Server.hs
@@ -7,6 +7,7 @@ import Cafp.Messages
import Control.Concurrent (threadDelay)
import Control.Concurrent.STM (STM, TVar, newTVar)
import Control.Monad (forever, when)
+import qualified Data.Aeson as Aeson
import qualified Data.HashMap.Strict as HMS
import Data.Text (Text)
import qualified Data.Text as T
@@ -53,9 +54,9 @@ wsApp pc = case routePendingConnection pc of
Just roomId -> do
conn <- WS.acceptRequest pc
WS.forkPingThread conn 30
- WS.sendTextData conn $ "Welcome to room " <> roomId
+ WS.sendTextData conn $ Aeson.encode Welcome
forever $ do
- WS.sendTextData conn $ ("loop data" :: Text)
+ WS.sendTextData conn $ Aeson.encode Bye
threadDelay $ 1 * 1000000
main :: IO ()
diff --git a/server/lib/Cafp/Messages.hs b/server/lib/Cafp/Messages.hs
index e3c28fe..bde199d 100644
--- a/server/lib/Cafp/Messages.hs
+++ b/server/lib/Cafp/Messages.hs
@@ -1,7 +1,13 @@
+{-# LANGUAGE TemplateHaskell #-}
module Cafp.Messages
( ServerMessage (..)
) where
+import Elm.Derive
+
data ServerMessage
= Welcome
+ | Bye
deriving (Show)
+
+deriveBoth defaultOptions ''ServerMessage