-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update live stream card in real-time
- Loading branch information
Showing
5 changed files
with
48 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule AsciinemaWeb.LiveStreamCardLive do | ||
use AsciinemaWeb, :live_view | ||
alias Asciinema.Streaming | ||
alias Asciinema.Streaming.LiveStreamServer | ||
|
||
@impl true | ||
def render(assigns) do | ||
~H""" | ||
<AsciinemaWeb.LiveStreamHTML.card stream={@stream} /> | ||
""" | ||
end | ||
|
||
@impl true | ||
def mount(_params, %{"stream_id" => stream_id}, socket) do | ||
socket = assign(socket, :stream, Streaming.get_live_stream(stream_id)) | ||
|
||
if connected?(socket) do | ||
LiveStreamServer.subscribe(stream_id, :metadata) | ||
end | ||
|
||
{:ok, socket} | ||
end | ||
|
||
@impl true | ||
def handle_info(%LiveStreamServer.Update{event: :metadata} = update, socket) do | ||
{:noreply, assign(socket, stream: update.data)} | ||
end | ||
end |