Menu

Expand
Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

Using the Track Priority API

Overview

Not all video tracks are equal. For example, in a webinar application the screen share track is more important than the webcams, while in a video collaboration service the dominant speaker has more relevance than the rest of the participants.

To account for this, Twilio has created the Track Priority API, which makes it possible to set the priority of Tracks. The priority of a Track can be set to any of the following values:

  • high
  • standard
  • low

Track priorities can be understood as the relative relevance of Tracks. This means that, from the Twilio perspective, any Track marked as high will be more important than any standard Track, which in turn will be more relevant that any low priority Track.

Currently, only the Network Bandwidth Profile API consumes Track priorities to determine which Tracks are more relevant from the bandwidth allocation perspective. In the future Twilio may use Track priorities for other further purposes.

Contents

SDK Compatibility

The Track Priority API is only available in Group Rooms (including Small Group Rooms). The following table illustrates current support:

Twilio Video SDK Track Priority API
JavaScript 2.0.0+
Android Coming soon
iOS Coming soon

Publisher Track Priorities

The publisher Track priority is the priority given to a track by its publisher. By default, the publisher Track priority is standard. However, developers can specify a different priority at publish time. Once set, the publisher Track priority can be read both at the local and remote Track publications. Developers can also update the publisher Track priority using the setPriority primitive. In that case, all remote subscribers will be notified through an event. The following code snippets illustrate how this works:

JavaScript SDK (Required v2.0.0+)

//You can set the publisher track priority at publish time
const localTrackPublication = await room.localParticipant.publishTrack(localTrack, {
  priority: 'high' //choose among 'high', 'standard' or 'low'
});
//The publisher Track priority can also be read.
assert.equal(localTrackPublication.priority, 'high');

//The publisher Track priority is propagated to the RemoteTrackPublication.
remoteParticipant.on('trackPublished', remoteTrackPublication => {
  console.log(`RemoteTrackPublication with priority ${remoteTrackPublication.publishPriority}`);
});

//You can also update the track priority of a published track
localTrackPublication.setPriority('low')

//That change will fire an event in all subscribers indicating the updated priority
remoteTrackPublication.on('publishPriorityChanged', priority => {
  console.log('The publisher has changed the priority this Track to "${priority}"');
  assert.equal(remoteTrackPublication.publishPriority, priority);
});

Android SDK

Coming soon

iOS SDK

Coming soon

Subscriber Track Priorities

As stated above, the publisher Track priority propagates to all remote subscribers. However, sometimes, there are use-cases where subscribers need to set their very specific priorities. To deal with this in a Group Room, we have introduced subscriber Track priorities: a mechanism that allows a subscriber to override the publisher Track priority. The following code snippets illustrate how this works:

JavaScript SDK (Required v2.0.0+)

//You can set the publisher track priority at the publisher
const localTrackPublication = await room.localParticipant.publishTrack(localTrack, {
  priority: 'low' //choose among 'high', 'standard' or 'low'
});

//That priority is propagated to all subscribers
assert.equal(remoteTrackPublication.priority, 'low');

//Subscribers can now override the publisher side priority on the remote Track
remoteTrack.setPriority('high')

//This subscriber Track priority only affects that specific subscriber
assert.equal(remoteTrack.priority,'high')
//The overridden priority is still visible
assert.equal(remoteTrackPublication.priority, 'low');

//We can revert back to the publisher priority
remoteTrack.setPriority(null)
assert.equal(remoteTrack.priority, null)
assert.equal(remoteTrackPublication.priority, 'low');

Android SDK

Coming soon

iOS SDK

Coming soon

Using Publisher and Subscriber Track Priorities

Developers can use publisher and subscriber Track priorities for setting the Track relevance. The difference among both are subtle but relevant:

  • Publisher Track priorities are designed to set the relevance of a track “for all the Room subscribers”. For example, in a collaboration application a screenshare Track may be set to publisher Track priority high while all the webcams may be set to low. That would make the screen share to be (by default) much more relevant than the webcams for all the Participants.
  • Subscriber Track priorities are designed to modify the relevance of a track “for a specific subscriber”. In the above mentioned application, a specific subscriber may be more interested on seeing the reaction of another participant to the presentation rather than on the screen share. In that case, developers can override the publisher Track priority for that specific subscriber. For example, when the end-user clicks on the webcam of her interest, the screen share can be set a subscriber Track priority low and the webcam a subscriber Track priority high. This would allow that end-user to enhance on her UI that specific webcam.

Hence, publisher Track priorities are useful for specifying the desired default relevance of tracks for an application, while subscriber Track priorities are a mechanism developers can use to customize priorities to the needs of specific end-users.

Luis Lopez Aymen Naim
Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.