on master help sign in
round-trip relationTrue in websocket server test
commit85ca65f54d3b2461de963823fe7e7e30dea8a151 authorAgentM <agentm@themactionfaction.com> dateFri 5 Aug 2016, 17:17 (10 years ago) parent2e87d05
6 files changed+18−20
ProjectM36/Server/RemoteCallTypes/Json.hs+3−2 ProjectM36/Server/WebSocket.hs+1−18 ProjectM36/Server/WebSocket/Main.hs+14 ProjectM36/Server/project-m36.js → ProjectM36/Server/WebSocket/project-m36.js ProjectM36/Server/websocket-client.html → ProjectM36/Server/WebSocket/websocket-client.html ProjectM36/Server/websocket-client.js → ProjectM36/Server/WebSocket/websocket-client.js
ProjectM36/Server/RemoteCallTypes/Json.hs+3−2
@@ -5,7 +5,6 @@ import ProjectM36.Server.RemoteCallTypes
55import ProjectM36.Base
66import ProjectM36.ConcreteTypeRep
77import ProjectM36.Error
8−import Control.Exception (IOException)
98
109import Data.Aeson
1110import Data.UUID.Aeson ()
@@ -122,7 +121,9 @@ instance FromJSON Atom where
122121 case atype of
123122 AnyAtomType -> fail "cannot pass AnyAtomType over the wire"
124123 caType@(ConstructedAtomType _ _) -> ConstructedAtom <$> o .: "dataconstructorname" <*> pure caType <*> o .: "atom"
125− RelationAtomType _ -> error "not implemented"
124+ RelationAtomType _ -> do
125+ rel <- o .: "val"
126+ pure $ Atom (rel :: Relation)
126127 AtomType cTypeRep -> if unCTR cTypeRep == typeRep (Proxy :: Proxy Int) then
127128 intAtom <$> o .: "val"
128129 else if unCTR cTypeRep == typeRep (Proxy :: Proxy Text) then
ProjectM36/Server/WebSocket.hs+1−18
@@ -1,4 +1,4 @@
1−--module ProjectM36.Server.WebSocket where
1+module ProjectM36.Server.WebSocket where
22-- while the tutd client performs TutorialD parsing on the client, the websocket server will pass tutd to be parsed and executed on the server- otherwise I have to pull in ghcjs as a dependency to allow client-side parsing- that's not appealing because then the frontend is not language-agnostic, but this could change in the future, perhaps by sending different messages over the websocket
33-- ideally, the wire protocol should not be exposed to a straight string-based API ala SQL, so we could make perhaps a javascript DSL which compiles to the necessary JSON- anaylyze tradeoffs
44
@@ -13,29 +13,12 @@ import Data.Aeson
1313import TutorialD.Interpreter
1414import TutorialD.Interpreter.Base
1515import ProjectM36.Client
16−import ProjectM36.Server
17−import ProjectM36.Server.ParseArgs
18−import ProjectM36.Server.Config
19−import Control.Concurrent
2016import Control.Exception
2117
2218-- | Called when the project-m36-server exits.
2319failureHandler :: Either SomeException Bool -> IO ()
2420failureHandler = error "project-m36-server exited unexpectedly"
2521
26−main :: IO ()
27−main = do
28− -- launch normal project-m36-server
29− portMVar <- newEmptyMVar
30− serverConfig <- parseConfig
31− let serverHost = bindHost serverConfig
32− _ <- forkFinally (launchServer serverConfig (Just portMVar)) failureHandler
33− --wait for server to be listening
34− serverPort <- takeMVar portMVar
35− --this built-in server is apparently not meant for production use, but it's easier to test than starting up the wai or snap interfaces
36− putStrLn "listening on 8888"
37− WS.runServer "0.0.0.0" 8888 (websocketProxyServer serverPort serverHost)
38−
3922websocketProxyServer :: Port -> Hostname -> WS.ServerApp
4023websocketProxyServer port host pending = do
4124 conn <- WS.acceptRequest pending
ProjectM36/Server/WebSocket/Main.hsnew file+14
@@ -0,0 +1,14 @@
1+import ProjectM36.Server.WebSocket
2+
3+main :: IO ()
4+main = do
5+ -- launch normal project-m36-server
6+ portMVar <- newEmptyMVar
7+ serverConfig <- parseConfig
8+ let serverHost = bindHost serverConfig
9+ _ <- forkFinally (launchServer serverConfig (Just portMVar)) failureHandler
10+ --wait for server to be listening
11+ serverPort <- takeMVar portMVar
12+ --this built-in server is apparently not meant for production use, but it's easier to test than starting up the wai or snap interfaces
13+ WS.runServer "0.0.0.0" 8888 (websocketProxyServer serverPort serverHost)
14+
ProjectM36/Server/project-m36.js → ProjectM36/Server/WebSocket/project-m36.jsrenamed

The content is the same.

ProjectM36/Server/websocket-client.html → ProjectM36/Server/WebSocket/websocket-client.htmlrenamed

The content is the same.

ProjectM36/Server/websocket-client.js → ProjectM36/Server/WebSocket/websocket-client.jsrenamed

The content is the same.