View Source Membrane.WebRTC.Live.Capture (Membrane WebRTC plugin v0.25.3)
LiveView for capturing audio and video from a browser and sending it via WebRTC to Membrane.WebRTC.Source
.
Note: This module will be available in your code only if you add {:phoenix, "~> 1.7"}
and {:phoenix_live_view, "~> 1.0"}
to the dependencies of of your root project.
It:
- creates WebRTC PeerConnection on the browser side.
- forwards signaling messages between the browser and
Membrane.WebRTC.Source
viaMembrane.WebRTC.Signaling
. - sends audio and video streams to the related
Membrane.WebRTC.Source
.
JavaScript Hook
Capture LiveView requires JavaScript hook to be registered under Capture
name.
The hook can be created using createCaptureHook
function.
For example:
import { createCaptureHook } from "membrane_webrtc_plugin";
let Hooks = {};
const iceServers = [{ urls: "stun:stun.l.google.com:19302" }];
Hooks.Capture = createCaptureHook(iceServers);
let liveSocket = new LiveSocket("/live", Socket, {
// ...
hooks: Hooks
});
Examples
defmodule StreamerWeb.StreamSenderLive do
use StreamerWeb, :live_view
alias Membrane.WebRTC.Live.Capture
@impl true
def render(assigns) do
~H"""
<Capture.live_render socket={@socket} capture_id="capture" />
"""
end
@impl true
def mount(_params, _session, socket) do
signaling = Membrane.WebRTC.Signaling.new()
{:ok, _supervisor, _pipelne} = Membrane.Pipeline.start_link(MyPipeline, signaling: signaling)
socket = socket |> Capture.attach(id: "capture", signaling: signaling)
{:ok, socket}
end
end
Summary
Functions
Attaches required hooks and creates Membrane.WebRTC.Live.Capture
struct.
Helper function for rendering Capture LiveView.
Types
@type t() :: %Membrane.WebRTC.Live.Capture{ audio?: boolean(), id: String.t(), preview?: boolean(), signaling: Membrane.WebRTC.Signaling.t(), video?: boolean() }
Functions
@spec attach(Phoenix.LiveView.Socket.t(), Keyword.t()) :: Phoenix.LiveView.Socket.t()
Attaches required hooks and creates Membrane.WebRTC.Live.Capture
struct.
Created struct is saved in socket's assigns and then it is sent by an attached hook to a child LiveView process.
Options:
id
- capture id. It is used to identify live view and generated HTML video player. It must be unique within single page.signaling
-Membrane.WebRTC.Signaling.t()
, that has been passed toMembrane.WebRTC.Source
as well.video?
- iftrue
, the video stream from the computer camera will be captured. Defaults totrue
.audio?
- iftrue
, the audio stream from the computer microphone will be captured. Defaults totrue
.preview?
- iftrue
, the functionMembrane.WebRTC.Live.Capture.live_render/1
will return a video HTML tag with attached captured video stream. Defaults totrue
.
@spec get_attached(Phoenix.LiveView.Socket.t(), String.t()) :: t()
Helper function for rendering Capture LiveView.
Attributes
socket
(Phoenix.LiveView.Socket
) (required) - Parent live view socket.capture_id
(:string
) (required) - ID of acaputre
previously attached to the socket. It has to be the same as the value passed to:id
fieldMembrane.WebRTC.Live.Capture.attach/2
.class
(:string
) - CSS/Tailwind classes for styling. Defaults to""
.