Skip to main content

Class: Producer

Coordinates video and audio encoding and publishing inside the pipeline worker.

Use addVideo() and addAudio() to configure tracks, then call start() to spawn the worker and begin encoding. Access the running pipeline through controller() to open a connection.

Example​

const producer = new Producer()
producer.addVideo(videoTrack, videoConfig)
producer.addAudio(audioTrack, audioConfig)
await producer.start(channelId)
const connection = producer.controller().connect({ url, authToken })

Methods​

addAudio()​

addAudio(track, config): this

Add an audio track for encoding.

Parameters​

track​

MediaStreamTrack

config​

AudioConfig | AudioConfig[]

Returns​

this


addTrack()​

addTrack(input): this

Add an audio or video track for encoding.

Parameters​

input​

TrackInput

Returns​

this


addVideo()​

addVideo(track, config): this

Add a video track for encoding.

Parameters​

track​

MediaStreamTrack

config​

VideoConfig | VideoConfig[]

Returns​

this


controller()​

controller(): PipelineController

The running pipeline controller. Throws before start().

Returns​

PipelineController


controllerIfStarted()​

controllerIfStarted(): PipelineController | undefined

The pipeline controller if started, otherwise undefined.

Returns​

PipelineController | undefined


hasClosed()​

hasClosed(): boolean

True once the producer has terminally settled (pipeline/worker death or close()). Synchronous.

Returns​

boolean


start()​

start(channelId): Promise<void>

Spawn the pipeline worker and begin encoding every added track.

Parameters​

channelId​

string

Returns​

Promise<void>