Skip to Content
Mux Docs: Home

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.

Naming your participants

Set and get participant display names

Understand display names

A participant can set a display name for themselves at join time, or at any time while connected to space. The initial display name, as well as any updates to the display name, will be available to other participants in the space, and reflected in any broadcasts created from this space.

The display name must be a string and must not be longer than 64 characters. The display name of a given participant may not be changed more than once every 10 seconds.

Set your display name while joining

For more details, refer to the SDK API documentation.

Before joining, a participant may pass a display name to the created space. This will set their display name immediately at join time.

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)
            .setDisplayName("Bob")
            .build();
} catch (Exception e) {
    e.printStackTrace();
    return;
}

Spaces spaces = Spaces.getInstance(this);
Space space = spaces.getSpace(spaceConfiguration);

space.join(new Space.Listener() {});

...

Update your display name

While connected, a participant can set their display name up to once every 10 seconds.

import com.mux.sdk.webrtc.spaces.LocalParticipant;
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)
            .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 onJoined(Space space, LocalParticipant localParticipant) {
        localParticipant.setDisplayName("Bob");
    }
});

...

Retrieve display names from participants

A participant's display name is always accessible as a field on the participant. If the participant has not set a display name, the string will be empty.

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)
            .setDisplayName("Bob")
            .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) {
      String displayName = remoteParticipant.getDisplayName();
  }

  @Override
  public void onParticipantDisplayNameUpdated(Space space, Participant participant, String displayName) {
      // The displayName is the display name, or:
      String name = participant.getDisplayName();
  }
});

...

Listen for display names changes

Developers can listen to the Space or the participant to be notified of any changes to a participant's display name.

import com.mux.sdk.webrtc.spaces.Participant;
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)
            .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 onParticipantDisplayNameUpdated(Space space, Participant participant, String displayName) {
        // Participant is the affected participant, displayName is their new updated displayName, also retrievable as
        String name = participant.getDisplayName();
    }
});

...

Was this page helpful?