Mux Real-Time Video has been sunset and is unavailiable for new usage. Existing access will end on December 31, 2023. We recommend migrating your application to our partner, LiveKit. Please reach out to real-time-video@mux.com if you need more help or details.
In this guide, you will learn about the different subscription modes in the Spaces SDKs and how to set them for the session.
Spaces SDKs offer an automatic mode and a manual mode for subscribing to participants. The SDKs only receive media from subscribed participants. By default, the SDKs operate under the automatic mode as it covers the majority of use cases.
The automatic subscription mode works by subscribing to a maximum of 20 participants which have the highest priority server-side. For example, recently speaking participants have higher priority than non-speaking participants, and you will automatically be subscribed to such participants if you're unsubscribed. Should you need more manual control, take a look at Using manual subscriptions.
The SDKs use the automatic subscription mode by default, so no configuration is required. Developers have the option to set their own automatic participant limit, which can be a number between 1 and 20, inclusive.
import com.mux.sdk.webrtc.spaces.Space;
import com.mux.sdk.webrtc.spaces.SpaceConfiguration;
import com.mux.sdk.webrtc.spaces.Spaces;
...
final String JWT = <YOUR_JWT>;
SpaceConfiguration spaceConfiguration = null;
try {
spaceConfiguration = SpaceConfiguration.newBuilder()
.setJWT(JWT)
.setManagedSubscriptions(5)
.build();
} catch (Exception e) {
e.printStackTrace();
return;
}
Spaces spaces = Spaces.getInstance(this);
Space space = spaces.getSpace(spaceConfiguration);
...
Developers can use the manual subscription mode for when they need programmatic control over which participants to subscribe to and receive media from.
import com.mux.sdk.webrtc.spaces.RemoteParticipant;
import com.mux.sdk.webrtc.spaces.Space;
import com.mux.sdk.webrtc.spaces.SpaceConfiguration;
import com.mux.sdk.webrtc.spaces.Spaces;
import com.mux.sdk.webrtc.spaces.Track;
import com.mux.sdk.webrtc.spaces.views.TrackRendererSurfaceView;
...
TrackRendererSurfaceView view;
RemoteParticipant alice;
...
final String JWT = <YOUR_JWT>;
SpaceConfiguration spaceConfiguration = null;
try {
spaceConfiguration = SpaceConfiguration.newBuilder()
.setJWT(JWT)
.setManagedSubscriptions(false)
.build();
} catch (Exception e) {
e.printStackTrace();
return;
}
Spaces spaces = Spaces.getInstance(this);
Space space = spaces.getSpace(spaceConfiguration);
space.join(new Space.Listener() {
@Override
public void onParticipantJoined(Space space, RemoteParticipant remoteParticipant) {
if(alice != null) {
alice.unsubscribe();
alice = null;
}
remoteParticipant.subscribe();
alice = remoteParticipant;
}
@Override
public void onParticipantLeft(Space space, RemoteParticipant remoteParticipant) {
if(alice == remoteParticipant) {
alice = null;
}
}
@Override
public void onParticipantTrackSubscribed(Space space, Participant participant, Track track) {
if(participant == alice && track.trackType == Track.TrackType.Video) {
view.setTrack(track);
}
}
@Override
public void onParticipantTrackUnsubscribed(Space space, Participant participant, Track track) {
if(participant == alice && track.trackType == Track.TrackType.Video) {
view.setTrack(null);
}
}
});
...