(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)))