p2p-db / test / ird / p2p / db / browser / harness.cljs
157 words
 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
(ns ird.p2p.db.browser.harness
  "The browser side of the browser-peer test's coordination with the Node
  harness (ird.p2p.db.browser-peer-test, which drives headless Chrome
  through puppeteer): the configuration arrives in the page's query
  string, progress goes out through globals the Node side polls, and the
  Node side answers through a global the browser polls."
  (:require [clojure.string :as str]))

(defonce config
  ;; :relay the relay's websockets multiaddr, :target the Node peer's
  ;; /p2p-circuit address through it, :address the database's OrbitDB
  ;; address, :secret :app-salt :name the database
  (atom {}))

(defn configure!
  "Read the query string into `config`."
  []
  (let [params (js/URLSearchParams. (.-search js/location))]
    (reset! config (into {} (map (fn [[k v]] [(keyword k) v])) (js/Array.from (.entries params))))))

(defn phase!
  "Announce PHASE (a string) with INFO (a map) to the Node side."
  [phase info]
  (set! (.-__ird_info js/window) (clj->js info))
  (set! (.-__ird_phase js/window) phase)
  nil)

(defn live-cmd
  "The live record the Node side announced ({:hash :marker}), or nil."
  []
  (some-> (.-__ird_live js/window) (js->clj :keywordize-keys true)))

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/p2p-db.git