by Pivec Labs
Broadcast Voice & Video

Broadcast

The finished LiveBroadcastDemo scene: go live with your webcam, or pick a running broadcast to watch.

01

Run it#

  1. Deploy the Chat Definition's server code and restart SmartFoxServer (same as the Group Call demo).
  2. Open Examples/Live/Scenes/LiveBroadcastDemo.unity, run two copies, connect both.
  3. In one, click Start broadcast. In the other, the broadcast appears in the list — click Watch.
02

How it works#

The host gives every viewer its own connection (send-only); the server enforces the viewer cap (live.maxViewers, default 8) and tells everyone in the room who is live:

csharp
broadcast.StartBroadcast();                    // host
broadcast.ActiveBroadcastsChanged += () => { /* rebuild list from broadcast.ActiveBroadcasts */ };
broadcast.Watch(hostId);                       // viewer
broadcast.RemoteVideoAvailable += tex => screen.texture = tex;
03

Broadcasting a game camera or a video#

Set video to RenderTexture and assign customRenderTexture (a camera's target texture, or a VideoPlayer's). Send the video's sound with SetOutgoingAudioSource(videoAudioSource) — it keeps playing locally too. The Character + Broadcast Screen demo does exactly that.

Upload is one stream per viewer: keep maxVideoBitrateKbps well below the host's upload, or the game's own updates suffer.