Audio Channel Events
Inherit from EasyManager.cs
using EasyCodeForVivox;
public class VivoxManager : EasyManager
{
}
Inject EasyEvents
using EasyCodeForVivox.Events;
using UnityEngine;
using Zenject;
public class VivoxEvents : MonoBehaviour
{
EasyEvents _events;
[Inject]
private void Initialize(EasyEvents events)
{
_events = events;
}
}
Dynamic Events
Make sure Dynamic Events are enabled
How to Subscribe to Audio Channel Events in EasyCode
EasyManager
Keeping the base methods are not necessary. They are simply Debug.Logs(). Feel free to delete them
// Voice Channel Event Callbacks
protected override void OnAudioChannelConnecting(IChannelSession channelSession)
{
base.OnAudioChannelConnecting(channelSession);
}
protected override void OnAudioChannelConnected(IChannelSession channelSession)
{
base.OnAudioChannelConnected(channelSession);
}
protected override void OnAudioChannelDisconnecting(IChannelSession channelSession)
{
base.OnAudioChannelDisconnecting(channelSession);
}
protected override void OnAudioChannelDisconnected(IChannelSession channelSession)
{
base.OnAudioChannelDisconnected(channelSession);
}
EasyEvents
public void SubscribeToAudioChannelEvents()
{
_events.AudioChannelConnecting += OnAudioChannelConnecting;
_events.AudioChannelConnected += OnAudioChannelConnected;
_events.AudioChannelDisconnecting += OnAudioChannelDisconnecting;
_events.AudioChannelDisconnected += OnAudioChannelDisconnected;
}
public void UnsubscribeToAudioChannelEvents()
{
_events.AudioChannelConnecting -= OnAudioChannelConnecting;
_events.AudioChannelConnected -= OnAudioChannelConnected;
_events.AudioChannelDisconnecting -= OnAudioChannelDisconnecting;
_events.AudioChannelDisconnected -= OnAudioChannelDisconnected;
}
protected virtual void OnAudioChannelConnecting(IChannelSession channelSession)
{
Debug.Log($"{channelSession.Channel.Name} Audio Is Connecting In Channel");
}
protected virtual void OnAudioChannelConnected(IChannelSession channelSession)
{
Debug.Log($"{channelSession.Channel.Name} Audio Has Connected In Channel");
}
protected virtual void OnAudioChannelDisconnecting(IChannelSession channelSession)
{
Debug.Log($"{channelSession.Channel.Name} Audio Is Disconnecting In Channel");
}
protected virtual void OnAudioChannelDisconnected(IChannelSession channelSession)
{
Debug.Log($"{channelSession.Channel.Name} Audio Has Disconnected In Channel");
}
Dynamic Events
[AudioChannelEvent(AudioChannelStatus.AudioChannelConnecting)]
private void OnAudioChannelConnecting(IChannelSession channelSession)
{
Debug.Log($"{channelSession.Channel.Name} Is Connecting");
}
[AudioChannelEvent(AudioChannelStatus.AudioChannelConnected)]
private void OnAudioChannelConnected(IChannelSession channelSession)
{
Debug.Log($"{channelSession.Channel.Name} Has Connected : Channel Type == {channelSession.Channel.Type}");
}
[AudioChannelEvent(AudioChannelStatus.AudioChannelDisconnecting)]
private void OnAudioChannelDisconnecting(IChannelSession channelSession)
{
Debug.Log($"{channelSession.Channel.Name} Is Disconnecting");
}
[AudioChannelEvent(AudioChannelStatus.AudioChannelDisconnected)]
private void OnAudioChannelDisconnected(IChannelSession channelSession)
{
Debug.Log($"{channelSession.Channel.Name} Has Disconnected");
}
Dynamic Async Events
Remember to use async void or async Task or else the event may run synchronously
[AudioChannelEventAsync(AudioChannelStatus.AudioChannelConnecting)]
private async void OnAudioChannelConnectingAsync(IChannelSession channelSession)
{
Debug.Log($"{channelSession.Channel.Name} Is Connecting");
await LoadPlayerData();
}
[AudioChannelEventAsync(AudioChannelStatus.AudioChannelConnected)]
private async void OnAudioChannelConnectedAsync(IChannelSession channelSession)
{
Debug.Log($"{channelSession.Channel.Name} Has Connected : Channel Type == {channelSession.Channel.Type}");
await GetJoinedLobbies();
}
[AudioChannelEventAsync(AudioChannelStatus.AudioChannelDisconnecting)]
private async void OnAudioChannelDisconnectingAsync(IChannelSession channelSession)
{
Debug.Log($"{channelSession.Channel.Name} Is Disconnecting");
await SavePlayerData();
}
[AudioChannelEventAsync(AudioChannelStatus.AudioChannelDisconnected)]
private async void OnAudioChannelDisconnectedAsync(IChannelSession channelSession)
{
Debug.Log($"{channelSession.Channel.Name} Has Disconnected");
await RemovePlayerFromLobby();
}
Last updated
Was this helpful?