IFRAME API Basics
Understanding the VDO.Ninja IFRAME API: Detecting User Joins and Disconnects
The VDO.Ninja IFRAME API allows websites to embed and interact with VDO.Ninja streams. One of the most useful features is the ability to detect when users join or disconnect from your stream through event messaging. This guide will explain how to implement this functionality in your own projects.
How the IFRAME API Works
VDO.Ninja's IFRAME API uses the browser's postMessage API to communicate between your parent website and the embedded VDO.Ninja iframe. This allows you to:
Send commands to control the VDO.Ninja instance
Receive events and data from the VDO.Ninja instance
Setting Up the Basic Structure
irst, you need to create an iframe that loads VDO.Ninja:
// Create the iframe element
var iframe = document.createElement("iframe");
// Set necessary permissions
iframe.allow = "camera;microphone;fullscreen;display-capture;autoplay;";
// Set the source URL (your VDO.Ninja room)
iframe.src = "https://vdo.ninja/?room=your-room-name&cleanoutput";
// Add the iframe to your page
document.getElementById("container").appendChild(iframe);Setting Up the Event Listener
To detect joins and disconnects, you need to set up an event listener for messages from the iframe:
Detecting User Joins and Disconnects
The key events to watch for are:
Guest Connections
Disconnections
Complete Working Example
Here's a complete example that demonstrates detecting joins and disconnects:
Waiting Room Example
You can implement a waiting room like the one in the waitingroom.html file from your code samples:
Getting Additional Information About Connections
For more detailed information about connections, you can use the getStreamIDs or getDetailedState commands:
Best Practices
Always check the source: Make sure messages are coming from your VDO.Ninja iframe.
Handle disconnections gracefully: Sometimes connections drop unexpectedly.
Consider implementing reconnection logic: If important users disconnect, you might want to notify them or attempt to reconnect.
Debug with console.log: Log all events during development to understand the full message flow.
Test with multiple users: The behavior can be different depending on who connects first.
By implementing these techniques, you can build sophisticated applications that respond to users joining and leaving your VDO.Ninja sessions, creating more interactive and responsive experiences.
VDO.Ninja IFRAME API - Complete Inbound Control Reference
This document provides a comprehensive list of all inbound remote control calls available through the VDO.Ninja IFRAME API. These commands allow you to control a VDO.Ninja instance embedded in an iframe from your parent webpage.
Table of Contents
Basic Usage
To send commands to the VDO.Ninja iframe:
Audio Controls
mic - Microphone Control
mic - Microphone ControlControls the local microphone mute state.
mute / speaker - Speaker Control
mute / speaker - Speaker ControlControls the speaker mute state (incoming audio).
volume - Volume Control
volume - Volume ControlSets the volume level for incoming audio (0.0 to 1.0).
panning - Audio Panning
panning - Audio PanningAdjusts stereo panning for incoming audio.
targetAudioBitrate - Audio Bitrate Target
targetAudioBitrate - Audio Bitrate TargetSets the target audio bitrate (in kbps).
audiobitrate - Audio Bitrate Control
audiobitrate - Audio Bitrate ControlChanges the audio bitrate with optional lock.
PPT - Push-to-Talk
PPT - Push-to-TalkControls push-to-talk functionality.
Video Controls
camera - Camera Control
camera - Camera ControlControls the local camera on/off state.
pauseinvisible - Pause Invisible Videos
pauseinvisible - Pause Invisible VideosControls whether videos hidden in the mixer are paused.
keyframe - Request Keyframe
keyframe - Request KeyframeForces a keyframe to be sent to all scene connections.
Stream Management
requestStream - Request Specific Stream
requestStream - Request Specific StreamLoads a specific stream by ID.
close / hangup - Disconnect Streams
close / hangup - Disconnect StreamsDisconnects and hangs up connections.
Recording Controls
record - Local Recording Control
record - Local Recording ControlControls local video recording.
Group Management
groups - Set Groups
groups - Set GroupsSets the groups for the local stream.
groupView - Set View Groups
groupView - Set View GroupsSets which groups are visible.
Bitrate & Quality Controls
bitrate - Video Bitrate Control
bitrate - Video Bitrate ControlSets video bitrate for streams (in kbps).
targetBitrate - Target Video Bitrate
targetBitrate - Target Video BitrateSets the fundamental bitrate target.
manualBitrate - Manual Bandwidth Control
manualBitrate - Manual Bandwidth ControlSets manual bandwidth limits.
scale - Resolution Scaling
scale - Resolution ScalingControls resolution scaling.
targetWidth / targetHeight - Resolution Request
targetWidth / targetHeight - Resolution RequestRequest specific resolution from remote connection.
Device Management
changeVideoDevice - Change Camera
changeVideoDevice - Change CameraChanges the active video input device.
changeAudioDevice - Change Microphone
changeAudioDevice - Change MicrophoneChanges the active audio input device.
changeAudioOutputDevice - Change Speaker
changeAudioOutputDevice - Change SpeakerChanges the audio output device.
getDeviceList - List Available Devices
getDeviceList - List Available DevicesRequests a list of available media devices.
Layout & Display Controls
layout - Set Layout
layout - Set LayoutSets the display layout.
previewMode - Switch Preview Mode
previewMode - Switch Preview ModeSwitches between preview modes.
slotmode - Slot Mode Control
slotmode - Slot Mode ControlControls slot mode behavior.
advancedMode - Toggle Advanced UI
advancedMode - Toggle Advanced UIShows/hides advanced UI elements.
toggleSettings - Toggle Settings Panel
toggleSettings - Toggle Settings PanelControls the settings panel visibility.
target - DOM Manipulation
target - DOM ManipulationManipulates video elements in the DOM.
Data & Messaging
sendData - Send Generic Data
sendData - Send Generic DataSends data through peer connections.
sendChat - Send Chat Message
sendChat - Send Chat MessageSends a chat message to all peers.
sendMessage - WebRTC Message to Viewers
sendMessage - WebRTC Message to ViewersSends a message to viewer connections.
sendRequest - WebRTC Request to Publishers
sendRequest - WebRTC Request to PublishersSends a request to publisher connections.
sendPeers - Message All Peers
sendPeers - Message All PeersSends a message to all connected peers.
sendRawMIDI - Send MIDI Data
sendRawMIDI - Send MIDI DataSends raw MIDI messages.
Statistics & Monitoring
getStats - Get Quick Stats
getStats - Get Quick StatsRequests current statistics.
getFreshStats - Get Detailed Stats
getFreshStats - Get Detailed StatsRequests detailed statistics (takes ~1 second).
getRemoteStats - Request Remote Stats
getRemoteStats - Request Remote StatsRequests statistics from remote peers.
requestStatsContinuous - Continuous Stats
requestStatsContinuous - Continuous StatsEnables/disables continuous statistics updates.
getLoudness - Audio Loudness Monitoring
getLoudness - Audio Loudness MonitoringEnables/disables loudness monitoring.
getStreamIDs - List Stream IDs
getStreamIDs - List Stream IDsGets a list of all connected stream IDs.
getStreamInfo - Detailed Stream Information
getStreamInfo - Detailed Stream InformationGets detailed information about all streams.
getDetailedState - Complete State Information
getDetailedState - Complete State InformationGets comprehensive state information.
getGuestList - Get Guest List
getGuestList - Get Guest ListGets a list of all connected guests.
Utility Functions
reload - Reload Page
reload - Reload PageForces a page reload.
style - Inject Custom CSS
style - Inject Custom CSSInjects custom CSS into the iframe.
function - Execute Built-in Functions
function - Execute Built-in FunctionsExecutes predefined functions.
saveVideoFrameToDisk - Save Screenshot
saveVideoFrameToDisk - Save ScreenshotSaves a video frame to disk.
getVideoFrame - Get Video Frame Data
getVideoFrame - Get Video Frame DataGets video frame data as base64.
copyVideoFrameToClipboard - Copy Screenshot
copyVideoFrameToClipboard - Copy ScreenshotCopies a video frame to clipboard.
getSnapshotBySlot / getSnapshotByStreamID - Get Slot/Stream Snapshot
getSnapshotBySlot / getSnapshotByStreamID - Get Slot/Stream SnapshotGets a snapshot from a specific slot or stream using MediaStreamTrackProcessor.
Advanced Controls
sceneState - OBS Scene State
sceneState - OBS Scene StateSets the scene state for OBS integration.
layouts - OBS Layout Sync
layouts - OBS Layout SyncSyncs layouts with OBS.
obsCommand - OBS Commands
obsCommand - OBS CommandsSends commands to OBS.
setBufferDelay - Audio/Video Buffer Delay
setBufferDelay - Audio/Video Buffer DelaySets the buffer delay in milliseconds.
automixer - Automixer Control
automixer - Automixer ControlControls the automatic mixer behavior.
enableYouTube - YouTube Chat Integration
enableYouTube - YouTube Chat IntegrationEnables YouTube chat integration.
nextSlide / prevSlide - Slide Navigation
nextSlide / prevSlide - Slide NavigationControls slide navigation.
getFaces / faceTrack - Face Detection
getFaces / faceTrack - Face DetectionControls face detection/tracking.
getEffectsData - Effects Data
getEffectsData - Effects DataGets data from visual effects (face tracking, etc.).
action - Companion API Actions
action - Companion API ActionsExecutes Companion API actions.
Response Handling
Many commands support a callback ID (cib) for tracking responses:
Notes
All commands are sent via
postMessageto the iframe'scontentWindowThe second parameter
"*"can be replaced with a specific origin for securitySome commands require director privileges to function
Commands that affect remote streams often accept
UUID,streamID, ortargetparametersThe
lockparameter on bitrate controls prevents automatic adjustmentsMany "get" commands return data via postMessage back to the parent window
Last updated
Was this helpful?