← All demos
Track management
A publisher starts with no media, then adds, removes, and switches camera and microphone tracks while the viewer stays connected. The viewer updates as tracks arrive or go away, without reconnecting.
- Start publishing. It connects with no media (data only).
- Start viewing here, or open the share link on another device and press Start viewing there.
- Add video or audio and watch it appear in the viewer. Press Unmute to hear audio (use headphones to avoid echo).
- Remove or switch tracks. The viewer drops or swaps them on the same connection.
Publisher
Not publishingTracks
Local preview
Viewer
Not viewingReceived tracks
Remote
Key SDK calls in this demo
// Publisher: start with no media, then change tracks live
const pub = new VDONinjaSDK({ room, password });
await pub.connect();
await pub.announce({ room, streamID }); // data-only to start
await pub.addTrack(camTrack, localStream); // renegotiates with each viewer
await pub.removeTrack(camTrack); // stops it and renegotiates
await pub.replaceTrack(oldCamTrack, newCamTrack); // swap without renegotiation
// Viewer: tracks arrive and leave on the same connection
viewer.addEventListener('track', ({ detail }) => {
show(detail.track);
detail.streams[0]?.addEventListener('removetrack', (e) => hide(e.track));
});
await viewer.quickView({ room, streamID, audio: true, video: true });