Skip to content

Add video_class attribute to player #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions lib/live_ex_webrtc/player.ex
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ defmodule LiveExWebRTC.Player do
"""
)

attr(:class, :string, default: nil, doc: "CSS/Tailwind classes for styling HTMLVideoElement")
attr(:class, :string, default: nil, doc: "CSS/Tailwind classes for styling container")

attr(:video_class, :string,
default: nil,
doc: "CSS/Tailwind classes for styling HTMLVideoElement"
)

@doc """
Helper function for rendering Player live view.
Expand All @@ -129,7 +134,8 @@ defmodule LiveExWebRTC.Player do
id: "#{@player.id}-lv",
session: %{
"publisher_id" => @player.publisher_id,
"class" => @class
"class" => @class,
"video_class" => @video_class
}
)}
"""
Expand Down Expand Up @@ -214,7 +220,14 @@ defmodule LiveExWebRTC.Player do
~H"""
<div class={@class}>
<div class="group inline-block relative w-full h-full">
<video id={@player.id} phx-hook="Player" class="w-full h-full" controls autoplay muted>
<video
id={@player.id}
phx-hook="Player"
class={["w-full h-full", @video_class]}
controls
autoplay
muted
>
</video>

<div class={"z-40 absolute top-0 left-0 #{@display_settings} w-full h-full opacity-75 bg-black"}>
Expand Down Expand Up @@ -244,8 +257,12 @@ defmodule LiveExWebRTC.Player do
end

@impl true
def mount(_params, %{"publisher_id" => pub_id, "class" => class}, socket) do
socket = assign(socket, class: class, player: nil)
def mount(
_params,
%{"publisher_id" => pub_id, "class" => class, "video_class" => video_class},
socket
) do
socket = assign(socket, class: class, player: nil, video_class: video_class)

if connected?(socket) do
ref = make_ref()
Expand Down