HS: socket on-message + as JSON (+3)

Steps 4-5 complete: hs-try-json-parse, ws.onmessage wiring (text/JSON
dispatch), onmessage test cases. 8/16 socket tests passing.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 10:43:38 +00:00
parent ce39a35c6b
commit e9ea1bf160
4 changed files with 112 additions and 3 deletions

View File

@@ -2528,6 +2528,10 @@
;; ── WebSocket / socket feature ───────────────────────────────────
(define
hs-try-json-parse
(fn (s) (host-call (host-global "JSON") "parse" s)))
(define
hs-socket-register!
(fn
@@ -2553,6 +2557,27 @@
wrapper
"rpc"
(host-call proxy-factory "call" nil wrapper))))
(host-set!
ws
"onmessage"
(host-callback
(fn
(event)
(let
((data (host-get event "data")))
(let
((parsed (hs-try-json-parse data)))
(cond
((and (not (nil? parsed)) (not (nil? (host-get parsed "iid"))))
nil)
((not (nil? handler))
(if
json?
(if
(not (nil? parsed))
(handler parsed)
(error "Received non-JSON message"))
(handler event)))))))))
(define
bind-path!
(fn