Skip to main content

Class: VideoStream<T>

Defined in: src/video/VideoStream.ts:101

The base class for handling video streams (from camera or file), managing the underlying

Extends​

Extended by​

Type Parameters​

T​

T extends VideoStreamDetails = VideoStreamDetails

Constructors​

Constructor​

new VideoStream<T>(options): VideoStream<T>

Defined in: src/video/VideoStream.ts:125

Parameters​

options​

VideoStreamOptions = {}

The configuration options.

Returns​

VideoStream<T>

Overrides​

Script.constructor

Properties​

aspectRatio?​

optional aspectRatio: number

Defined in: src/video/VideoStream.ts:107


height?​

optional height: number

Defined in: src/video/VideoStream.ts:106


isXRScript​

isXRScript: boolean = true

Defined in: src/core/Script.ts:99

Inherited from​

Script.isXRScript


loaded​

loaded: boolean = false

Defined in: src/video/VideoStream.ts:104


state​

state: StreamState = StreamState.IDLE

Defined in: src/video/VideoStream.ts:109


stream_​

protected stream_: MediaStream | null = null

Defined in: src/video/VideoStream.ts:111


texture​

texture: Texture

Defined in: src/video/VideoStream.ts:108


video_​

protected video_: HTMLVideoElement

Defined in: src/video/VideoStream.ts:112


width?​

optional width: number

Defined in: src/video/VideoStream.ts:105


xb?​

optional xb: XBObjectOptions

Defined in: src/interaction/InteractionTypes.ts:34

Inherited from​

Script.xb

Accessors​

video​

Get Signature​

get video(): HTMLVideoElement

Defined in: src/video/VideoStream.ts:113

Returns​

HTMLVideoElement

Methods​

dispose()​

dispose(): void

Defined in: src/video/VideoStream.ts:362

Disposes of all resources used by this stream.

Returns​

void

Overrides​

Script.dispose


drawSnapshotSource_()​

protected drawSnapshotSource_(context, width, height): void

Defined in: src/video/VideoStream.ts:251

Draws the current snapshot source into context at the requested size. Subclasses may override this to provide pixels from another source.

Parameters​

context​

CanvasRenderingContext2D

width​

number

height​

number

Returns​

void


getSnapshot()​

Call Signature​

getSnapshot(options): ImageData

Defined in: src/video/VideoStream.ts:264

Captures the current video frame.

Parameters​
options​

VideoStreamGetSnapshotImageDataOptions

The options for the snapshot.

Returns​

ImageData

The captured data.

Call Signature​

getSnapshot(options): Promise<string | null>

Defined in: src/video/VideoStream.ts:265

Captures the current video frame.

Parameters​
options​

VideoStreamGetSnapshotBase64Options

The options for the snapshot.

Returns​

Promise<string | null>

The captured data.

Call Signature​

getSnapshot(options): Texture

Defined in: src/video/VideoStream.ts:268

Captures the current video frame.

Parameters​
options​

VideoStreamGetSnapshotTextureOptions

The options for the snapshot.

Returns​

Texture

The captured data.

Call Signature​

getSnapshot(options): Promise<Blob | null>

Defined in: src/video/VideoStream.ts:269

Captures the current video frame.

Parameters​
options​

VideoStreamGetSnapshotBlobOptions

The options for the snapshot.

Returns​

Promise<Blob | null>

The captured data.


handleVideoStreamLoadedMetadata()​

protected handleVideoStreamLoadedMetadata(resolve, reject, allowRetry): void

Defined in: src/video/VideoStream.ts:174

Processes video metadata, sets dimensions, and resolves a promise.

Parameters​

resolve​

() => void

The resolve function of the wrapping Promise.

reject​

(_) => void

The reject function of the wrapping Promise.

allowRetry​

boolean = false

Whether to allow a retry attempt on failure.

Returns​

void


init()​

init(_?): void | Promise<void>

Defined in: src/core/Script.ts:108

Initializes an instance with XR controllers, grips, hands, and default options. We allow all scripts to quickly access its user (e.g., user.isSelecting(), user.hands), world (e.g., physical depth mesh, lighting estimation, and recognized objects), and scene (the root of three.js's scene graph). If this returns a promise, we will wait for it.

Parameters​

_?​

object

Returns​

void | Promise<void>

Inherited from​

Script.init


initPhysics()​

initPhysics(_physics): void | Promise<void>

Defined in: src/core/Script.ts:118

Enables depth-aware interactions with physics. See /samples/advanced/ballpit

Parameters​

_physics​

Physics

Returns​

void | Promise<void>

Inherited from​

Script.initPhysics


onHoverEnter()​

onHoverEnter(_event): void

Defined in: src/core/Script.ts:215

Called when a source starts hovering over this object.

Parameters​

_event​

HoverEvent

The hover source, target, surface, and intersection. Call event.stopPropagation() to stop bubbling to ancestor Scripts.

Returns​

void

Inherited from​

Script.onHoverEnter


onHoverExit()​

onHoverExit(_event): void

Defined in: src/core/Script.ts:221

Called when a source stops hovering over this object.

Parameters​

_event​

HoverEvent

The hover source, target, surface, and intersection. Call event.stopPropagation() to stop bubbling to ancestor Scripts.

Returns​

void

Inherited from​

Script.onHoverExit


onHovering()​

onHovering(_event): void

Defined in: src/core/Script.ts:227

Called while a source hovers over this object.

Parameters​

_event​

HoverEvent

The hover source, target, surface, and intersection. Call event.stopPropagation() to stop bubbling to ancestor Scripts.

Returns​

void

Inherited from​

Script.onHovering


onKeyDown()​

onKeyDown(_event): void

Defined in: src/core/Script.ts:158

Called on keyboard keypress.

Parameters​

_event​

KeyEvent

Event containing .code to read the keyboard key.

Returns​

void

Inherited from​

Script.onKeyDown


onKeyUp()​

onKeyUp(_event): void

Defined in: src/core/Script.ts:159

Parameters​

_event​

KeyEvent

Returns​

void

Inherited from​

Script.onKeyUp


onLongSelect()​

onLongSelect(_event): void

Defined in: src/core/Script.ts:152

Called when an object selection reaches the long-select delay.

Parameters​

_event​

LongSelectEvent

Returns​

void

Inherited from​

Script.onLongSelect


onObjectGrabbing()​

onObjectGrabbing(_event): void

Defined in: src/core/Script.ts:253

Called every frame a hand is grabbing this object.

Parameters​

_event​

ObjectGrabEvent

Returns​

void

Inherited from​

Script.onObjectGrabbing


onObjectGrabEnd()​

onObjectGrabEnd(_event): void

Defined in: src/core/Script.ts:258

Called when a hand stops grabbing this object. This ends built-in direct-touch manipulation without ending contact.

Parameters​

_event​

ObjectGrabEvent

Returns​

void

Inherited from​

Script.onObjectGrabEnd


onObjectGrabStart()​

onObjectGrabStart(_event): void

Defined in: src/core/Script.ts:249

Called when a hand starts grabbing this object (touching + pinching). A grab starts built-in direct-touch manipulation when enabled.

Parameters​

_event​

ObjectGrabEvent

Returns​

void

Inherited from​

Script.onObjectGrabStart


onObjectLongSelect()​

onObjectLongSelect(_event): void

Defined in: src/core/Script.ts:203

Called once when a captured selection is held for the long-select delay. Manipulation captures do not emit this callback.

Parameters​

_event​

LongSelectEvent

The controller and completed hold duration. Call event.stopPropagation() to stop bubbling to ancestor Scripts.

Returns​

void

Inherited from​

Script.onObjectLongSelect


onObjectManipulate()​

onObjectManipulate(_event): void

Defined in: src/core/Script.ts:209

Called for each phase of an automatic object manipulation. Call event.stopPropagation() to stop bubbling. Calling preventDefault() on a start event suppresses the automatic action.

Parameters​

_event​

ManipulationEvent

Returns​

void

Inherited from​

Script.onObjectManipulate


onObjectSelectEnd()​

onObjectSelectEnd(_event): void

Defined in: src/core/Script.ts:196

Called when a source stops selecting the object this Script represents.

Parameters​

_event​

SelectEndEvent

The completed state and end reason. Call event.stopPropagation() to stop bubbling to ancestor Scripts.

Returns​

void

Inherited from​

Script.onObjectSelectEnd


onObjectSelectStart()​

onObjectSelectStart(_event): void

Defined in: src/core/Script.ts:190

Called when a source starts selecting the object this Script represents.

Parameters​

_event​

SelectEvent

event.target is the logical object and event.source.controller identifies the controller. Call event.stopPropagation() to stop bubbling to ancestor Scripts.

Returns​

void

Inherited from​

Script.onObjectSelectStart


onObjectTouchEnd()​

onObjectTouchEnd(_event): void

Defined in: src/core/Script.ts:244

Called when a hand's index finger stops touching this object. This ends the default selection lifecycle after the touch callback.

Parameters​

_event​

ObjectTouchEvent

Returns​

void

Inherited from​

Script.onObjectTouchEnd


onObjectTouching()​

onObjectTouching(_event): void

Defined in: src/core/Script.ts:239

Called every frame that a hand's index finger is touching this object. The object remains selected during these frames unless touch selection was prevented when contact started.

Parameters​

_event​

ObjectTouchEvent

Returns​

void

Inherited from​

Script.onObjectTouching


onObjectTouchStart()​

onObjectTouchStart(_event): void

Defined in: src/core/Script.ts:233

Called when a hand's index finger starts touching this object. Direct touch starts the object's selection lifecycle by default. Call event.preventDefault() to handle contact without selecting.

Parameters​

_event​

ObjectTouchStartEvent

Returns​

void

Inherited from​

Script.onObjectTouchStart


onSelect()​

onSelect(_event): void

Defined in: src/core/Script.ts:144

Called whenever pinch / mouse click successfully completes, globally.

Parameters​

_event​

SelectEvent

The interaction source and completed target.

Returns​

void

Inherited from​

Script.onSelect


onSelectEnd()​

onSelectEnd(_event): void

Defined in: src/core/Script.ts:138

Called whenever pinch / mouse click discontinues, globally.

Parameters​

_event​

SelectEndEvent

The completed state and end reason.

Returns​

void

Inherited from​

Script.onSelectEnd


onSelecting()​

onSelecting(_event): void

Defined in: src/core/Script.ts:149

Called whenever pinch / mouse click is happening, globally.

Parameters​

_event​

SelectEvent

Returns​

void

Inherited from​

Script.onSelecting


onSelectStart()​

onSelectStart(_event): void

Defined in: src/core/Script.ts:132

Called whenever pinch / mouse click starts, globally.

Parameters​

_event​

SelectEvent

The interaction source and optional captured target.

Returns​

void

Inherited from​

Script.onSelectStart


onSimulatorStarted()​

onSimulatorStarted(): void

Defined in: src/core/Script.ts:124

Returns​

void

Inherited from​

Script.onSimulatorStarted


onSqueeze()​

onSqueeze(_event): void

Defined in: src/core/Script.ts:181

Called whenever gamepad trigger successfully completes, globally.

Parameters​

_event​

SelectEvent

event.source.controller identifies the controller.

Returns​

void

Inherited from​

Script.onSqueeze


onSqueezeEnd()​

onSqueezeEnd(_event): void

Defined in: src/core/Script.ts:170

Called whenever gamepad trigger stops, globally.

Parameters​

_event​

SelectEvent

event.source.controller identifies the controller.

Returns​

void

Inherited from​

Script.onSqueezeEnd


onSqueezeStart()​

onSqueezeStart(_event): void

Defined in: src/core/Script.ts:165

Called whenever gamepad trigger starts, globally.

Parameters​

_event​

SelectEvent

event.source.controller identifies the controller.

Returns​

void

Inherited from​

Script.onSqueezeStart


onSqueezing()​

onSqueezing(_event): void

Defined in: src/core/Script.ts:175

Called whenever gamepad is being triggered, globally.

Parameters​

_event​

SelectEvent

Returns​

void

Inherited from​

Script.onSqueezing


onXRSessionEnded()​

onXRSessionEnded(): void

Defined in: src/core/Script.ts:122

Returns​

void

Inherited from​

Script.onXRSessionEnded


onXRSessionStarted()​

onXRSessionStarted(_session?): void

Defined in: src/core/Script.ts:121

Parameters​

_session?​

XRSession

Returns​

void

Inherited from​

Script.onXRSessionStarted


physicsStep()​

physicsStep(): void

Defined in: src/core/Script.ts:119

Returns​

void

Inherited from​

Script.physicsStep


setState_()​

protected setState_(state, details): void

Defined in: src/video/VideoStream.ts:155

Sets the stream's state and dispatches a 'statechange' event.

Parameters​

state​

StreamState

The new state.

details​

Additional data for the event payload.

VideoStreamDetails | T

Returns​

void


snapshotSourceAvailable_()​

protected snapshotSourceAvailable_(): boolean

Defined in: src/video/VideoStream.ts:243

Whether the current snapshot source has pixels available. Subclasses may override this to provide non-video sources while preserving getSnapshot's format handling.

Returns​

boolean


stop_()​

protected stop_(): void

Defined in: src/video/VideoStream.ts:343

Stops the current video stream tracks.

Returns​

void


update()​

update(_time?, _frame?): void

Defined in: src/core/Script.ts:113

Runs per frame.

Parameters​

_time?​

number

_frame?​

XRFrame

Returns​

void

Inherited from​

Script.update


waitForFreshFrame()​

waitForFreshFrame(timeoutMs): Promise<VideoFrameMetadata | null>

Defined in: src/video/VideoStream.ts:216

Waits for the next new video frame before returning, so a subsequent getSnapshot reads fresh pixels instead of whatever (possibly stale) frame the <video> element currently holds. Hidden or non-composited video elements — the normal situation inside an immersive XR session — can be throttled by the browser, in which case the held frame may be arbitrarily old.

Resolves with the frame's metadata (whose captureTime, when present, dates the pixels in the performance.now() timebase), or null when the signal is unavailable (requestVideoFrameCallback unsupported, no active media stream) or no frame arrived within timeoutMs.

Parameters​

timeoutMs​

number = 400

Returns​

Promise<VideoFrameMetadata | null>