From 516ec0843664fcf1513a490d181830143aec818f Mon Sep 17 00:00:00 2001 From: Mahesh Bandara Wijerathna Date: Tue, 21 May 2024 10:37:53 +0530 Subject: [PATCH] [ModPlayVOD, ws_util] Add support for streaming VODs --- backend/src/ws_util.rs | 29 ++++++++++++++++ frontend/src/assets/styles/common.scss | 1 + frontend/src/components/BlockVODCard.vue | 15 ++++++++- frontend/src/components/ModPlayVOD.vue | 42 ++++++++++++++++++++++++ frontend/src/modules/ws-util.js | 5 +++ frontend/src/pages/Landing.vue | 22 ++++++++++++- frontend/src/store/modPlayVOD.js | 20 +++++++++++ 7 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 frontend/src/components/ModPlayVOD.vue create mode 100644 frontend/src/store/modPlayVOD.js diff --git a/backend/src/ws_util.rs b/backend/src/ws_util.rs index b12d6d4..59eb7bd 100644 --- a/backend/src/ws_util.rs +++ b/backend/src/ws_util.rs @@ -80,6 +80,8 @@ fn handle_ws_client(socket: &SocketRef) { socket.on("verify-url", handle_verify_url_event); + socket.on("get-playable", handle_get_playable_event); + socket.on("download", handle_download_event); socket.on("cancel-download", handle_cancel_download_event); @@ -267,6 +269,33 @@ async fn handle_verify_url_event(ack: AckSender, Data(data): Data) { } } +/// Handles the `get-playable` WS event. +async fn handle_get_playable_event(ack: AckSender, Data(data): Data) { + if let Ok(url) = serde_json::from_value::(data) { + match get_vod_meta(url.as_str()).await { + Ok(mut vod) => { + if !vod.access { + return send_error( + ack, + "You need a Fight Pass subscription to watch this video", + ); + } + + match get_vod_stream_url(vod.id).await { + Ok(hls) => { + vod.hls = hls; + ack.send(vod).ok(); + } + Err(error) => send_error(ack, error), + } + } + Err(error) => send_error(ack, error), + } + } else { + send_error(ack, "Invalid video play request"); + } +} + /// Handles the `download` WS event. async fn handle_download_event(ack: AckSender, Data(mut data): Data) { if let (Ok(mut vod), Some(is_restart)) = ( diff --git a/frontend/src/assets/styles/common.scss b/frontend/src/assets/styles/common.scss index d39fccf..51054f3 100644 --- a/frontend/src/assets/styles/common.scss +++ b/frontend/src/assets/styles/common.scss @@ -23,6 +23,7 @@ body { } & > i { + border-radius: 0; font-size: 26rem; } } diff --git a/frontend/src/components/BlockVODCard.vue b/frontend/src/components/BlockVODCard.vue index f9f01ab..ed0e8ed 100644 --- a/frontend/src/components/BlockVODCard.vue +++ b/frontend/src/components/BlockVODCard.vue @@ -13,6 +13,14 @@
+