Skip to content

Instantly share code, notes, and snippets.

@aullman
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aullman/c16a7b0af5b28cd6b1c3 to your computer and use it in GitHub Desktop.
Save aullman/c16a7b0af5b28cd6b1c3 to your computer and use it in GitHub Desktop.
Example API to support Simulcast

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.

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