on master help sign in
WIP verifying that JSON is sent over websocket
commiteaac48189303399215a0ae61b784f1f687a681e8 authorAgentM <agentm@themactionfaction.com> dateSat 23 Jul 2016, 23:49 (10 years ago) parentaa45cff
3 files changed+43−4
ProjectM36/Server/RemoteCallTypes/Json.hs+1−1 ProjectM36/Server/WebSocket.hs+5−3 ProjectM36/Server/websocket-test.html+37
ProjectM36/Server/RemoteCallTypes/Json.hs+1−1
@@ -88,7 +88,7 @@ instance FromJSON Atom where
8888 case atype of
8989 AnyAtomType -> fail "cannot pass AnyAtomType over the wire"
9090 caType@(ConstructedAtomType _ _) -> ConstructedAtom <$> o .: "dataconstructorname" <*> pure caType <*> o .: "atom"
91− RelationAtomType _ -> undefined
91+ RelationAtomType _ -> error "not implemented"
9292 AtomType cTypeRep -> if unCTR cTypeRep == typeRep (Proxy :: Proxy Int) then
9393 intAtom <$> o .: "val"
9494 else if unCTR cTypeRep == typeRep (Proxy :: Proxy Text) then
ProjectM36/Server/WebSocket.hs+5−3
@@ -4,7 +4,10 @@
44import Control.Monad (forever)
55import qualified Data.Text as T
66import qualified Network.WebSockets as WS
7−import ProjectM36.Server.RemoteCallTypes.Json
7+import ProjectM36.Server.RemoteCallTypes.Json ()
8+import ProjectM36.Base
9+import qualified Data.Set as S
10+import Data.Aeson
811
912main :: IO ()
1013main = do
@@ -17,8 +20,7 @@ application pending = do
1720 forever $ do
1821 msg <- (WS.receiveData conn) :: IO T.Text
1922 case msg of
20− "hello" -> WS.sendTextData conn ("nice" :: T.Text)
21− "bye" -> WS.sendClose conn ("bye" :: T.Text)
23+ "db" -> WS.sendTextData conn (encode (Project (AttributeNames (S.fromList ["spam1", "spam2"])) (RelationVariable "elgringo")))
2224 str -> WS.sendTextData conn str
2325 return ()
2426
ProjectM36/Server/websocket-test.htmlnew file+37
@@ -0,0 +1,37 @@
1+<html>
2+<head>
3+<script>
4+ var socket = new WebSocket("ws://localhost:8888");
5+ socket.onopen = function(event) {
6+ //socket.send("smoked");
7+ console.log("connected");
8+ setStatus("connected");
9+ }
10+ socket.onerror = function(event) {
11+ console.log("error: " + event);
12+ }
13+ socket.onmessage = function (event) {
14+ console.log("message received: " + event.data);
15+ }
16+ socket.onclose = function(event) {
17+ console.log("conn closed: " + event);
18+ setStatus("disconnected");
19+ }
20+
21+function setStatus(text)
22+{
23+ newtext = document.createTextNode(text);
24+ statusnode = document.getElementById("status");
25+ while( statusnode.firstChild ) {
26+ statusnode.removeChild( statusnode.firstChild );
27+ }
28+ statusnode.appendChild(newtext);
29+}
30+
31+</script>
32+</head>
33+<body>
34+<p>Status:<span id="status">Fresh</span></p>
35+
36+</body>
37+</html>