API Reference
The public API of NetCrafterLiveConnection and NetCrafterLiveBroadcast — the two runtime MonoBehaviours NetCrafter Live ships. Both live in Scripts/, namespace PivecLabs.NetCrafterLive. Neither is generated — attach them to a GameObject directly, like any other component.
Both read TURN/rendezvous connection details from the same project-wide RelaySettings asset (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.
NetCrafterLiveVideoSource (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. |
NetCrafterLiveVideoDisplayMode (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.
NetCrafterLiveConnection#
Fields
| Field | Type | Default | Notes |
|---|---|---|---|
connectionSettings | RelaySettings | required | Assign via the Inspector's "Assign Project's Relay Settings" button, or drag it 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. |
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. |
NetCrafterLiveBroadcast#
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. |
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.