videojs / videojs-errors

A video.js plugin that displays error messages to video viewers.
Other
86 stars 28 forks source link

feat: Add backgroundTimeout option #198

Closed alex-barstow closed 3 years ago

alex-barstow commented 3 years ago

Description

This is a different approach to #197.

Background throttling can cause playback delays that will recover once the document becomes visible again, so it makes sense to handle foreground and background timeouts separately. This PR adds support for a backgroundTimeout option:

// Note: these are the default values for each timeout
player.errors({
  timeout: 45 * 1000,
  // 5 minutes. Pretty arbitrary so we can discuss alternative default values
  backgroundTimeout: 300 * 1000
});

// or after the plugin has been initialized:
player.errors.backgroundTimeout(Infinity);

Setting the value to Infinity disables background timeouts altogether.

brandonocasey commented 3 years ago

I looked into the throttled values for timers and there are a few things to note:

  1. most timers will be throttled to take 1s
  2. Timers can be throttled to take 1 minute if the video is muted and the page has been in the background for more than 5 minutes.

With that in mind we probably want to:

  1. Disable timers entirely if a video is muted and in a background tab. We will always time out when timers start to take 1 minute.
  2. I think five minutes is a good value as I think it's likely at least a 10x slowdown for timers to take 1s, but I don't think that 450 seconds is a reasonable value.

Documentation

alex-barstow commented 3 years ago

@brandonocasey Added another check and test for the muted case