Using UI Kit Broadcast
The example below shows how to use the Livepeer UI KitBroadcast component to broadcast from the web.
Broadcast
This guide assumes you have configured a Livepeer JS SDK client with an API key. We can use theBroadcast primitives with a
stream key, from a stream we created.
We show some simple styling below with Tailwind CSS, but this can use any
styling library, since the primitives ship as unstyled, composable components.
Broadcast.tsx
Embeddable broadcast
This is one of the easiest ways to broadcast video from your website/applications. You can embed the iframe on your website/applications by using the below code snippet. You can replace theSTREAM_KEY with your stream key for the stream.
Adding custom broadcasting
If you want to add custom broadcasting to your app and handle the WebRTC SDP negotiation without using the Livepeer React primitives, you can follow the steps below.Get the SDP Host
First, you will need to make a request to get the proper ingest URL for the region which your end user is in. We have a global presence, and we handle redirects based on GeoDNS to allow users to get the lowest latency server. To do this make aHEAD request to the WebRTC redirect endpoint:
https://lax-prod-catalyst-2.lp-playback.studio/webrtc/{STREAM_KEY}. We will
use this in the next step.
Broadcast
Now that we have the endpoint for the ICE servers, we can start SDP negotiation following the WHIP spec and kick off a livestream. The outline of the steps are:- Create a new
RTCPeerConnectionwith the ICE servers from the redirect URL. - Construct an SDP offer using the library of your choice.
- Wait for ICE gathering.
- Send the SDP offer to the server and get the response.
- Use the response to set the remote description on the
RTCPeerConnection. - Get a local media stream and add the track to the peer connection, and set
the video element
srcto thesrcObject.
The final HTTP DELETE is not needed for our media server, since we detect the
end of broadcast by the lack of incoming packets from the gateway.
WHIP Outline