Skip to content

Commit

Permalink
[#13116] Load audio messages from http server
Browse files Browse the repository at this point in the history
  • Loading branch information
flexsurfer committed Feb 23, 2022
1 parent aaf655a commit 74cb257
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
40 changes: 26 additions & 14 deletions src/status_im/ui/screens/chat/message/audio.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
[quo.design-system.colors :as colors]
[status-im.ui.components.icons.icons :as icons]
[status-im.ui.components.react :as react]
[status-im.ui.components.slider :as slider]))
[status-im.ui.components.slider :as slider]
["react-native-blob-util" :default ReactNativeBlobUtil]
[status-im.utils.platform :as platform]
[taoensso.timbre :as log]))

(defonce player-ref (atom nil))
(defonce current-player-message-id (atom nil))
Expand Down Expand Up @@ -110,25 +113,34 @@
#(update-state (merge params {:error (:message %)}))))))
(update-state (merge params {:seek-to-ms value})))

(defn reload-player [{:keys [message-id state-ref] :as params} base64-data on-success]
(defn download-audio-http [base64-uri on-success]
(-> (.config ReactNativeBlobUtil (clj->js {:trusty platform/ios?}))
(.fetch "GET" base64-uri)
(.then #(on-success (.base64 %)))
(.catch #(log/error "could not fetch audio"))))

(defn reload-player [{:keys [message-id state-ref] :as params} audio-url on-success]
;; to avoid reloading player while is initializing,
;; we go ahead only if there is no player or
;; if it is already prepared
(when (or (nil? @player-ref) (audio/can-play? @player-ref))
(when @player-ref
(destroy-player (merge params {:reloading? true})))
(reset! player-ref (audio/new-player
base64-data
{:autoDestroy false
:continuesToPlayInBackground false}
#(seek params 0 true nil)))
(audio/prepare-player
@player-ref
#(when on-success (on-success))
#(update-state (merge params {:error (:message %)})))
(reset! current-player-message-id message-id)
(reset! current-active-state-ref-ref state-ref)
(update-state params)))
(download-audio-http
audio-url
(fn [base64-data]
(reset! player-ref (audio/new-player
(str "data:audio/acc;base64," base64-data)
{:autoDestroy false
:continuesToPlayInBackground false}
#(seek params 0 true nil)))
(audio/prepare-player
@player-ref
#(when on-success (on-success))
#(update-state (merge params {:error (:message %)})))
(reset! current-player-message-id message-id)
(reset! current-active-state-ref-ref state-ref)
(update-state params)))))

(defn play-pause [{:keys [message-id state-ref] :as params} audio]
(if (not= message-id @current-player-message-id)
Expand Down
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im",
"repo": "status-go",
"version": "v0.94.6",
"commit-sha1": "3cc683587dabf16e17a987d1af7b2003faf09d60",
"src-sha256": "1d8f2x7na3scvsgarmfqay5f6nb5x9sh2m6af7lh8d295ia70ha8"
"version": "feature/load-audio-from-http-server",
"commit-sha1": "5821975053e0f877e34f564c79fc80ca4d4397fd",
"src-sha256": "0f84nqncv0rcpdax834cm9sz7w67cd8h39dky3pkr4qjjfchmk5q"
}

0 comments on commit 74cb257

Please sign in to comment.