dev / templates / app-cljs-live / client / src / __NAME__ / game / frames.cljs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
;; 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))

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/dev.git