From 78808161c6b8726be5e18427a5da4328ab1fa26f Mon Sep 17 00:00:00 2001 From: Arjun Satarkar Date: Mon, 29 Jul 2024 01:10:14 +0530 Subject: Refactor --- lib/mediasync/router.ex | 23 +++++++++-------------- lib/mediasync/templates.ex | 13 ++++++++----- priv/discord_activity.html.eex | 10 ++++++---- priv/home.html.eex | 10 +++++----- priv/room.html.eex | 32 +++++++++++++++++++++++++++++--- priv/static/room/main.js | 4 ++-- 6 files changed, 59 insertions(+), 33 deletions(-) diff --git a/lib/mediasync/router.ex b/lib/mediasync/router.ex index 2a80882..2e8b421 100644 --- a/lib/mediasync/router.ex +++ b/lib/mediasync/router.ex @@ -42,7 +42,7 @@ defmodule Mediasync.Router do enable_discord_activity? and Map.has_key?(conn.query_params, query_param_discord_activity_inner()) -> - send_resp(conn, 200, Mediasync.Templates.home(:discord_activity)) + send_resp(conn, 200, Mediasync.Templates.home(true)) true -> send_resp(conn, 200, Mediasync.Templates.home()) @@ -112,24 +112,19 @@ defmodule Mediasync.Router do case Registry.lookup(Mediasync.RoomRegistry, room_id) do [{pid, _value}] -> - video_info = Mediasync.Room.get_video_info(pid) - - {video_info, websocket_path, state_url, home_url} = - if Application.fetch_env!(:mediasync, :enable_discord_activity?) and - Map.has_key?(conn.query_params, query_param_discord_activity_inner()) do - {%{video_info | url: "/.proxy/room/#{room_id}/video"}, - "/.proxy/room/#{room_id}/websocket?#{query_param_discord_activity_inner()}", - "/.proxy/room/#{room_id}/state.json?#{query_param_discord_activity_inner()}", - "/.proxy/?#{query_param_discord_activity_inner()}"} - else - {video_info, "/room/#{room_id}/websocket", "/room/#{room_id}/state.json", nil} - end + in_discord_activity? = + Application.fetch_env!(:mediasync, :enable_discord_activity?) and + Map.has_key?(conn.query_params, query_param_discord_activity_inner()) conn |> put_html_content_type() |> send_resp( 200, - Mediasync.Templates.room(video_info, websocket_path, state_url, home_url) + Mediasync.Templates.room( + Mediasync.Room.get_video_info(pid), + room_id, + in_discord_activity? + ) ) [] -> diff --git a/lib/mediasync/templates.ex b/lib/mediasync/templates.ex index c6b15cc..b9ef937 100644 --- a/lib/mediasync/templates.ex +++ b/lib/mediasync/templates.ex @@ -2,16 +2,19 @@ defmodule Mediasync.Templates do require EEx def home() do - home(:normal) + home(false) end - EEx.function_from_file(:def, :home, "priv/home.html.eex", [:mode]) + def room(video_info, room_id) do + room(video_info, room_id, false) + end + + EEx.function_from_file(:def, :home, "priv/home.html.eex", [:in_discord_activity?]) EEx.function_from_file(:def, :room, "priv/room.html.eex", [ :video_info, - :websocket_path, - :state_url, - :home_url + :room_id, + :in_discord_activity? ]) EEx.function_from_file(:def, :discord_activity, "priv/discord_activity.html.eex") diff --git a/priv/discord_activity.html.eex b/priv/discord_activity.html.eex index 5cb8a68..cfdba73 100644 --- a/priv/discord_activity.html.eex +++ b/priv/discord_activity.html.eex @@ -1,5 +1,8 @@ -<% home_url="/.proxy/?#{Mediasync.Constants.query_param_discord_activity_inner()}" %> +<% +import Mediasync.Constants +home_url="/.proxy/?#{query_param_discord_activity_inner()}" +%> @@ -72,15 +75,14 @@ currently hosting:
- diff --git a/priv/static/room/main.js b/priv/static/room/main.js index 7e0ade5..9a0b2ec 100644 --- a/priv/static/room/main.js +++ b/priv/static/room/main.js @@ -40,10 +40,10 @@ { let customIconPosition = 1; const Button = videojs.getComponent("Button"); - if (HOME_URL !== null) { + if (HOME_BUTTON_URL !== null) { const homeButton = new Button(player, { clickHandler: (_) => { - location = HOME_URL; + location = HOME_BUTTON_URL; }, }); homeButton.addClass("icon-home"); -- cgit v1.2.3-57-g22cb