Advanced Topics
Scripting API reference, custom frame source implementation, domain events, WebGL platform behaviour, and cross-platform compatibility.
Advanced Vision Configuration and Custom Integration
This page covers the full scripting API of ConvaiVisionPublisher, the contract for implementing a custom frame source, the domain events emitted throughout the Vision lifecycle, platform-specific behaviour, and a cross-platform compatibility matrix. It is intended for developers who need programmatic control beyond what the Inspector provides.
ConvaiVisionPublisher Scripting API
IsPublishing
bool IsPublishing { get; }
true when a video track is actively published to the room.
FrameSource
IVisionFrameSource FrameSource { get; }
The currently active frame source. null on WebGL.
PublishPolicy
VisionPublishPolicy PublishPolicy { get; }
The current publish policy.
VideoTrackName
string VideoTrackName { get; }
The WebRTC video track name in use.
SetPublishPolicy
void SetPublishPolicy(VisionPublishPolicy policy)
Changes the publish policy. If publishing is active, the track is restarted with the new profile immediately.
EnablePublishing
void EnablePublishing(bool enabled)
Starts or stops publishing without changing the policy. Required when policy is Manual; available on all policies.
Example: conditional policy selection
using Convai.Modules.Vision;
using Convai.Runtime.Vision.Publishing;
ConvaiVisionPublisher publisher = GetComponent<ConvaiVisionPublisher>();
bool isHighBandwidthNetwork = /* your network quality check */;
VisionPublishPolicy chosen = isHighBandwidthNetwork
? VisionPublishPolicy.HighResponsiveness
: VisionPublishPolicy.LowOverhead;
publisher.SetPublishPolicy(chosen);Implementing a Custom Frame Source
If none of the built-in sources fits your use case — for example, you want to publish a render texture produced by a custom post-processing pipeline, or stream from a third-party SDK — implement IVisionFrameSource.
Interface Contract
Y-Flip Requirement
CurrentRenderTexture must be oriented top-down (Y-flipped relative to Unity's default bottom-up convention). Failing to flip the texture produces an upside-down video stream on the backend. Use Graphics.Blit with a flipped scale vector:
Minimal Custom Implementation
Optional: IVisionFrameSourceStatusProvider
To expose detailed state information (used by VisionDebugPreview and the coordinator's health checks), also implement IVisionFrameSourceStatusProvider:
Assign your custom component to ConvaiVisionPublisher's Frame Source Component field. The publisher accepts any MonoBehaviour that implements IVisionFrameSource.
Domain Events
Vision publishes all significant state changes through the SDK's IEventHub. Subscribe to these events from any component that holds an IEventHub reference, or through the ConvaiManager's event infrastructure.
Event Reference
VisionCaptureStarted
Convai.Domain.DomainEvents.Vision
Width, Height, FramesPerSecond, SourceId, Timestamp, AspectRatio, TotalPixels
VisionFrameCaptured
Convai.Domain.DomainEvents.Vision
Width, Height, FrameIndex, SizeBytes, SourceId, Timestamp
VisionCaptureStopped
Convai.Domain.DomainEvents.Vision
TotalFramesCaptured, Reason, SourceId, ErrorMessage, ErrorCode, IsError, IsNormalStop
VideoTrackPublished
Convai.Domain.DomainEvents.Vision
TrackSid, TrackName, RoomSessionId, Timestamp, IsVisionTrack
VideoTrackUnpublished
Convai.Domain.DomainEvents.Vision
TrackSid, TrackName, Reason, Timestamp, IsNormalUnpublish
VisionCaptureStopReason Values
UserRequested (0)
StopCapture() was called explicitly
SessionEnded (1)
The Convai room session ended
CameraLost (2)
The camera was disconnected or became unavailable
Error (3)
An internal error occurred (see ErrorMessage and ErrorCode)
ComponentDisabled (4)
The frame source component was disabled
VideoTrackUnpublishReason Values
UserRequested (0)
EnablePublishing(false) or policy change
SessionEnded (1)
Room session ended
SourceLost (2)
The frame source was removed or stopped unexpectedly
Error (3)
Track unpublished due to a transport error
ComponentDisabled (4)
The publisher component was disabled
Accessing Vision State from a MonoBehaviour
IEventHub is part of the SDK's internal module dependency injection system. It is not directly accessible from regular MonoBehaviour scripts — it is provided to classes that implement IConvaiModule through the module lifecycle.
For user scripts, the recommended approach is to monitor state directly via the publisher and frame source:
Domain Event Subscription (SDK Module Context)
If you are building a class that implements IConvaiModule and receives IEventHub through the module lifecycle, domain event subscription follows this pattern:
WebGL Platform Deep Dive
On WebGL builds the Vision pipeline bypasses the IVisionFrameSource contract entirely. Instead, ConvaiVisionPublisher captures the visible Unity WebGL canvas using the browser's canvas.captureStream() API and publishes the resulting MediaStream directly.
Key differences from the native path:
Frame source component
Required
Not used
Capture resolution
Set by CapturePreset
Matches the browser canvas size
Max frame rate
Up to 30 fps
Capped at 15 fps
VisionDebugPreview
Shows capture
Shows blank (no RenderTexture)
IsPublishing
true when track is live
true when track is live
Publish policy
All values supported
Frame rate clamped to 15 fps
WebGL browser policy requires a user gesture (click, key press) before audio playback is permitted, even when video is already publishing. If your session uses both Vision and voice, ensure the user has interacted with the page before the room connects.
Platform Compatibility Matrix
CameraVisionFrameSource
✅
✅
❌ (no frame source needed)
✅
WebcamVisionFrameSource
✅
✅ (permission flow)
❌
❌
QuestVisionFrameSource
❌
❌
❌
✅ (Meta XR SDK required)
WebGL canvas capture
❌
❌
✅ (automatic)
❌
VisionDebugPreview
✅ (Editor only)
✅ (Editor only)
⚠️ blank
✅ (Editor only)
Max publish FPS
30
30
15
30
HighResponsiveness policy
✅
✅
✅ (FPS clamped)
✅
Common Pitfalls
Multiple frame sources in the same hierarchy. If more than one IVisionFrameSource component exists in the scene, always assign the correct one to ConvaiVisionPublisher's Frame Source Component field. The auto-discovery picks the first source it finds, which may not be the one you intend.
VisionPublishPolicy is client-side only. The policy controls the transport (FPS and bitrate). It does not control which AI model or vision provider the Convai backend uses, and it does not guarantee a particular response latency from the character.
SRP/URP + CameraCaptureMode. On SRP/URP projects, Auto correctly selects the explicit render path. Manually setting CameraCaptureMode to BuiltInHooks on an SRP project produces a black feed because the render callbacks are not triggered by SRP cameras.
Conclusion
This page covers the full depth of Vision's programmable surface — the publisher API, the custom frame source contract, domain events, the WebGL pipeline, and the platform matrix. For a fast return to the Inspector-based basics, revisit the Quick Start. For diagnosing problems in any of the areas above, see Troubleshooting.
Last updated
Was this helpful?