enhance(rtc,crypt): upload public-key when device not exists

This commit is contained in:
rcmerci
2024-10-11 18:09:36 +08:00
committed by Tienson Qin
parent 6bcdf2bbf4
commit 923c043a15
4 changed files with 87 additions and 54 deletions

View File

@@ -59,3 +59,25 @@
(defn get-ws-url
[token]
(gstring/format @worker-state/*rtc-ws-url token))
(defn- new-task--get-ws-create
"Return a map with atom *current-ws and a task
that get current ws, create one if needed(closed or not created yet)"
[url & {:keys [retry-count open-ws-timeout]
:or {retry-count 10 open-ws-timeout 10000}}]
(let [*current-ws (atom nil)
ws-create-task (ws/mws-create url {:retry-count retry-count :open-ws-timeout open-ws-timeout})]
{:*current-ws *current-ws
:get-ws-create-task
(m/sp
(let [ws @*current-ws]
(if (and ws
(not (ws/closed? ws)))
ws
(let [ws (m/? ws-create-task)]
(reset! *current-ws ws)
ws))))}))
(def new-task--get-ws-create--memoized
"Return a memoized task to reuse the same websocket."
(memoize new-task--get-ws-create))