Important: This is documentation for the legacy version of the Vivox Unity SDK. This documentation will be removed after July 2025. Refer to the v16 documentation for the new version of the SDK.
Mute other users for a specific user
You can mute other users for a specific user by using a local mute. The LocalMute
function prevents a user from hearing a muted user, but other users in the channel continue to hear the muted user.
For example, Cynthia, Fernando, and Wang are in a channel. Fernando does not want to hear Wang’s audio. By using a local mute, you can allow Fernando to stop hearing Wang’s audio. However, Cynthia continues to hear Wang, and Wang continues to hear Cynthia and Fernando.
The following examples detail the implementation for a user who is locally muting another user in the same channel.
. . .
public void MuteOtherUser(string username)
{
IChannelSession currentChannelSession = loginSession.GetChannelSession(currentChannelID);
string constructedParticipantKey = "sip:." + Issuer + "." + username + ".@" + Domain;
var participants = currentChannelSession.Participants;
if (participants[constructedParticipantKey].InAudio)
{
if (participants[constructedParticipantKey].LocalMute == false)
{
participants[constructedParticipantKey].LocalMute = true;
}
else
{
participants[constructedParticipantKey].LocalMute = false;
}
}
else
{
//Tell Player To Try Again
Debug.Log("Try Again");
}
}
Note: If you want to update a UI element to indicate which users a user has muted, you need to wait until you receive an event from the Vivox SDK to confirm that the other users have actually been muted.
private void OnParticipantValueUpdated(object sender, ValueEventArg<string, IParticipant> valueEventArg)
{
ValidateArgs(new object[] { sender, valueEventArg });
var source = (VivoxUnity.IReadOnlyDictionary<string, IParticipant>)sender;
var participant = source[valueEventArg.Key];
string username = valueEventArg.Value.Account.Name;
ChannelId channel = valueEventArg.Value.ParentChannelSession.Key;
string property = valueEventArg.PropertyName;
switch (property)
{
case "LocalMute":
{
if (username != accountId.Name)
{
//UPDATE UI HERE
}
break;
}
default:
break;
}
}
private static void ValidateArgs(object[] objs)
{
foreach (var obj in objs)
{
if (obj == null)
throw new ArgumentNullException(obj.GetType().ToString(), "Specify a non-null/non-empty argument.");
}
}