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

Member
Signature
Description

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

Event type
Namespace
Key fields

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

VisionFrameCaptured does not carry frame pixel data. It is a lightweight accounting event used for telemetry and monitoring. Actual frame data flows directly through the video pipeline.

VisionCaptureStopReason Values

Value
Meaning

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

Value
Meaning

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:

Aspect
Native
WebGL

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


Platform Compatibility Matrix

Feature
PC / Mac
Android / iOS
WebGL
Meta Quest

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


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?