This topic includes details on setting the maximum video bitrate using the Vonage Video web client SDK. Please note that the API is supported in recent versions of all supported browsers. If you encounter errors, make sure that the client is using an up-to-date browser version.
For an overview of the publisher maximum bitrate API, see this topic.
The Publisher object includes setVideoBitratePreset() and
getVideoBitratePreset() methods. The setVideoBitratePreset() method accepts
string values - 'DEFAULT', 'BW_SAVER', or 'EXTRA_BW_SAVER' (or their
lowercase counterparts) - and the getVideoBitratePreset() method returns these
values (or 'CUSTOM'). See Video bitrate presets for
more details on these presets.
Please note the getVideoBitratePreset()
method returns undefined if no preset or bitrate has previously been set.
The setVideoBitratePreset() method has one parameter: preset, the desired preset.
Example:
console.log(publisher.getVideoBitratePreset()); // undefined
await publisher.setVideoBitratePreset('BW_SAVER'); // or 'DEFAULT' or 'EXTRA_BW_SAVER'
console.log(publisher.getVideoBitratePreset()); // 'BW_SAVER'
The setVideoBitratePreset() method can throw an error with the name property of the error object set to the following:
OT_INVALID_PARAMETER - Invalid preset. It must be 'DEFAULT', 'BW_SAVER', or 'EXTRA_BW_SAVER'.
OT_UNEXPECTED_ERROR_CODE - An unexpected error was encountered, and the preset was not updated.
Wrap the call to the setVideoBitratePreset() method in a try/catch block, even if the preset name is correct:
const invalidPreset = 'VERY_FAST';
try {
await publisher.setVideoBitratePreset(invalidPreset);
} catch (err) {
console.error(err.name);
// 'OT_INVALID_PARAMETER'
}
If the predefined presets are not suitable, you can manually set a custom raw bitrate value.
To get the maximum video bitrate currently set for a publisher, call the getMaxVideoBitrate() method of a Publisher object. This returns the currently set maximum bitrate (in bits per second). If no custom value is set, the function returns undefined.
Example:
console.log(publisher.getMaxVideoBitrate());
To set a custom maximum bitrate value (instead of a preset), use the setMaxVideoBitrate() method on of a Publisher object. This function has the a single parameter: bitrateBps, the desired maximum bitrate (in bits per second), between 5,000 and 10,000,000.
Example:
const new_bitrate = 300000; // 300 kbps
await publisher.setMaxVideoBitrate(new_bitrate);
The setMaxVideoBitrate() method can throw an error with the name property of the error object set to the following:
OT_INVALID_PARAMETER - Invalid bitrate. The value must be 0 or a number between 5000 and 10000000.OT_UNEXPECTED_ERROR_CODE - An unexpected error was encountered and the bitrate was not updated.Wrap the call to the setVideoBitratePreset() method in a try/catch block, even if the number passed in is valid.
See Setting raw bitrate values for more details.
Setting the maximum bitrate value to 0 removes any previously set bitrate limitation, reverting to the default behavior.
const zero_bitrate = 0; // no limitations
const int new_bitrate = 300000; // 300 kbps
publisher.setMaxVideoBitrate(new_bitrate);
// publisher.getMaxVideoBitrate() === 300000
publisher.setMaxVideoBitrate(zero_bitrate);
// publisher.getMaxVideoBitrate() === 0
Calling the getVideoBitratePreset() method after setting a custom bitrate other than 0 returns CUSTOM.
const zero_bitrate = 0; // no limitations
const new_bitrate = 1000000; // 1 mbps
publisher.setMaxVideoBitrate(new_bitrate);
// publisher.getVideoBitratePreset() === 'CUSTOM'
publisher.setMaxVideoBitrate(zero_bitrate);
// publisher.getVideoBitratePreset() === 'DEFAULT'
The raw bitrate getter returns 0 when the publisher is using a preset.
let bitrateBps = publisher.getMaxVideoBitrate();
// bitrateBps === 0
publisher.setVideoBitratePreset('bw_saver);
bitrateBps = publisher.getMaxVideoBitrate();
// bitrateBps === 0
publisher.setVideoBitratePreset('extra_bw_saver');
bitrateBps = publisher.getMaxVideoBitrate();
// bitrateBps === 0
publisher.setMaxVideoBitrate(200000);
bitrateBps = publisher.getMaxVideoBitrate();
// bitrateBps === 200000
publisher.setVideoBitratePreset('default');
bitrateBps = publisher.getMaxVideoBitrate();
// bitrateBps === 0