dev / templates / app-cljs-live / client / src / __NAME__ / social.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
26
27
28
29
30
31
32
33
34
;; The social side: presence to friends, live invite toasts. Its own shadow
;; module (loaded via shadow.lazy after boot — the CLJS equivalent of TS's
;; `void import("ardegazu-social-kit")`) and the ONLY namespace referencing
;; the kit's main entry, so the initial chunk stays lean. Must never break
;; the app.
;;
;; Leaderboard games additionally construct soc/GameLb here and route its
;; lbq/lbs/lbr frames FIRST in main's onMessage — game1's social.cljs is the
;; worked example.
(ns __NAME__.social
  (:require ["ardegazu-social-kit" :as soc]
            [__NAME__.config :as config]
            [__NAME__.i18n :as i18n]))

(defn setup!
  "cfg: js obj (ident net myName). Attaches the social agent to the node's
   pubsub."
  [^js cfg]
  (let [ident ^js (unchecked-get cfg "ident")
        net ^js (unchecked-get cfg "net")
        boot ^js (unchecked-get ident "boot")
        lp ^js (unchecked-get net "libp2p")
        bridge ^js (unchecked-get ident "bridge")
        rec (.lastRecord bridge)]
    (soc/attachSocial
     (js-obj "ns" (unchecked-get ident "ns")
             "app" (aget (.split config/APP-SALT "/") 0)
             "identity" (unchecked-get boot "identity")
             "seed" (unchecked-get boot "seed")
             "myName" (unchecked-get cfg "myName")
             "pubsub" (unchecked-get (.-services lp) "pubsub")
             "soc" (when (some? rec) (unchecked-get rec "soc"))
             "roomLink" (fn [] (.-href js/location))
             "t" i18n/t-kit))))

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