Skip to main content

VivoxClient

A class in Root.Township, Alta.Voice.

Wrapper around the Vivox voice and text chat client: login, audio devices, channels and muting. Client only; one is made by VivoxManager and reached through VivoxManager.Instance.Client.

Constructors​

MemberWhat it is
VivoxClient()Creates a VivoxClient with default values.

Fields​

MemberWhat it is
ILoginSession loginSessionThe Vivox login session, or null when logged out.
8 private and internal fields
MemberWhat it is
private AccountId accountThe Vivox account id for the logged-in user, built from the user id and display name. Null when logged out.
private readonly Dictionary<string, VivoxSession> channelsJoined channel sessions, keyed by channel name.
private Client clientThe underlying Vivox SDK client, created in the constructor and cleared by Terminate.
private bool isIntendedMuteWhether the player wants the mic muted, flipped by ToggleMute. Restored when a mod mute is lifted.
private bool isMutedByModsWhether moderators have muted this player's mic, set by SetModsMute. While true, ToggleMute does not unmute.
private static Logger loggerNLog logger for this class.
private IVivoxVoiceUpdatable positionalChatThe voice session of the last joined voice-enabled channel; its 3D position is updated each Update.
private static StringBuilder stringBuilderShared builder used for login and device log messages.

Properties​

MemberWhat it is
IAudioDevice ActiveInputDevice { get; }The microphone chosen in Vivox.
IAudioDevice ActiveOutputDevice { get; }The speaker or headset chosen in Vivox.
IAudioDevice EffectiveInputDevice { get; }The microphone Vivox is actually using.
IAudioDevice EffectiveOutputDevice { get; }The output device Vivox is actually using.
IEnumerable<IAudioDevice> InputDevices { get; }Available microphones.
bool IsLoggedIn { get; private set; }Whether login succeeded and no logout has happened since.
bool IsMicMuted { get; }Whether the microphone is muted.
IEnumerable<IAudioDevice> OutputDevices { get; }Available output devices.

Events​

MemberWhat it is
event Action ChannelJoinedRaised after a channel is joined.
event Action LoginFailedRaised when the login attempt fails.
event Action LoginSucceededRaised when login succeeds.
event Action<IParticipant> PlayerJoinedChannelRaised when a participant in a channel is paired with a player.

Methods​

MemberWhat it is
void JoinChannel(VivoxChannel channel, Action<VivoxText> textCreated, Action<VivoxVoice> voiceCreated)Joins a channel and calls back when its text or voice part connects. A voice channel becomes the positional one.
void LeaveChannel(VivoxChannel channel)Leaves a joined channel and removes its session.
async Task<bool> Login(int userId, string displayName)Logs in to Vivox for a user id and display name, then refreshes devices. Logging in twice logs an error and returns true.
void Logout()Logs out and clears the session.
async Task<bool> RefreshDevices()Refreshes the input and output device lists; true if both worked.
async Task<bool> SetInputDevice(IAudioDevice device)Chooses the microphone.
void SetModsMute(bool isMutedByMods)Mutes the mic while moderators require it, then restores the player's own mute choice.
void SetMuted(bool isMuted)Mutes or unmutes your mic; with a user id, mutes that user in every joined channel.
void SetMuted(int userId, bool isMuted)Mutes or unmutes your mic; with a user id, mutes that user in every joined channel.
async Task<bool> SetOutputDevice(IAudioDevice device)Chooses the output device.
void Terminate()Shuts the Vivox client down.
void ToggleMute()Flips the player's chosen mute; it only takes effect if moderators aren't muting them.
void Update()Runs Vivox once and updates the positional voice position. Call every frame.
4 private and internal methods
MemberWhat it is
private void HandleSessionStateChanged()Runs when the Vivox login state changes; on logged out it calls Logout and logs back in through VivoxManager if the game login is still active.
private void LogDeviceInfo()Logs the available, active and effective audio input and output devices. Called after login.
private void OnPlayerPaired(IParticipant player)Passes a session's PlayerPaired event on as PlayerJoinedChannel.
private void SessionPropertyChanged(object sender, PropertyChangedEventArgs e)Handler for the login session's PropertyChanged; logs the change and calls HandleSessionStateChanged when State changes.

Used in​

Members of other types that take, return or hold a VivoxClient: