by Pivec Labs
API ReferencePublic component API

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.

01

NetCrafterLiveVideoSource (enum)#

Shared by both components' videoSource field.

ValueMeaning
WebcamCaptures from the local webcam (default).
RenderTextureStreams from customRenderTexture instead — point this at your own camera's render target.
NoneAudio-only — no video track is sent at all.
02

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.

ValueMeaning
ScreenSpace2DDefault. The conventional choice — display the texture on a screen-space RawImage or similar.
WorldSpace3DDisplay 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.

03

NetCrafterLiveConnection#

NetCrafterLiveConnection
1-to-1 video/voice call. Signaling via /signal/*.
Runtime — not generated

Fields

FieldTypeDefaultNotes
connectionSettingsRelaySettingsrequiredAssign via the Inspector's "Assign Project's Relay Settings" button, or drag it in yourself.
forceRelayboolfalseForces all ICE traffic through the TURN relay — no direct/STUN candidates.
videoSourceNetCrafterLiveVideoSourceWebcam
customRenderTextureRenderTexturenullUsed when videoSource is RenderTexture.
captureAudiobooltrueSet false for a video-only call.
remoteAudioOutputAudioSourcenullOptional. Auto-created if unassigned; assign your own for spatial audio / mixer-group routing.
videoDisplayModeNetCrafterLiveVideoDisplayModeScreenSpace2DWhich 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

PropertyTypeNotes
CurrentStateRTCPeerConnectionStateMirrors the last value from ConnectionStateChanged.
CurrentJoinCodestringSet once Host()/Join() has a code, null otherwise.
IsActiveboolTrue while a peer connection exists.

Events

EventSignatureFires when
ConnectionStateChangedAction<RTCPeerConnectionState>The peer connection's state changes.
RemoteVideoTextureAvailableAction<Texture>The remote peer's video frame is ready — wire to a RawImage.texture or similar.
LocalVideoTextureAvailableAction<Texture>Your own outgoing video frame is ready — wire to a self-preview RawImage. Not raised if videoSource is None.
JoinCodeReadyAction<string>After Host() mints a join code.
VideoDisplayModeChangedAction<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).
ErrorOccurredAction<string>Any operation fails. Also Console-logged, [NetCrafterLiveConnection] prefix.

Methods

MethodNotes
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.
04

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/*.

NetCrafterLiveBroadcast
Host-broadcast, both roles in one class.
Runtime — not generated

Fields

FieldTypeDefaultNotes
connectionSettingsRelaySettingsrequiredSame as NetCrafterLiveConnection.
forceRelayboolfalseSame as NetCrafterLiveConnection.
videoSourceNetCrafterLiveVideoSourceWebcamHost only — viewers never capture anything.
customRenderTextureRenderTexturenullHost only.
captureAudiobooltrueHost only.
remoteAudioOutputAudioSourcenullViewer only — auto-created if unassigned.
videoDisplayModeNetCrafterLiveVideoDisplayModeScreenSpace2DSame as NetCrafterLiveConnection — applies to whichever side (host or viewer) this instance is currently acting as.
allowHostingbooltrueSet 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

PropertyTypeNotes
IsHostingboolTrue between StartBroadcast() and StopBroadcast()/teardown.
IsViewingboolTrue between JoinBroadcast() and LeaveBroadcast()/teardown.
CurrentBroadcastCodestringThe active broadcast's join code, host or viewer side.
ConnectedViewerIdsIReadOnlyCollection<string>Host only — every currently-connected viewer's id.

Events

EventSignatureSideFires when
BroadcastCodeReadyAction<string>HostStartBroadcast() mints a code.
ViewerJoinedAction<string>HostA viewer's peer connection is created (viewer id).
ViewerLeftAction<string>HostA viewer is removed — terminal ICE failure, RemoveViewer(), or StopBroadcast().
ViewerStateChangedAction<string, RTCPeerConnectionState>HostA specific viewer's connection state changes.
ConnectionStateChangedAction<RTCPeerConnectionState>ViewerThis viewer's connection state changes.
RemoteVideoTextureAvailableAction<Texture>ViewerThe host's video frame is ready.
LocalVideoTextureAvailableAction<Texture>HostThe host's own outgoing video frame is ready — wire to a "what viewers see" self-preview.
VideoDisplayModeChangedAction<NetCrafterLiveVideoDisplayMode>BothSame pattern as NetCrafterLiveConnection — videoDisplayMode actually changed, whether via SetVideoDisplayMode() or an Inspector edit.
ErrorOccurredAction<string>BothAlso Console-logged, [NetCrafterLiveBroadcast] prefix. Also where the allowHosting guard surfaces.

Methods

MethodSideNotes
StartBroadcast()HostCaptures 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)ViewerResolves the code, creates a receive-only peer connection to the host. Unaffected by allowHosting.
StopBroadcast()HostTears down every viewer connection and releases local media.
LeaveBroadcast()ViewerTears down this viewer's connection.
RemoveViewer(string viewerId)HostRemoves one specific viewer without disturbing any other.
SetVideoDisplayMode(NetCrafterLiveVideoDisplayMode mode)BothSame 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.