# new BandwidthMonitor()
Example
const monitor = new BandwidthMonitor();
// Add video consumers to monitor
monitor.addConsumer(videoConsumer);
// Start monitoring (logs stats every 2 seconds)
monitor.startBandwidthMonitoring();
// Stop monitoring when done
monitor.stopBandwidthMonitoring();
// Clean up
monitor.dispose();
Classes
Methods
# addConsumer(consumer)
Add a consumer to be monitored. Only video consumers are tracked; audio consumers are ignored.
Parameters:
| Name | Type | Description |
|---|---|---|
consumer |
Object
|
A consumer object |
id |
string
|
Unique consumer identifier |
kind |
string
|
Consumer type: 'video' or 'audio' |
getStats |
function
|
Method to retrieve WebRTC stats |
# dispose()
Stop monitoring and remove all consumers. Call this when cleaning up the monitor instance.
# startBandwidthMonitoring()
Start bandwidth monitoring for all registered consumers. Logs bitrate, resolution, and FPS every 2 seconds. If monitoring is already active, it will be restarted.
# stopBandwidthMonitoring()
Stop bandwidth monitoring for all consumers. Also removes any closed consumers from the list.