Working with Streams
Use StreamApi to manage Stream Rooms and real-time media streams.
Streams allow users to communicate in real time using audio, video, and desktop sharing inside Stream Rooms.
Each Context can contain any number of Stream Rooms with a unique identifier (streamRoomId) used to distinguish them.
About Streams
The public API exposed to library users is StreamApi.
It combines two areas of responsibility:
- Stream Room management
- live media publishing and remote stream subscriptions
Before working with Streams, follow the Getting Started Guide. It will show you how to set up your project to work with PrivMX Bridge. Sample code on this page is based on the initial assumptions.
Working with Streams
When working with Streams, you will use:
StreamApi- provides methods used to manage Stream Rooms and WebRTC streams
Creating Stream Rooms
createStreamRoom(...) creates a new Stream Room inside a given Context.
Like other PrivMX Modules, a Stream Room uses users, managers, publicMeta, and privateMeta.
Creating a basic Stream Room:
Listing and Reading Stream Rooms
Use listStreamRooms(...) for paged room listing and getStreamRoom(...) to fetch a single room.
You can fetch Stream Rooms exactly as you do with other Modules: by Context, by ID, or using paging parameters.
The returned StreamRoom object contains room metadata, members, managers, version, policy, and timestamps.
Modifying Stream Rooms
To update a room, use updateStreamRoom(...).
Just like with Threads, Stores, Inboxes, and KVDBs, updates overwrite the existing room definition, so you should pass the full set of room parameters.
Joining Stream Rooms
Before publishing a local stream or subscribing to remote streams, you need to join the room.
Use joinStreamRoom(...) when entering a room.
Publishing Local Streams
After joining a room, the usual publish flow is:
- Create a local stream handle with
createStream(...). - Add one or more tracks with
addTrack(...). - Publish the prepared stream using
publishStream(...).
If you later add or remove tracks, use updateStream(...) to apply the staged changes.
Subscribing to Remote Streams
To receive remote media:
- Call
listStreams(streamRoomId)to see what is currently available. - Build
StreamSubscriptionobjects for selected streams or tracks. - Subscribe with
subscribeToRemoteStreams(...). - Register a listener with
addRemoteStreamListener(...)to handle incoming tracks and media data.
When the subscription set changes, use modifyRemoteStreamsSubscriptions(...) or unsubscribeFromRemoteStreams(...).
Next Step
To react to room and stream lifecycle changes, continue with Stream Events.
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.