awful-sse/examples/example1.scm

28 lines
741 B
Scheme
Raw Normal View History

2014-07-08 02:37:35 +00:00
;; Run with 'awful example1.scm'.
;; On web browser open http://localhost:8080/client and watch the
2014-07-08 02:01:53 +00:00
;; new time coming each second from the server.
(use awful-sse awful spiffy posix srfi-18)
(define (sse-proc)
(let loop ()
(send-sse-data (seconds->string) id: (random 10) event: "message")
(thread-sleep! 1)
(loop)))
(define-page/sse "/client"
(lambda ()
(add-javascript
"var source = new EventSource('/sse');
source.onmessage = function (event) {
display = document.getElementById('display');
display.innerHTML = event.data;
};")
(add-css "#display { color: blue; }")
`(div "Current time: "
(span (@ (id "display")) "")))
"/sse"
sse-proc
use-sxml: #t)