X-Git-Url: https://jxself.org/git/?p=mudsync.git;a=blobdiff_plain;f=mudsync%2Fnetworking.scm;h=4417cfd27e898f4061992aad69bc65f820c58216;hp=6f60ad971d8f15b7b2d351820a283168d4184f36;hb=0ea9e56921f887613da5472f12c1e2ae229cb829;hpb=16299416786d528400f22d4d0c07bd3bbeb90ae3 diff --git a/mudsync/networking.scm b/mudsync/networking.scm index 6f60ad9..4417cfd 100644 --- a/mudsync/networking.scm +++ b/mudsync/networking.scm @@ -32,6 +32,7 @@ #:use-module (web response) #:use-module (web uri) #:use-module (mudsync package-config) + #:use-module (mudsync contrib mime-types) #:use-module (rnrs io ports) #:export (;; Should we be exporting these? @@ -205,40 +206,43 @@ (pk 'web-server (create-actor nm #:port web-server-port #:http-handler (wrap-apply http-handler) - #:websocket-handler (wrap-apply websocket-handler))))) + #:on-ws-message (wrap-apply websocket-new-message))))) (define (view:main-display request body) + (define one-entry + '(div (@ (class "stream-entry")) + (p (b "") " Wow, it's so shiny!"))) + (define body-tmpl - '(body - (@ (style "display: flex; flex-direction: column; align-content: stretch; align-items: stretch;")) - (div (@ (style "background: #555555; flex: 1;") - (id "stream-output")) - (p "nope")) - (div (@ (id "input-box") - (style "flex: 1; background: #000055;")) - (p "test test") + `((div (@ (id "stream-metabox")) + (div (@ (id "stream")) + ,@(map (const one-entry) (iota 25)) + (div (@ (class "stream-entry")) + (p (b "") " Last one!")))) + (div (@ (id "input-metabox")) (input (@ (id "input")))))) (define (main-tmpl) - `(html (@ (xmlns "http://www.w3.org/1999/xhtml") - (style "width: 100%; height: 100%;")) - (head - (title "Mudsync!") - (meta (@ (charset "UTF-8")))) - ,body-tmpl)) + `(html (@ (xmlns "http://www.w3.org/1999/xhtml")) + (head (title "Mudsync!") + (meta (@ (charset "UTF-8"))) + (link (@ (rel "stylesheet") + (href "/static/css/main.css"))) + (script (@ (type "text/javascript") + (src "/static/js/mudsync.js")))) + (body ,@body-tmpl))) (define (write-template-to-string) (with-fluids ((%default-port-encoding "UTF-8")) - (with-output-to-string - (lambda () - (sxml->xml (main-tmpl)))))) + (call-with-output-string + (lambda (p) + (sxml->xml (main-tmpl) p))))) (values (build-response #:code 200 #:headers '((content-type . (application/xhtml+xml)))) (write-template-to-string))) (define (view:render-static request body static-path) (values (build-response #:code 200 - ;; #:content-type (mime-type static-path) - ) + #:headers `((content-type . (,(mime-type static-path))))) (call-with-input-file (web-static-filepath static-path) get-bytevector-all))) (define (view:standard-four-oh-four . args) @@ -266,7 +270,9 @@ ;; Respond to text messages by reversing the message. Respond to ;; binary messages with "hello". -(define (websocket-handler data) - (if (string? data) - (string-reverse data) - "hello")) +(define (websocket-new-message websocket-server client-id data) + (<- (actor-id websocket-server) 'ws-send + client-id + (if (string? data) + (string-reverse data) + "hello")))