From fe81ccdd9a3d2e3f2654be20f896e9ee6d7c833d Mon Sep 17 00:00:00 2001 From: Miguel Ángel Moreno Date: Tue, 3 Jan 2023 15:46:32 +0100 Subject: feat(frontend): Add support for stream format selection --- src/frontend/tau/events.cljs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/frontend/tau/events.cljs') diff --git a/src/frontend/tau/events.cljs b/src/frontend/tau/events.cljs index 12404dc..dace6f5 100644 --- a/src/frontend/tau/events.cljs +++ b/src/frontend/tau/events.cljs @@ -309,11 +309,12 @@ {:nextPage (js/encodeURIComponent next-page-url)}) :db (assoc db :show-pagination-loading true))))) -(rf/reg-event-db +(rf/reg-event-fx ::load-stream - (fn [db [_ res]] - (assoc db :stream (js->clj res :keywordize-keys true) - :show-page-loading false))) + (fn [{:keys [db]} [_ res]] + {:db (assoc db :stream (js->clj res :keywordize-keys true) + :show-page-loading false) + :fx [[:dispatch [::change-stream-format nil]]]})) (rf/reg-event-fx ::get-stream @@ -323,6 +324,16 @@ [::load-stream] [::bad-response]) :db (assoc db :show-page-loading true)))) +(rf/reg-event-db + ::change-stream-format + (fn [{:keys [stream] :as db} [_ format-id]] + (let [{:keys [audio-streams video-streams]} stream] + (if format-id + (assoc db :stream-format + (first (filter #(= format-id (:id %)) (apply conj audio-streams video-streams)))) + (assoc db :stream-format (-> (if (empty? video-streams) audio-streams video-streams) + last)))))) + (rf/reg-event-db ::load-channel (fn [db [_ res]] -- cgit v1.2.3