Easy Code For Vivox
  • Introduction
    • Official Links
    • Getting Started
      • Wheres The Code
      • Setup EasyCode in My Project
    • Setup Demo Scenes
      • Vivox Developer Portal
      • Unity Gaming Services (UGS) Dashboard
    • Things To Consider
    • FAQ
  • Development Info
    • Design Decisions
    • Release Notes
      • v2.0
      • v1.3
      • v1.2
      • v1.1
      • Template
    • Not Supported
  • Easy Code For Vivox
    • How do I setup EasyCode?
      • Setup Your Credentials
    • How do I do this in EasyCode?
      • Login / Logout
        • Login Properties
        • SetTransmissionMode
        • Login Events
      • Join / Leave Channel
        • Audio Channel
          • Audio Channel Events
        • Text Channel
          • Text Channel Events
        • Channel Events
      • Send Messages
        • Message Events
      • Mute / Unmute
        • Mute / Unmute Events
      • Subscribe to User Events
      • Volume / Audio Settings
        • Audio Device Events
      • Text To Speech ( TTS )
        • TTS Events
    • Vivox Access Tokens
      • Unity Cloud Code
    • Supported Vivox Events
      • Callback Methods
    • Folder Structure / Info
      • / Demo Scenes /
      • / Documentation /
      • / Examples /
      • / Plugins /
      • / Resources /
      • / Scripts /
      • / Settings /
    • Common Errors
  • API Info
    • EasySession.cs
    • EasyManager.cs
      • Main Methods
      • Vivox Event Callbacks
    • Easy3DPositional.cs
    • EasyVivoxUtilities.cs
    • EasySettings.cs
    • Extension Methods
      • EasySIPExtensions.cs
      • GameObjectExtensions.cs
      • TTSMessageExtensions.cs
      • UIExtensions.cs
      • VivoxExtensions.cs
      • EasyDebug.cs
    • EasyEvents.cs
  • Dependency Injection
    • Zenject vs Extenject
    • Install Dependencies
    • Inject Classes
  • Dynamic Events
    • Dynamic Events
    • Tests
    • Gotchas
    • Dynamic Async Events
      • Dont Do
    • Event Examples
  • Related Info
    • How do I do this in Vivox?
      • Conference Chat
    • Pre-Processor Directives
    • How to set iOS Info.plist for Unity?
    • Unity Gaming Services
  • The Future
    • Roadmap
    • Todo / Notes / Changelog
Powered by GitBook
On this page
  • Inherit from EasyManager.cs
  • Inject EasyEvents
  • Dynamic Events
  • How to Subscribe to Audio Channel Events in EasyCode

Was this helpful?

  1. Easy Code For Vivox
  2. How do I do this in EasyCode?
  3. Join / Leave Channel
  4. Audio Channel

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();
}
PreviousAudio ChannelNextText Channel

Last updated 2 years ago

Was this helpful?

Make sure the parameter in your method matches the event type. See what parameter is required for each . Dynamic events will dynamically invoke your method at runtime on every game object that has a dynamic event attribute. Because of this there is no need to Subscribe/Unsubscribe from events with the usual +=/-=

Make sure the parameter in your method matches the event type. See what parameter is required for each . Dynamic events will dynamically invoke your method at runtime on every game object that has a dynamic event attribute. Because of this there is no need to Subscribe/Unsubscribe from events with the usual +=/-=

More information on the methods called in any async method can be found here. . They are direct copies from Unity's docs. These are just examples and don't mimic real world use cases

Unity Gaming Services Examples
AudioChannel Event here
AudioChannel Event here