API Reference
The public API of NetCrafterLiveConnection and NetCrafterLiveBroadcast — the two runtime MonoBehaviours behind Live voice & video. Both live in Scripts/, namespace PivecLabs.NetCrafterRelay.Live. Neither is generated — attach them to a GameObject directly, like any other component.
Both read TURN/rendezvous connection details from a NetCrafter Relay RelaySettings asset — normally your game's Definition's (see the Manual's Relay Settings section) via their connectionSettings field, and neither builds any UI of its own — everything below is events/properties/methods for your own scripts to wire up.
01NetCrafterLiveVideoSource (enum)#
Shared by both components' videoSource field.
| Value | Meaning |
Webcam | Captures from the local webcam (default). |
RenderTexture | Streams from customRenderTexture instead — point this at your own camera's render target. |
None | Audio-only — no video track is sent at all. |
02NetCrafterLiveVideoDisplayMode (enum)#
Shared by both components' videoDisplayMode field. Purely a piece of configuration for whatever UI you build on top of the component — neither component ever creates, touches, or hides any display object itself. LocalVideoTextureAvailable/RemoteVideoTextureAvailable hand you a plain Texture either way; this enum only exists so your own UI (or the shipped demo scenes) has a single source of truth for which display style is currently selected, with a proper change notification via VideoDisplayModeChanged.
| Value | Meaning |
ScreenSpace2D | Default. The conventional choice — display the texture on a screen-space RawImage or similar. |
WorldSpace3D | Display the texture on a world-space object instead (a 3D quad/panel, VR/AR use cases, etc.). |
See the demo scenes (Examples/OneToOneCallDemo/, Examples/HostBroadcastDemo/) for a complete reference implementation of both — a screen-space RawImage pair and a draggable world-space video panel pair, switched via one Toggle, both driven by the exact same texture events.
03NetCrafterLiveConnection#
Fields
| Field | Type | Default | Notes |
connectionSettings | RelaySettings | required | Assign via the Inspector's Use Definition + Assign Relay Settings, or drag a RelaySettings asset in yourself. |
forceRelay | bool | false | Forces all ICE traffic through the TURN relay — no direct/STUN candidates. |
videoSource | NetCrafterLiveVideoSource | Webcam | |
customRenderTexture | RenderTexture | null | Used when videoSource is RenderTexture. |
captureAudio | bool | true | Set false for a video-only call. |
remoteAudioOutput | AudioSource | null | Optional. Auto-created if unassigned; assign your own for spatial audio / mixer-group routing. |
videoDisplayMode | NetCrafterLiveVideoDisplayMode | ScreenSpace2D | Which display style your own UI should show. Editing this field directly in the Inspector raises VideoDisplayModeChanged (via OnValidate), same as calling SetVideoDisplayMode() at runtime. Prefer SetVideoDisplayMode() from script so the change notification is consistent either way. |
Properties
| Property | Type | Notes |
CurrentState | RTCPeerConnectionState | Mirrors the last value from ConnectionStateChanged. |
CurrentJoinCode | string | Set once Host()/Join() has a code, null otherwise. |
IsActive | bool | True while a peer connection exists. |
Events
| Event | Signature | Fires when |
ConnectionStateChanged | Action<RTCPeerConnectionState> | The peer connection's state changes. |
RemoteVideoTextureAvailable | Action<Texture> | The remote peer's video frame is ready — wire to a RawImage.texture or similar. |
LocalVideoTextureAvailable | Action<Texture> | Your own outgoing video frame is ready — wire to a self-preview RawImage. Not raised if videoSource is None. |
JoinCodeReady | Action<string> | After Host() mints a join code. |
VideoDisplayModeChanged | Action<NetCrafterLiveVideoDisplayMode> | videoDisplayMode actually changes — either from SetVideoDisplayMode() at runtime, or from editing the field directly in the Inspector. Does not fire if set to its current value. Use this to drive your own UI (e.g. toggling a screen-space vs. world-space preview object, keeping a Toggle's visual state in sync when the change came from elsewhere). |
ErrorOccurred | Action<string> | Any operation fails. Also Console-logged, [NetCrafterLiveConnection] prefix. |
Methods
| Method | Notes |
Host() | Mints a join code, sets up the peer connection, posts an offer. Tears down any previous connection first. |
Host(string gameJoinCode) | 2.0+. Same as Host(), but uses the given Relay game join code instead of a new random one, so players who joined the game can join the call with it. The server only accepts the code of an active game session. NetCrafterLiveRelayLink calls this for you. |
Join(string joinCode) | Resolves the code, sets up the peer connection, waits for the host's offer. Tears down any previous connection first. |
Leave() | Closes the connection, stops polling, releases the webcam/mic. Safe to call even if nothing is active. |
SetVideoDisplayMode(NetCrafterLiveVideoDisplayMode mode) | Sets videoDisplayMode and fires VideoDisplayModeChanged if it actually changed. The preferred way to switch display mode from script. |
04NetCrafterLiveBroadcast#
One host streaming video/voice to any number of receive-only viewers over a single shared join code. A single component instance can be either the host or a viewer — which one depends on which method you call, not a compile-time or Inspector choice. Signaling via /broadcast/*.
Fields
| Field | Type | Default | Notes |
connectionSettings | RelaySettings | required | Same as NetCrafterLiveConnection. |
forceRelay | bool | false | Same as NetCrafterLiveConnection. |
videoSource | NetCrafterLiveVideoSource | Webcam | Host only — viewers never capture anything. |
customRenderTexture | RenderTexture | null | Host only. |
captureAudio | bool | true | Host only. |
remoteAudioOutput | AudioSource | null | Viewer only — auto-created if unassigned. |
videoDisplayMode | NetCrafterLiveVideoDisplayMode | ScreenSpace2D | Same as NetCrafterLiveConnection — applies to whichever side (host or viewer) this instance is currently acting as. |
allowHosting | bool | true | Set false to build a receive-only app (e.g. a spectator/audience build) that can never become a broadcast source. Gates StartBroadcast() only — JoinBroadcast() and every viewer-side capability are unaffected. Enforced inside StartBroadcast() itself, not just a UI-hiding convenience. |
Properties
| Property | Type | Notes |
IsHosting | bool | True between StartBroadcast() and StopBroadcast()/teardown. |
IsViewing | bool | True between JoinBroadcast() and LeaveBroadcast()/teardown. |
CurrentBroadcastCode | string | The active broadcast's join code, host or viewer side. |
ConnectedViewerIds | IReadOnlyCollection<string> | Host only — every currently-connected viewer's id. |
Events
| Event | Signature | Side | Fires when |
BroadcastCodeReady | Action<string> | Host | StartBroadcast() mints a code. |
ViewerJoined | Action<string> | Host | A viewer's peer connection is created (viewer id). |
ViewerLeft | Action<string> | Host | A viewer is removed — terminal ICE failure, RemoveViewer(), or StopBroadcast(). |
ViewerStateChanged | Action<string, RTCPeerConnectionState> | Host | A specific viewer's connection state changes. |
ConnectionStateChanged | Action<RTCPeerConnectionState> | Viewer | This viewer's connection state changes. |
RemoteVideoTextureAvailable | Action<Texture> | Viewer | The host's video frame is ready. |
LocalVideoTextureAvailable | Action<Texture> | Host | The host's own outgoing video frame is ready — wire to a "what viewers see" self-preview. |
VideoDisplayModeChanged | Action<NetCrafterLiveVideoDisplayMode> | Both | Same pattern as NetCrafterLiveConnection — videoDisplayMode actually changed, whether via SetVideoDisplayMode() or an Inspector edit. |
ErrorOccurred | Action<string> | Both | Also Console-logged, [NetCrafterLiveBroadcast] prefix. Also where the allowHosting guard surfaces. |
Methods
| Method | Side | Notes |
StartBroadcast() | Host | Captures local media once, mints a broadcast code, starts accepting viewers. If allowHosting is false, does nothing except raise ErrorOccurred — this check runs even if something bypasses the UI (a stray hotkey, a modified script), not just when the button is hidden. |
StartBroadcast(string gameJoinCode) | Host | 2.0+. Same as StartBroadcast(), but broadcasts under the given Relay game join code (active game sessions only). NetCrafterLiveRelayLink calls this for you. |
JoinBroadcast(string code) | Viewer | Resolves the code, creates a receive-only peer connection to the host. Unaffected by allowHosting. |
StopBroadcast() | Host | Tears down every viewer connection and releases local media. |
LeaveBroadcast() | Viewer | Tears down this viewer's connection. |
RemoveViewer(string viewerId) | Host | Removes one specific viewer without disturbing any other. |
SetVideoDisplayMode(NetCrafterLiveVideoDisplayMode mode) | Both | Same as NetCrafterLiveConnection — sets videoDisplayMode and fires VideoDisplayModeChanged if it actually changed. |
Why viewers are receive-only
Real product shape: one broadcaster's video/game feed and voice (if captureAudio is on) go out to every viewer; nothing ever comes back from a viewer to the host over this component. Viewers use recvonly WebRTC transceivers on their own peer connection — if a viewer's connection ever receives a track from the host's side (it never legitimately should), that's logged as an explicit anomaly, not silently ignored. If your game's voice needs differ from this shape (e.g. many-to-many voice among viewers), that's a separate system — not something this component is built to do.
Building a viewer-only (spectator) build
Set allowHosting = false (Inspector, or before any script calls StartBroadcast()) to ship a build that can only ever JoinBroadcast(). See the Player Hosting Guide's "Viewer-only builds" section for the full walkthrough, including the UI-hiding convention used by the shipped demo.
| Member | On | Description |
string microphoneDevice | Connection, Broadcast | Microphone to use; empty = system default. The Console lists available devices when a call starts. |
bool microphoneAutoGain / float microphoneGain | Connection, Broadcast | Automatic level control for quiet microphones (on, up to 6x by default); off = fixed gain. |
int maxVideoBitrateKbps / int maxVideoFramerate | Broadcast | Per-viewer video caps (0 = none). Host upload ~ cap x viewers. |
SetOutgoingAudioSource(AudioSource) | Broadcast | Send any AudioSource (e.g. a video's soundtrack) instead of the microphone; null = microphone. Switched live on all viewers. |
Host(string gameJoinCode) / StartBroadcast(string gameJoinCode) | Connection / Broadcast | Use the Relay game's join code (see NetCrafterLiveRelayLink). |
06NetCrafterLiveRelayLink#
New in 2.0. Drop-in voice/video for any NetCrafter Relay game, with one join code for both. Add it next to a NetCrafterLiveConnection and/or NetCrafterLiveBroadcast. It subscribes to Relay's NetCrafterEventDispatcher, so it needs no reference to your Definition's generated code:
RelayHosting (payload: join code) → Host(code) / StartBroadcast(code)
RelayJoined (payload: RelayJoinInfo, 2.0+) → Join(code) / JoinBroadcast(code)
ConnectionLost → hang up
Fields
| Field | Type | Default | Description |
call | NetCrafterLiveConnection | — | 1-to-1 call to drive. Optional. |
broadcast | NetCrafterLiveBroadcast | — | Broadcast to drive. Optional. |
autoStart | bool | true | Start/join automatically when the game is hosted/joined. Off = call StartLive() yourself (e.g. from a "Camera on" button). |
callPartnerUserId | int | 1 | The call is 1-to-1: only the joiner with this Relay player id joins the host's call. Relay gives the first joiner id 1. |
hostBroadcasts | bool | true | Whether the Relay host starts the broadcast. Off = this link only watches. |
joinRetryDelay / joinRetries | float / int | 1.5 / 3 | Joiner-side retry if the host's side isn't up yet. |
Properties, events and methods
| Member | Description |
string GameJoinCode | The game join code in use, or null when not in a game. |
bool IsGameHost | True on the Relay host. |
int LocalUserId | This player's Relay id (host = 0, -1 when not in a game). |
bool IsLive | True while this link has started or joined the call/broadcast. |
event Action<string> StatusChanged | Human-readable status, handy for a UI label. |
StartLive() / StopLive() | Start/join or hang up manually (requires being in a game). |
Requires the 2.0 rendezvous service: it only lets a call/broadcast use a game's join code while that game session is active. A 1.x server has no Live signalling at all, so starting a call fails with a "not found" error — re-run the Server Setup Wizard and choose Update / redeploy.