add connected/disconnected text
[mudsync.git] / mudsync / networking.scm
index 1a8ece5002b4e47fad5c433e3e9cace5cdc8863c..b541c1ee99da72ff881e73c2a6bfc0b2e4891e3d 100644 (file)
@@ -26,6 +26,9 @@
   #:use-module (ice-9 receive)
   #:use-module (oop goops)
 
+  ;; Formatting
+  #:use-module (mudsync scrubl)
+
   ;; used by web server only
   #:use-module (sxml simple)
   #:use-module (web request)
 
 (define* (nm-send-to-client-id nm message #:key client data)
   "Send DATA to TO-CLIENT id"
+  (define formatted-data
+    (scrubl-write scrubl-sxml data))
   (define client-obj (hash-ref (nm-clients nm) client))
   (match client-obj
     (#f (throw 'no-such-client
                "Asked to send data to client but that client doesn't exist"
                #:client-id client
-               #:data data))
+               #:data formatted-data))
     (('socket . client-socket)
-     (display data client-socket))
+     (display formatted-data client-socket))
     (('websocket . ws-client-id)
-     (<- (.web-server nm) 'ws-send ws-client-id data))))
+     (<- (.web-server nm) 'ws-send ws-client-id formatted-data))))
 
 (define (nm-incoming-line-action nm message client-id line)
   "Handle LINE coming in, probably from an external message handler,
@@ -244,7 +249,11 @@ like the web one"
                 ;;      (p (b "<bar>") " Last one!"))
                 ))
       (div (@ (id "input-metabox"))
-           (input (@ (id "main-input"))))))
+           (input (@ (id "main-input")))
+           " "
+           (span (@ (id "connection-status")
+                    (class "disconnected"))
+                 "[disconnected]"))))
 
   (define (main-tmpl)
     `(html (@ (xmlns "http://www.w3.org/1999/xhtml"))