;; App wire protocol, carried as length-prefixed JSON over per-peer libp2p
;; streams (net/ gates room membership with the sealed-hello handshake; frames
;; are noise-encrypted end-to-end and `from` is the authenticated peer id).
;;
;; Demo protocol — replace with your app's frames. Keep the shape: a
;; discriminated union on "t" plus a guard applied to every received payload
;; (peers are honest about transport, never about content). Builders emit js
;; objects with quoted string keys — never renamed by :advanced.
(ns __NAME__.game.frames)
(defn is-app-frame [p]
(and (some? p)
(identical? "object" (js* "typeof ~{}" p))
(let [t (unchecked-get p "t")]
(cond
(identical? t "hi") (string? (unchecked-get p "nick"))
(identical? t "note") (and (string? (unchecked-get p "text"))
(number? (unchecked-get p "ts")))
:else false))))
(defn mk-hi [nick]
(js-obj "t" "hi" "nick" nick))
(defn mk-note [text ts]
(js-obj "t" "note" "text" text "ts" ts))