Suggestions

close search

Add Messaging, Voice, and Authentication to your apps with Vonage Communications APIs

Visit the Vonage API Developer Portal
Developer Documentation is moving soon to a new location → https://developer.vonage.com Content will remain unchanged.

Publisher Video Constraints — Web

Once you have initialized a Publisher, you can control the preferred resolution and frame rate of the outgoing video track. This lets you optimize bandwidth and CPU usage for different UI sizes (thumbnails, tiles, full screen) and subscriber devices.

This topic includes the following sections:

Understanding publisher video constraints

The Publisher can advertise a preferred resolution and frame rate for its video track: the SDK applies constraints to the capture device and outbound track. Subscribers benefit from lower bandwidth and CPU when the publisher sets smaller sizes or lower frame rates for small UI targets. Note that delivered quality can be further adjusted by device capabilities and network conditions.

Setting the preferred resolution

Call publisher.setPreferredResolution(preferredResolution) to set the preferred pixel dimensions:

await publisher.setPreferredResolution({ width: 640, height: 360 });

Throws an error if:

try {
  // If the initial publish was 640x480, this will throw:
  await publisher.setPreferredResolution({ width: 1920, height: 1080 });
} catch (error) {
  console.error('Failed to set preferred resolution:', error.message);
}

Setting the preferred frame rate

Call publisher.setPreferredFrameRate(frameRate) to set a preferred frames-per-second value:

await publisher.setPreferredFrameRate(15);

Throws an error if:

How constraints affect delivery

Preferred constraints influence the outbound video track for all subscribers to the stream. However, the final delivered resolution and frame rate may be lower due to:

Best practices

Examples

// Lower quality for mobile users
if (isMobileUser) {
  publisher.setPreferredResolution({ width: 320, height: 180 });
  publisher.setPreferredFrameRate(15);
}

// Higher quality for desktop
if (isDesktopUser) {
  publisher.setPreferredResolution({ width: 1280, height: 720 });
  publisher.setPreferredFrameRate(30);
}

// Error when using resolution above initial publish
try {
  await publisher.setPreferredResolution({ width: 1920, height: 1080 }); // If initial was 640x480, throws error
} catch (error) {
  console.error(error.message);
}

// Debugging: Current track settings
const videoTrack = publisher.getVideoSource().track;
const { width, height, frameRate } = videoTrack.getSettings();
console.log('Current resolution:', width, 'x', height);
console.log('Current frame rate:', frameRate);

Troubleshooting

Handling errors

Wrap calls in try/catch and surface user-friendly messages when constraints are invalid or the environment cannot satisfy them.

async function setPublisherQuality(publisher, preferredResolution, preferredFrameRate) {
  try {
    await publisher.setPreferredResolution(preferredResolution);
    await publisher.setPreferredFrameRate(preferredFrameRate);
  } catch (err) {
    showMessage('Unable to apply video constraints. Check your device and network.');
    console.error(err);
  }
}

Network considerations

If the network is constrained, the media pipeline may lower the delivered resolution or frame rate regardless of preferred settings. Consider implementing UI indicators for reduced quality modes.

Additional resources