Menu

Expand
Rate this page:

Using the Track Priority API

This page is for reference only. We are no longer onboarding new customers to Programmable Video. Existing customers can continue to use the product until December 5, 2024.

We recommend migrating your application to the API provided by our preferred video partner, Zoom. We've prepared this migration guide to assist you in minimizing any service disruption.

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 5.8.0+
iOS 3.4.0+

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 (Required v5.8.0+)

// You can set the publisher track priority at publish time
LocalTrackPublicationOptions localTrackPublicationOptions = new LocalTrackPublicationOptions(TrackPriority.HIGH);
localParticipant.publishTrack(localVideoTrack, localTrackPublicationOptions);

 // The publish priority is also represented in remote audio, video, and data track publications.
remoteVideoTrackPublication.getPublishPriority();

// You can also update the track priority of a published track
localVideoTrackPublication.setPriority(TrackPriority.STANDARD);

// That change will result in a RemoteParticipant.Listener callback 
@Override
public void onVideoTrackPublishPriorityChanged(
        @NonNull final RemoteParticipant remoteParticipant,
        @NonNull final RemoteVideoTrackPublication remoteVideoTrackPublication,
        @NonNull final TrackPriority trackPriority) {
    Log.d(TAG, "The publisher has changed the priority of this Track to " + trackPriority)
}

iOS SDK (Required v3.4.0+)

// You can set the publisher track priority at publish time
let localVideoTrackPublicationOptions = LocalTrackPublicationOptions(priority: .high)
localParticipant.publishVideoTrack(localVideoTrack, publicationOptions: localVideoTrackPublicationOptions);

// The publish priority is also represented in remote audio, video, and data track publications.
let publishPriority = remoteVideoTrackPublication.publishPriority

// You can also update the track priority of a published track
localVideoTrackPublication.priority = .high

// That change will result in a RemoteParticipantDelegate callback 
extension ViewController : RemoteParticipantDelegate {
    func remoteParticipantDidChangeAudioTrackPublishPriority(participant: RemoteParticipant,
                                                             priority: Track.Priority,
                                                             publication: RemoteAudioTrackPublication) {}
}

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 (Required v5.8.0+)

// You can set the publisher track priority at publish time
LocalTrackPublicationOptions localTrackPublicationOptions = new LocalTrackPublicationOptions(TrackPriority.LOW);
localParticipant.publishTrack(localVideoTrack, localTrackPublicationOptions);

 // That priority is propagated to all subscribers
remoteVideoTrackPublication.getPublishPriority();

// Subscribers can now override the publisher side priority on the remote Track
remoteVideoTrack.setPriority(TrackPriority.HIGH);

// We can revert back to the publisher priority
remoteVideoTrack.setPriority(null);

iOS SDK (Required v3.4.0)

// You can set the publisher track priority at publish time
let localVideoTrackPublicationOptions = LocalTrackPublicationOptions(priority: .low)
localParticipant.publishVideoTrack(localVideoTrack, publicationOptions: localVideoTrackPublicationOptions);

// That priority is propagated to all subscribers
let publishPriority = remoteVideoTrackPublication.publishPriority

// Subscribers can now override the publisher side priority on the remote Track
remoteVideoTrack.priority = .high

// We can revert back to the publisher priority
remoteVideoTrack.priority = nil

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 Carly Vanderwert Dax Lehman
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 by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

Loading Code Sample...
        
        
        

        Thank you for your feedback!

        Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        thanks-feedback-gif