This commit is contained in:
Ulises M 2024-10-29 21:17:56 -06:00
parent 8e38393f04
commit 276eea2a5c
No known key found for this signature in database
GPG Key ID: 5A15782EB758534E
4 changed files with 29 additions and 25 deletions

View File

@ -11,7 +11,8 @@
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.transforms :as types])) [utils.transforms :as types]))
(defn- extract-from-native-modules [module] (defn- extract-from-native-modules
[module]
(if status-im.config/STATUS_BACKEND_ENABLED (if status-im.config/STATUS_BACKEND_ENABLED
status-backend/fetch-js-obj status-backend/fetch-js-obj
(some-> react-native (some-> react-native
@ -36,7 +37,9 @@
[handler] [handler]
(if status-im.config/STATUS_BACKEND_ENABLED (if status-im.config/STATUS_BACKEND_ENABLED
(status-backend/init-web-socket handler) (status-backend/init-web-socket handler)
(.addListener ^js (.-DeviceEventEmitter ^js react-native) "gethEvent" #(handler (.-jsonEvent ^js %))))) (.addListener ^js (.-DeviceEventEmitter ^js react-native)
"gethEvent"
#(handler (.-jsonEvent ^js %)))))
(defn clear-web-data (defn clear-web-data
[] []

View File

@ -7,7 +7,7 @@
":" ":"
status-im.config/STATUS_BACKEND_PORT)) status-im.config/STATUS_BACKEND_PORT))
(def ^:private data-dir-path (def data-dir-path
(str status-im.config/STATUS_BACKEND_STORAGE_DIR "/data")) (str status-im.config/STATUS_BACKEND_STORAGE_DIR "/data"))
(def ^:private public-storage-dir (def ^:private public-storage-dir

View File

@ -1,10 +1,10 @@
(ns status-backend.core (ns status-backend.core
(:require (:require
[status-backend.config :as config]
[utils.network.core :as network]
[clojure.string :as string] [clojure.string :as string]
[oops.core :as oops] [oops.core :as oops]
[taoensso.timbre :as log])) [status-backend.config :as config]
[taoensso.timbre :as log]
[utils.network.core :as network]))
(def ^:private default-fetch-params (def ^:private default-fetch-params
{:method :POST {:method :POST
@ -21,7 +21,8 @@
params (assoc default-fetch-params :body body-params)] params (assoc default-fetch-params :body body-params)]
(network/fetch url params callback)))) (network/fetch url params callback))))
(defn- method-name->endpoint [s] (defn- method-name->endpoint
[s]
(let [first-letter-capitalized (string/capitalize (first s))] (let [first-letter-capitalized (string/capitalize (first s))]
(str first-letter-capitalized (subs s 1)))) (str first-letter-capitalized (subs s 1))))
@ -36,11 +37,10 @@
(let [endpoint (method-name->endpoint native-module-method-name)] (let [endpoint (method-name->endpoint native-module-method-name)]
(partial fetch endpoint)))})) (partial fetch endpoint)))}))
(declare web-socket) (defn init-web-socket
[on-message]
(defn init-web-socket [on-message] (let [web-socket (js/WebSocket. config/signals-url)]
(defonce web-socket (js/WebSocket. config/signals-url))
(oops/oset! web-socket "onopen" #(log/debug "[backend] Web Socket connected")) (oops/oset! web-socket "onopen" #(log/debug "[backend] Web Socket connected"))
(oops/oset! web-socket "onmessage" #(-> % (oops/oget "data") (on-message))) (oops/oset! web-socket "onmessage" #(-> % (oops/oget "data") on-message))
(oops/oset! web-socket "onerror" #(log/error "[backend] Web Socket error" %)) (oops/oset! web-socket "onerror" #(log/error "[backend] Web Socket error" %))
(oops/oset! web-socket "onclose" #(log/error "[backend] Web Socket closed" %))) (oops/oset! web-socket "onclose" #(log/debug "[backend] Web Socket closed" %))))

View File

@ -42,7 +42,8 @@
(map :error) (map :error)
(not-any? identity))) (not-any? identity)))
(defn fetch [url {:keys [body] :as params} callback] (defn fetch
[url {:keys [body] :as params} callback]
(let [js-params (cond-> params (let [js-params (cond-> params
(map? body) (update :body (comp js/JSON.stringify clj->js)) (map? body) (update :body (comp js/JSON.stringify clj->js))
:always clj->js)] :always clj->js)]