Skip to content

Instantly share code, notes, and snippets.

@ggarber
Forked from aullman/simulcastAPI.md
Last active December 9, 2021 11:16
Show Gist options
  • Save ggarber/d840457b548c97080914 to your computer and use it in GitHub Desktop.
Save ggarber/d840457b548c97080914 to your computer and use it in GitHub Desktop.

The Subscriber has maxResolution and maxFrameRate properties:

  • maxResolution - Object containing a width and a height property. When set the Subscriber will try to use a resolution that falls within those values.
  • maxFrameRate - The maximum frame rate the Subscriber should use. This is an integer value.

These properties are used to limit the maximum quality of the stream for that specific subscriber and also to prioritize different subscribers in the same endpoint. In case the bandwidth available is not enough to send the video of all the subscribers at maximum quality they will be prioritized based on these properties (for example a subscriber with higher maxResolution/FrameRate will receive more bits when the available bandwidth is limited).

You can initialise these values by passing them to the session.subscribe method eg.

var subscriber = session.subscribe(stream, subscriberEl, {
  maxResolution: {
    width: 640,
    height: 480
  },
  maxFrameRate: 15
});

You can also set these values later once you have already started subscribing with:

subscriber.setMaxResolution({
  width: 640,
  height: 480
});

subscriber.setMaxFrameRate(15);

Here is an example of how you would dynamically set the resolution and frame rate. This example has moveOnStage and moveOffStage methods which will move the participants on and off stage. The logic for moving those participants on and off stage is not included. It is assumed though that some kind of signaling will be used to move people on and off stage. It is also assumed that the name of the streams for a person who is initially on stage is set to 'onstage'.

var onStageResolution = {
    width: 1280,
    height: 720
  },
  onStageFrameRate = 30,
  offStageResolution = {
    width: 320,
    height: 240
  },
  offStageFrameRate = 15;

var moveOnStage = function (subscriber) {
  $('#' + subscriber.id).addClass('onstage');
  subscriber.setMaxResolution(onStageResolution);
  subscriber.setMaxFrameRate(onStageFrameRate);
}

var moveOffStage = function (subscriber) {
  $('#' + subscriber.id).removeClass('onstage');
  subscriber.setMaxResolution(offStageResolution);
  subscriber.setMaxFrameRate(offStageFrameRate);
}

session.on('streamCreated', function (event) {
  var maxResolution = offStageFrameRate,
    maxFrameRate = offStageFrameRate;
  if (event.stream.name === 'onstage') {
    maxResolution = onStageResolution;
    maxFrameRate = onStageFrameRate;
  }
  session.subscribe(event.stream, 'subscribers', {
    insertMode: 'append',
    maxResolution: maxResolution,
    maxFrameRate: maxFrameRate
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment