aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/mediasync/router.ex23
-rw-r--r--lib/mediasync/templates.ex13
-rw-r--r--priv/discord_activity.html.eex10
-rw-r--r--priv/home.html.eex10
-rw-r--r--priv/room.html.eex32
-rw-r--r--priv/static/room/main.js4
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()}" %>
<!DOCTYPE html>
+<%
+import Mediasync.Constants
+home_url="/.proxy/?#{query_param_discord_activity_inner()}"
+%>
<html lang="en">
<head>
@@ -72,15 +75,14 @@
<span style="font-weight: bold;">currently hosting:</span>
<div id="instance-room-info-content"></div>
</div>
- </div>
<iframe src="<%= home_url %>" style="display: none;" class="at-home" name="activity-inner-iframe"></iframe>
<script>
- const QUERY_PARAM_DISCORD_ACTIVITY_INNER = "<%= Mediasync.Constants.query_param_discord_activity_inner() %>";
+ const QUERY_PARAM_DISCORD_ACTIVITY_INNER = "<%= query_param_discord_activity_inner() %>";
const DISCORD_CLIENT_ID = "<%= Application.fetch_env!(:mediasync, :discord_client_id) %>";
const ACCESS_TOKEN_URL = `/.proxy/discord_activity/access_token?${QUERY_PARAM_DISCORD_ACTIVITY_INNER}`;
const HOME_URL = "<%= home_url %>";
const roomsForInstanceUrl = (instanceId) => {
- return `/.proxy/discord_activity/rooms_for_instance?${QUERY_PARAM_DISCORD_ACTIVITY_INNER}&instance_id=${instanceId}`;
+ return `/.proxy/discord_activity/rooms_for_instance?${QUERY_PARAM_DISCORD_ACTIVITY_INNER}&<%= query_param_instance_id() %>=${instanceId}`;
};
const roomUrl = (roomId) => {
return `/.proxy/room/${roomId}?${QUERY_PARAM_DISCORD_ACTIVITY_INNER}`;
diff --git a/priv/home.html.eex b/priv/home.html.eex
index 4b6accd..87b0d5d 100644
--- a/priv/home.html.eex
+++ b/priv/home.html.eex
@@ -1,11 +1,11 @@
+<!DOCTYPE html>
<%
-{form_action_base, form_action_suffix} = case mode do
- :discord_activity -> {"/.proxy/", "?#{Mediasync.Constants.query_param_discord_activity_inner()}"}
- :normal -> {"/", ""}
- _ -> raise ArgumentError
+import Mediasync.Constants
+{form_action_base, form_action_suffix} = case in_discord_activity? do
+ true -> {"/.proxy/", "?#{query_param_discord_activity_inner()}"}
+ false -> {"/", ""}
end
%>
-<!DOCTYPE html>
<html lang="en">
<head>
diff --git a/priv/room.html.eex b/priv/room.html.eex
index 9f2ed0f..012ec0d 100644
--- a/priv/room.html.eex
+++ b/priv/room.html.eex
@@ -1,4 +1,18 @@
<!DOCTYPE html>
+<%
+import Mediasync.Constants
+
+{video_info, websocket_path, state_url, home_button_url} = if in_discord_activity? do
+ {
+ %{video_info | url: "/.proxy/room/#{room_id}/video?#{query_param_discord_activity_inner()}"},
+ "/.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
+%>
<html lang="en">
<head>
@@ -18,7 +32,7 @@
src: url("/static/fontawesome-free-6.6.0-web/webfonts/fa-solid-900.woff2") format("woff2");
}
- .icon-home, .icon-users {
+ .icon-home, .icon-users, .icon-left, .icon-right, .icon-left-right {
font-family: "FontAwesomeSolid";
}
@@ -27,7 +41,19 @@
}
.icon-users::before {
- content: "\f0c0"
+ content: "\f0c0";
+ }
+
+ .icon-left::before {
+ content: "\f30a";
+ }
+
+ .icon-right::before {
+ content: "\f30b";
+ }
+
+ .icon-left-right::before {
+ content: "\f337";
}
#state-button-active::after {
@@ -53,7 +79,7 @@
<script src="/static/video.js/video.min.js"></script>
<script>
const WEBSOCKET_URL = location.origin.replace(/^http/, "ws") + "<%= websocket_path %>";
- const HOME_URL = <%= if home_url, do: ~s("#{home_url}"), else: "null" %>;
+ const HOME_BUTTON_URL = <%= if home_button_url, do: ~s("#{home_button_url}"), else: "null" %>;
const STATE_ELEMENT_INITIAL_TEXT = "loading...";
const STATE_URL = "<%= state_url %>";
</script>
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");