[server] Add new structure for server applications

This commit is contained in:
Joscha 2020-03-15 00:59:18 +00:00
parent 04b8bd7445
commit cdfe515df6
4 changed files with 128 additions and 16 deletions

View file

@ -2,15 +2,10 @@
module Main where
import Control.Concurrent.MVar
import qualified Network.WebSockets as WS
import qualified Network.WebSockets as WS
import Forest.Node
import Forest.Server
import Forest.Server.Broadcast
import Forest.Server.TreeModule.Const
import Forest.Server.TreeModule.Fork
import Forest.Server.TreeModule.SharedEditing
import Forest.Server.TreeApp
pingDelay :: Int
pingDelay = 10
@ -23,15 +18,14 @@ options = WS.defaultServerOptions
{ WS.serverRequirePong = Just pongDelay
}
app :: TreeApp Node ()
app = TreeApp
{ appGraft = id
, appHandleEvent = \s _ -> pure $ continue s
, appConstructor = simpleConstructor $ txtNode "" "Hello world"
}
main :: IO ()
main = do
putStrLn "Preparing shared edit module"
sharedEditNodeVar <- newMVar $ txtNode "r" ""
sharedEditBroadcaster <- newBroadcaster
putStrLn "Starting server"
WS.runServerWithOptions options $ serverApp pingDelay $ forkModule "Forest"
[ ProngConstructor "Test" $ constModule $ newNode "" "" [txtNode "" "Bla"]
, ProngConstructor "Sandbox" $ sharedEditingModule sharedEditNodeVar sharedEditBroadcaster
, ProngConstructor "About" $ constModule projectDescriptionNode
]
WS.runServerWithOptions options $ runTreeApp pingDelay Nothing app