StreamApi
Class representing instance of Streams API
Methods
destroyRefs
Created by EndpointFactory.createStreamApi - never constructed by SDK users.
createStreamRoom
Creates a new Stream Room in the given Context and returns the new Stream Room's ID. A random 256-bit room key is generated client-side and encrypted separately for each listed user with ECIES using their public key - the server stores only the encrypted per-user key entries and cannot read the key. privateMeta is encrypted client-side with the room key; publicMeta is stored unencrypted on the server. Entry point of the publish/receive workflows: follow with joinStreamRoom before creating or subscribing to streams. Adjust members or metadata later with updateStreamRoom.
Params
contextId
string
ID of the Context to create the Stream Room in, from Context.contextId via Connection.listContexts
users
UserWithPubKey[]
members allowed to access the Stream Room; build the entries from Connection.listContextUsers
managers
UserWithPubKey[]
members who can additionally update or delete the Stream Room; build the entries from Connection.listContextUsers
publicMeta
Uint8Array
metadata stored unencrypted on the server - readable by the Bridge, so never place secrets here
privateMeta
Uint8Array
metadata encrypted client-side with the room key; only Stream Room members can decrypt it
policies
ContainerPolicy
fine-grained access rules overriding the Context defaults; pass undefined to use the defaults
emptyRoomTtl
number
grace period (ms) the room stays open after the last participant leaves before being closed; 0 closes it immediately, and undefined uses the server default
Returns
Promise<string> ·
ID of the new Stream Room - pass to joinStreamRoom, getStreamRoom or updateStreamRoom
updateStreamRoom
Replaces the member lists, metadata and (optionally) the encryption key of an existing Stream Room. The room key list is re-encrypted for the new user set (ECIES on each user's public key). With forceGenerateNewKey a fresh room key is generated and redistributed, so removed users cannot decrypt media or data sent after the update. The update is a full replacement, not a diff - fetch the current state with getStreamRoom, modify it, and pass the Stream Room's version back so concurrent modifications are detected. Set forceGenerateNewKey whenever you remove users.
Params
streamRoomId
string
ID of the Stream Room to update, returned by createStreamRoom or from StreamRoom.streamRoomId in listStreamRooms
users
UserWithPubKey[]
full replacement list of members allowed to access the Stream Room; users missing from this list lose access
managers
UserWithPubKey[]
full replacement list of members with management rights (update / delete the Stream Room)
publicMeta
Uint8Array
new metadata stored unencrypted on the server - never place secrets here
privateMeta
Uint8Array
new metadata encrypted client-side with the room key
version
number
current Stream Room version, from StreamRoom.version returned by getStreamRoom - lets the server reject stale updates
force
boolean
true skips the version check and overwrites any concurrent modification; defaults to false
forceGenerateNewKey
boolean
when true, a fresh room key is generated and redistributed, so users removed by this update cannot decrypt media or data sent afterwards - set it whenever you revoke access; defaults to false
policies
ContainerPolicy
new access policies; pass undefined to keep the current ones
listStreamRooms
Lists the Stream Rooms of a Context that the user is a member of, one page at a time. Downloads the Stream Room records from the Bridge and decrypts each privateMeta client-side with the corresponding room key. Typically the first StreamApi call after connecting - pick a Stream Room from the result and enter it with joinStreamRoom.
Params
contextId
string
ID of the Context to enumerate, from Context.contextId via Connection.listContexts
query
PagingQuery
pagination and sorting; start with { skip: 0, limit: 100, sortOrder: "desc" } and page using skip or lastId
Returns
Promise<PagingList<StreamRoom>> ·
one page of Stream Rooms plus totalAvailable; use StreamRoom.streamRoomId with joinStreamRoom or getStreamRoom
joinStreamRoom
Joins a Stream Room so this connection can publish or receive its streams. Establishes the room's encrypted Event channel over the Bridge, through which the room key and per-stream keys are synchronized to this client. Required before createStream / publishStream on the publish path and before createSubscriberStream on the receive path; leave the room with leaveStreamRoom.
Params
streamRoomId
string
ID of the Stream Room to join, returned by createStreamRoom or from StreamRoom.streamRoomId in listStreamRooms
leaveStreamRoom
Leaves a Stream Room, tearing down this connection's membership of its Event channel. The client stops receiving the room's key updates and events; any published streams should be stopped first with unpublishStream. Last step of the publish workflow after unpublishStream; rejoin later with joinStreamRoom.
Params
streamRoomId
string
ID of the Stream Room to leave, returned by createStreamRoom or from StreamRoom.streamRoomId in listStreamRooms
getStreamRoom
Fetches a single Stream Room with its metadata, member lists and version. Downloads the Stream Room record from the Bridge and decrypts privateMeta client-side with the user's copy of the room key; publicMeta arrives as stored, unencrypted. Use it to display Stream Room details or to obtain the current version required by updateStreamRoom.
Params
streamRoomId
string
ID of the Stream Room to fetch, returned by createStreamRoom or from StreamRoom.streamRoomId in listStreamRooms
Returns
Promise<StreamRoom> ·
decrypted Stream Room data - version feeds updateStreamRoom; streamRoomId feeds joinStreamRoom
deleteStreamRoom
Permanently deletes a Stream Room together with its encrypted key entries. The server removes the Stream Room record and its encrypted per-user key entries - there is no undo. Requires management rights to the Stream Room (see the managers list of createStreamRoom / updateStreamRoom). To merely revoke access, keep the room and remove users with updateStreamRoom instead.
Params
streamRoomId
string
ID of the Stream Room to delete, returned by createStreamRoom or from StreamRoom.streamRoomId in listStreamRooms
createStream
Creates a local Stream handle for publishing media or data in the given Stream Room and returns the handle. Only a local, in-memory Stream entry is created - nothing reaches the server or peers yet. Stage tracks with addStreamTrack / removeStreamTrack, then push the changes with publishStream / updateStream. Follows joinStreamRoom on the publish path; next call addStreamTrack per track and finally publishStream.
Params
streamRoomId
string
ID of the Stream Room to create the stream in, returned by createStreamRoom or from StreamRoom.streamRoomId in listStreamRooms
Returns
Promise<number> ·
local stream handle consumed by addStreamTrack, publishStream and unpublishStream
listStreams
Lists the streams currently published by all members in the given Stream Room. Fetches the room's live stream roster from the Bridge - these are remote streams produced by published peers, not the local handles created with createStream. Use it to discover which remote streams exist before selecting some to receive with createSubscriberStream.
Params
streamRoomId
string
ID of the Stream Room to enumerate, returned by createStreamRoom or from StreamRoom.streamRoomId in listStreamRooms
Returns
Promise<StreamInfo[]> ·
descriptors of currently published streams; pick targets to subscribe to with createSubscriberStream
listStreamRoomParticipants
Lists the participants of the given Stream Room, along with the stream subscriptions each of them currently has and, if they are publishing, the descriptor of their published stream.
Params
streamRoomId
string
ID of the Stream Room to enumerate, returned by createStreamRoom or from StreamRoom.streamRoomId in listStreamRooms
Returns
Promise<StreamSubscriber[]> ·
descriptors of the room's participants
addStreamTrack
Stages a media track (or data channel) on a local Stream handle and returns its track ID. The track is recorded only in an in-memory map - it reaches the server and peers, and starts being AES-256-GCM encrypted in the E2EE worker, only after publishStream (or updateStream for an already-published stream). Call once per track between createStream and publishStream; pass createDataChannel to stage a data channel whose ID is later used with sendData.
Params
streamHandle
number
local stream handle returned by createStream
meta
StreamTrackInit
track/data-channel definition - track is the browser MediaStreamTrack to publish and/or createDataChannel requests a data channel
Returns
Promise<string> ·
track ID identifying this staged track - pass to sendData for data channels
removeStreamTrack
Marks a previously staged media track for removal from a Stream handle. The matching track is only flagged in the in-memory map; the removal reaches peers when updateStream renegotiates the published stream (or it is simply dropped before the first publishStream). Use it to drop a track from a stream; apply the change with updateStream for an already-published stream.
Params
streamHandle
number
local stream handle returned by createStream
meta
StreamTrackInit
track definition whose track matches the browser MediaStreamTrack previously passed to addStreamTrack
publishStream
Publishes the Stream with its currently staged tracks, making it visible to other Stream Room members. Fetches per-publish TURN credentials, negotiates an outbound WebRTC peer connection with the Bridge's Janus media server, and wires the E2EE worker into the RTCRtpSender pipeline so every outgoing media frame is AES-256-GCM encrypted (with the frame header as additional authenticated data). Only tracks staged via addStreamTrack are sent. Core call of the publish workflow after createStream and addStreamTrack; stage further track changes and apply them with updateStream, stop publishing with unpublishStream, and send data-channel bytes with sendData.
Params
streamHandle
number
local stream handle returned by createStream
onStreamState
(state: RTCPeerConnectionState) => void
optional callback invoked whenever the underlying RTCPeerConnection changes state (e.g. connected, disconnected, failed)
Returns
Promise<StreamPublishResult> ·
result of the publish operation describing the now-live stream
updateStream
Applies staged track additions and removals to an already-published Stream. Refreshes the TURN credentials and renegotiates the existing WebRTC peer connection, adding senders for newly staged tracks and removing the ones flagged by removeStreamTrack; the E2EE worker keeps encrypting outgoing frames with AES-256-GCM across the renegotiation. Call after staging more addStreamTrack / removeStreamTrack changes on a stream already sent with publishStream.
Params
streamHandle
number
local stream handle returned by createStream and already published via publishStream
Returns
Promise<StreamPublishResult> ·
result of the update operation describing the renegotiated stream
unpublishStream
Stops publishing the Stream and tears down its outbound peer connection. Notifies the Bridge to drop the stream, closes the sender RTCPeerConnection, and discards the handle's staged tracks and state - the stream stops being visible to other members. Follows publishStream when you are done streaming; leave the room afterwards with leaveStreamRoom.
Params
streamHandle
number
local stream handle returned by createStream and published via publishStream
createSubscriberStream
Creates a subscriber stream that receives the selected remote streams (and optionally specific tracks) in the Stream Room, and returns its handle. Fetches TURN credentials and negotiates an inbound WebRTC peer connection with the Janus media server for the chosen streams; incoming media frames are decrypted with AES-256-GCM in the E2EE worker wired into the RTCRtpReceiver pipeline. The returned SubscriberStreamHandle identifies this subscriber stream for later updateSubscriberStream / removeSubscriberStream calls. Entry point of the receive workflow after joinStreamRoom; register a callback with addRemoteStreamListener to obtain the arriving tracks, then adjust the set with updateSubscriberStream or tear it down with removeSubscriberStream.
Params
streamRoomId
string
ID of the Stream Room to subscribe in, returned by createStreamRoom or from StreamRoom.streamRoomId in listStreamRooms
subscriptions
StreamSubscription[]
remote streams/tracks to subscribe to, selected from the descriptors returned by listStreams
Returns
Promise<number> ·
handle identifying the new subscriber stream - pass it to updateSubscriberStream and removeSubscriberStream
updateSubscriberStream
Adds and removes subscriptions on an existing subscriber stream in one call, without recreating it from scratch. Tells the Bridge to start delivering the added streams and stop the removed ones over the subscriber stream's existing inbound peer connection; the E2EE worker continues decrypting frames for the streams that remain subscribed. Use it to adjust the set established by createSubscriberStream (e.g. follow the active speaker); to tear the whole subscriber stream down use removeSubscriberStream.
Params
subscriberStreamHandle
number
handle returned by createSubscriberStream
subscriptionsToAdd
StreamSubscription[]
remote streams/tracks to start receiving, selected from the descriptors returned by listStreams
subscriptionsToRemove
StreamSubscription[]
remote streams/tracks to stop receiving, from the set previously passed to createSubscriberStream or updateSubscriberStream
removeSubscriberStream
Removes a subscriber stream, stopping delivery of all the remote streams it received. Tells the Bridge to drop the subscriber stream; its inbound tracks end and the E2EE worker stops decrypting their frames. The inbound peer connection is torn down by the WebRTC layer when the last subscriber stream in the room is removed. Use it to stop receiving streams created via createSubscriberStream; to change rather than drop the set, prefer updateSubscriberStream.
Params
subscriberStreamHandle
number
handle returned by createSubscriberStream
addRemoteStreamListener
Registers a callback that fires when a subscribed remote track arrives in the Stream Room. The listener is invoked from the inbound RTCPeerConnection's track event after the E2EE worker has been wired in to decrypt the stream's frames; the delivered MediaStreamTrack already carries decrypted media. Register it on the receive path, normally right after createSubscriberStream, so the tracks selected there surface through onRemoteStreamTrack.
Params
listener
RemoteStreamListener
listener configuration object
subscribeFor
Subscribes this connection to Stream Room events matching the given subscription queries. Registers the subscriptions on the Bridge over the connection's event channel; matching events are then pushed by the server and surface through EndpointFactory.getEventQueue(). Required order: buildSubscriptionQuery (one query per event-type/selector pair) → subscribeFor(queries) → consume events from the event queue → unsubscribeFrom when no longer needed.
Params
subscriptionQueries
string[]
query strings produced by buildSubscriptionQuery; hand-written strings are not supported
Returns
Promise<string[]> ·
subscription IDs, index-aligned with subscriptionQueries - keep them to unsubscribeFrom later
unsubscribeFrom
Cancels Stream Room event subscriptions previously created on this connection, so the server stops pushing the matching events. Subscriptions also end implicitly when the connection is closed; call this only to stop receiving a subset of events while keeping the connection alive.
Params
subscriptionIds
string[]
IDs returned by subscribeFor; unknown IDs cause a NativeError rejection
buildSubscriptionQuery
Builds a subscription-query string describing one class of Stream Room events (e.g. "all stream events in Stream Room X"). The query is assembled locally by the WASM core in the server's expected format - nothing is sent yet; pass the result to subscribeFor to activate it.
Params
eventType
StreamEventType
which Stream Room event class to listen for (Stream Room create/update/delete, stream events, …)
selectorType
StreamEventSelectorType
what selectorId refers to (e.g. a whole Context or a single Stream Room), narrowing the event scope
selectorId
string
ID of the selected scope - a Stream Room ID returned by createStreamRoom or a Context ID from Connection.listContexts, depending on selectorType
Returns
Promise<string> ·
query string consumed by subscribeFor
readAudioStats
Reads the current audio-level statistics for the session's local and remote audio. Your local mic is measured directly from its track (a consistent reading in every browser); remote levels come from native WebRTC statistics, so a remote stream is simply omitted when the browser or SFU exposes no level for it. Pull-based, not a subscription: each call does one fresh read and returns immediately. Poll it on whatever interval suits your UI (e.g. every 200-500ms) to drive speaking indicators or volume meters; call it once the session is established via publishStream or createSubscriberStream. Each entry in levels is identified by streamId: your own local microphone is reported under streamId === -1, and each remote publisher under its own (non-negative) stream ID from listStreams. A stream only appears once it has reported a level, and drops out after prolonged silence - so the local entry is absent in a subscribe-only session and may briefly disappear between utterances; treat a missing entry as "not speaking." Per entry, emaRms is the smoothed level in dBFS (roughly -70 when quiet up to ~0 when loud) and activeUntil is the timestamp until which the stream counts as actively speaking (compare it against Date.now()).
Returns
Promise<AudioLevelsStats> ·
the current per-stream audio levels; levels[i].streamId === -1 is the local microphone
configureActiveSpeakerDetector
Tunes the active-speaker detection used by readAudioStats - pass any subset of the fields; omitted ones keep their current value. Takes effect immediately, from the next readAudioStats call.
Params
config
Partial<ActiveSpeakerDetectorConfig>
partial tuning overrides
sendData
Sends binary data to remote participants over a published Stream's WebRTC data channel. The bytes are encrypted natively by StreamApiLow into a sequenced wire frame and sent over the data channel; the sequence number strictly increases per data track for replay protection. Requires a data track staged with createDataChannel via addStreamTrack and a stream already sent with publishStream.
Params
streamTrackId
string
track ID returned by addStreamTrack for a data channel track
data
Uint8Array
raw bytes to deliver to remote participants
We use cookies on our website. We use them to ensure proper functioning of the site and, if you agree, for purposes such as analytics, marketing, and targeting ads.