1
0
mirror of https://github.com/algora-io/tv.git synced 2024-11-26 01:00:20 +02:00

add icons for rtmp destinations

This commit is contained in:
zafer 2024-05-20 17:43:23 +03:00
parent 4833992e41
commit aa4d1f6de9
2 changed files with 94 additions and 1 deletions

View File

@ -0,0 +1,89 @@
defmodule AlgoraWeb.RTMPDestinationIconComponent do
use Phoenix.Component
attr :url, :string
attr :class, :string, default: nil
def render(assigns) do
~H"""
<%= case get_icon(@url) do %>
<% :twitch -> %>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class={["text-purple-400", @class]}
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" /><path d="M4 5v11a1 1 0 0 0 1 1h2v4l4 -4h5.584c.266 0 .52 -.105 .707 -.293l2.415 -2.414c.187 -.188 .293 -.442 .293 -.708v-8.585a1 1 0 0 0 -1 -1h-14a1 1 0 0 0 -1 1z" /><path d="M16 8l0 4" /><path d="M12 8l0 4" />
</svg>
<% :youtube -> %>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class={["text-red-400", @class]}
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" /><path d="M2 8a4 4 0 0 1 4 -4h12a4 4 0 0 1 4 4v8a4 4 0 0 1 -4 4h-12a4 4 0 0 1 -4 -4v-8z" /><path d="M10 9l5 3l-5 3z" />
</svg>
<% :x -> %>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class={["text-white", @class]}
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" /><path d="M4 4l11.733 16h4.267l-11.733 -16z" /><path d="M4 20l6.768 -6.768m2.46 -2.46l6.772 -6.772" />
</svg>
<% _ -> %>
<svg
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
class={["text-green-400", @class]}
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" /><path d="M18.364 19.364a9 9 0 1 0 -12.728 0" /><path d="M15.536 16.536a5 5 0 1 0 -7.072 0" /><path d="M12 13m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0" />
</svg>
<% end %>
"""
end
defp get_icon(url) do
host = URI.parse(url).host
cond do
String.ends_with?(host, "youtube.com") -> :youtube
String.ends_with?(host, "youtu.be") -> :youtube
String.ends_with?(host, "live-video.net") -> :twitch
String.ends_with?(host, "twitch.tv") -> :twitch
String.ends_with?(host, "twitch.com") -> :twitch
String.ends_with?(host, "pscp.tv") -> :x
String.ends_with?(host, "twitter.com") -> :x
String.ends_with?(host, "x.com") -> :x
true -> :broadcast
end
end
end

View File

@ -3,6 +3,7 @@ defmodule AlgoraWeb.SettingsLive do
alias Algora.Accounts
alias Algora.Accounts.Destination
alias AlgoraWeb.RTMPDestinationIconComponent
def render(assigns) do
~H"""
@ -47,7 +48,10 @@ defmodule AlgoraWeb.SettingsLive do
<ul :if={length(@destinations) > 0} class="space-y-2">
<%= for destination <- @destinations do %>
<li class="w-full gap-4 py-2 px-3 border border-gray-600 bg-gray-950 rounded-md shadow-sm focus:outline-none focus:ring-gray-900 focus:border-gray-900 flex items-center justify-between">
<span class="text-sm truncate"><%= destination.rtmp_url %></span>
<div class="flex items-center gap-2">
<RTMPDestinationIconComponent.render class="w-6 h-6" url={destination.rtmp_url} />
<span class="text-sm truncate"><%= destination.rtmp_url %></span>
</div>
<label class="inline-flex items-center cursor-pointer">
<span class="hidden sm:inline mr-3 text-sm font-medium text-gray-900 dark:text-gray-300">
<%= if destination.active do %>