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,12 +11,13 @@
[taoensso.timbre :as log]
[utils.transforms :as types]))
(defn- extract-from-native-modules [module]
(defn- extract-from-native-modules
[module]
(if status-im.config/STATUS_BACKEND_ENABLED
status-backend/fetch-js-obj
(some-> react-native
(oops/gobj-get "NativeModules")
(oops/gobj-get module))))
(oops/gobj-get "NativeModules")
(oops/gobj-get module))))
(defn status [] (extract-from-native-modules "Status"))
(defn account-manager [] (extract-from-native-modules "AccountManager"))
@ -36,7 +37,9 @@
[handler]
(if status-im.config/STATUS_BACKEND_ENABLED
(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
[]

View File

@ -7,7 +7,7 @@
":"
status-im.config/STATUS_BACKEND_PORT))
(def ^:private data-dir-path
(def data-dir-path
(str status-im.config/STATUS_BACKEND_STORAGE_DIR "/data"))
(def ^:private public-storage-dir
@ -17,4 +17,4 @@
(def signals-url (str url "/signals"))
(def keystore-dir-path (str data-dir-path "/keystore"))
(def log-dir-path (str data-dir-path "/log"))
(def log-request-file-path (str public-storage-dir "/requests.log"))
(def log-request-file-path (str public-storage-dir "/requests.log"))

View File

@ -1,10 +1,10 @@
(ns status-backend.core
(:require
[status-backend.config :as config]
[utils.network.core :as network]
[clojure.string :as string]
[oops.core :as oops]
[taoensso.timbre :as log]))
[clojure.string :as string]
[oops.core :as oops]
[status-backend.config :as config]
[taoensso.timbre :as log]
[utils.network.core :as network]))
(def ^:private default-fetch-params
{:method :POST
@ -21,7 +21,8 @@
params (assoc default-fetch-params :body body-params)]
(network/fetch url params callback))))
(defn- method-name->endpoint [s]
(defn- method-name->endpoint
[s]
(let [first-letter-capitalized (string/capitalize (first s))]
(str first-letter-capitalized (subs s 1))))
@ -31,16 +32,15 @@
This call: (.myMethod fetch-js-obj params)
Is the same as: (fetch \"MyMethod\" params)
"
(js/Proxy. #js{}
#js{:get (fn [_target native-module-method-name]
(let [endpoint (method-name->endpoint native-module-method-name)]
(partial fetch endpoint)))}))
(js/Proxy. #js {}
#js {:get (fn [_target native-module-method-name]
(let [endpoint (method-name->endpoint native-module-method-name)]
(partial fetch endpoint)))}))
(declare web-socket)
(defn init-web-socket [on-message]
(defonce web-socket (js/WebSocket. config/signals-url))
(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 "onerror" #(log/error "[backend] Web Socket error" %))
(oops/oset! web-socket "onclose" #(log/error "[backend] Web Socket closed" %)))
(defn init-web-socket
[on-message]
(let [web-socket (js/WebSocket. config/signals-url)]
(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 "onerror" #(log/error "[backend] Web Socket error" %))
(oops/oset! web-socket "onclose" #(log/debug "[backend] Web Socket closed" %))))

View File

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