# EasyEvents.cs

### Subscribe To Vivox Events

Subscribe to relevant **Vivox** events in <mark style="color:blue;">**Awake()**</mark> or <mark style="color:blue;">**Start()**</mark> methods. Check out the [**Login Events**](https://fullstackindie.gitbook.io/easy-code-for-vivox/easy-code-for-vivox/how-do-i-do-this-in-easycode/login-logout/login-events) page to see examples on how to use **EasyEvents**

### &#x20;Audio Device **Events**

```csharp
#region Audio Device Events

public event Action<IAudioDevice> AudioInputDeviceAdded;
public event Action<IAudioDevice> AudioInputDeviceRemoved;
public event Action<IAudioDevice> AudioInputDeviceUpdated;

public event Action<IAudioDevice> AudioOutputDeviceAdded;
public event Action<IAudioDevice> AudioOutputDeviceRemoved;
public event Action<IAudioDevice> AudioOutputDeviceUpdated;

#endregion
```

{% tabs %}
{% tab title="Script" %}
Uses **`EasyEvents.cs`** to access **Login** events

You can also access **EasyEvents** by injecting it into your class using Zenject dependency injection. [Read more about it here](https://fullstackindie.gitbook.io/easy-code-for-vivox/dependency-injection/inject-classes#method-injection).
{% endtab %}

{% tab title="Events" %}

<table data-header-hidden><thead><tr><th width="461">Event</th><th>Purpose</th></tr></thead><tbody><tr><td>AudioInputDeviceAdded</td><td>Called when a <strong>new Audio device</strong> is detected (Mic)</td></tr><tr><td>AudioInputDeviceRemoved</td><td>Called when an <strong>Audio device</strong> is removed (Mic)</td></tr><tr><td>AudioInputDeviceUpdated</td><td>Called <strong>after the 2 previous events</strong> and is called when a device is <strong>added, removed, or changed</strong></td></tr><tr><td></td><td></td></tr><tr><td>AudioOutputDeviceAdded</td><td>Called when a <strong>new Audio device</strong> is detected (Speaker / Headphones)</td></tr><tr><td>AudioOutputDeviceRemoved</td><td>Called when an <strong>Audio device</strong> is removed (Speaker / Headphones)</td></tr><tr><td>AudioOutputDeviceUpdated</td><td>Called <strong>after the 2 previous events</strong> and is called when a device is <strong>added, removed, or changed</strong></td></tr></tbody></table>

{% endtab %}

{% tab title="Callback Methods and Parameters" %}

| OnAudioInputDeviceAdded    | **requires (**&#x49;AudioDevice audioDevic&#x65;**)** |
| -------------------------- | ----------------------------------------------------- |
| OnAudioInputDeviceRemoved  | **requires (**&#x49;AudioDevice audioDevic&#x65;**)** |
| OnAudioInputDeviceUpdated  | **requires (**&#x49;AudioDevice audioDevic&#x65;**)** |
|                            |                                                       |
| OnAudioOutputDeviceAdded   | **requires (**&#x49;AudioDevice audioDevic&#x65;**)** |
| OnAudioOutputDeviceRemoved | **requires (**&#x49;AudioDevice audioDevic&#x65;**)** |
| OnAudioOutputDeviceUpdated | **requires (**&#x49;AudioDevice audioDevic&#x65;**)** |
| {% endtab %}               |                                                       |

{% tab title="Use Case" %}
Subscribe to Audio Device events if you want to allow users to change their **Mic / Headphone / Speaker** device settings in game instead of having to exit the game and adjust audio device settings
{% endtab %}
{% endtabs %}

### &#x20; **Login Events**

```csharp
 // Subscribe to Login Related Events
 _events.LoggingIn += OnLoggingIn;
 _events.LoggedIn += OnLoggedIn;
 _events.LoggedIn += OnLoggedInSetup;
 _events.LoggingOut += OnLoggingOut;
 _events.LoggedOut += OnLoggedOut;
 
 _events.LoginAdded += OnLoginAdded;
 _events.LoginRemoved += OnLoginRemoved;
 _events.LoginUpdated += OnLoginUpdated;
```

{% tabs %}
{% tab title="Script" %}
Uses **`EasyEvents.cs`** to access **Login** events

You can also access **EasyEvents** by injecting it into your class using Zenject dependency injection. [Read more about it here](https://fullstackindie.gitbook.io/easy-code-for-vivox/dependency-injection/inject-classes#method-injection).
{% endtab %}

{% tab title="Events" %}

| Event              | Purpose                                                                               |
| ------------------ | ------------------------------------------------------------------------------------- |
| **`LoggingIn`**    | Called when **Vivox** begins logging in a user                                        |
| **`LoggedIn`**     | Called when **Vivox** successfully logs in a user                                     |
| **`LoggingOut`**   | Called locally and immediately when the **`LogoutOfVivox()`** method is called        |
| **`LoggedOut`**    | Called locally and fires after the **`LogoutOfVivox()`** method is called             |
| **`LoginAdded`**   | Called when a new LoginSession is added to Vivox Client - User Logged In              |
| **`LoginRemoved`** | Called when a new LoginSession is removed to Vivox Client - User Logged out           |
| **`LoginUpdated`** | Called when a new LoginSession values are updated in Vivox Client - User Changed Name |
| {% endtab %}       |                                                                                       |

{% tab title="Callback Methods and Parameters" %}

| Callback Method       | Parameters                                  |
| --------------------- | ------------------------------------------- |
| **`OnLoggingIn`**     | **`requires (ILoginSession loginSession)`** |
| **`OnLoggedIn`**      | **`requires (ILoginSession loginSession)`** |
| **`OnLoggedInSetup`** | **`requires (ILoginSession loginSession)`** |
| **`OnLoggingOut`**    | **`requires (ILoginSession loginSession)`** |
| **`OnLoggedOut`**     | **`requires (ILoginSession loginSession)`** |
| **`OnLoginAdded`**    | **`requires (AccountId accountId)`**        |
| **`OnLoginRemoved`**  | **`requires (AccountId accountId)`**        |
| **`OnLoginUpdated`**  | **`requires (ILoginSession loginSession)`** |
| {% endtab %}          |                                             |

{% tab title="Use Case" %}
Subscribe to **Login** events if you want to perform actions based on each level of logging in or out, you want to offer users the ability to have multiple login sessions at 1 time and keep track of them, or simply want to implement a **`Debug.Log`** statement to ensure the player is logged in successfully.
{% endtab %}
{% endtabs %}

###

### **Channel Events**

```csharp
 // Subscribe to Channel Related Events
_events.ChannelConnecting += OnChannelConnecting;
_events.ChannelConnected += OnChannelConnected;
_events.ChannelDisconnecting += OnChannelDisconnecting;
_events.ChannelDisconnected += OnChannelDisconnected;
```

{% tabs %}
{% tab title="Script" %}
Uses **`EasyEvents.cs`** to access **Channel** events

You can also access **EasyEvents** by injecting it into your class using Zenject dependency injection. [Read more about it here](https://fullstackindie.gitbook.io/easy-code-for-vivox/dependency-injection/inject-classes#method-injection).
{% endtab %}

{% tab title="Events" %}

| Event                      | Purpose                                                                                                   |
| -------------------------- | --------------------------------------------------------------------------------------------------------- |
| **`ChannelConnecting`**    | Called when **Vivox** starts connecting a user to a channel. If the channel doesn't exists one is created |
| **`ChannelConnected`**     | Called when **Vivox** successfully connects a user to a channel.                                          |
| **`ChannelDisconnecting`** | Called when **Vivox** starts disconnecting a user from a channel.                                         |
| **`ChannelDisconnected`**  | Called when **Vivox** successfully disconnects a user from a channel.                                     |
| {% endtab %}               |                                                                                                           |

{% tab title="Callback Methods and Parameters" %}

| Callback Method              | Parameters                                      |
| ---------------------------- | ----------------------------------------------- |
| **`OnChannelConnecting`**    | **`requires (IChannelSession channelSession)`** |
| **`OnChannelConnected`**     | **`requires (IChannelSession channelSession)`** |
| **`OnChannelDisconnecting`** | **`requires (IChannelSession channelSession)`** |
| **`OnChannelDisconnected`**  | **`requires (IChannelSession channelSession)`** |
| {% endtab %}                 |                                                 |

{% tab title="Use Case" %}
Subscribe to Channel events if you want to perform actions based on each level of connecting/disconnecting or simply want to implement a **`Debug.Log`** statement to ensure the player is connected to a channel
{% endtab %}
{% endtabs %}

###

### **Audio Channel Events**

```csharp
 // Subscribe to Channel Related Events
_events.AudioChannelConnecting += OnVoiceConnecting;
_events.AudioChannelConnected += OnVoiceConnected;
_events.AudioChannelDisconnecting += OnVoiceDisconnecting;
_events.AudioChannelDisconnected += OnVoiceDisconnected;
```

{% tabs %}
{% tab title="Script" %}
Uses **`EasyEvents.cs`** to access **Audio Channel** events

You can also access **EasyEvents** by injecting it into your class using Zenject dependency injection. [Read more about it here](https://fullstackindie.gitbook.io/easy-code-for-vivox/dependency-injection/inject-classes#method-injection).
{% endtab %}

{% tab title="Events" %}

| Event                           | Purpose                                                                                                    |
| ------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| **`AudioChannelConnecting`**    | Called when **Vivox** starts connecting a user to a voice channel. Channel must exist for voice to connect |
| **`AudioChannelConnected`**     | Called when **Vivox** successfully connects a user to voice a channel.                                     |
| **`AudioChannelDisconnecting`** | Called when **Vivox** starts disconnecting a user from a voice channel.                                    |
| **`AudioChannelDisconnected`**  | Called when **Vivox** successfully disconnects a user from a voice channel.                                |
| {% endtab %}                    |                                                                                                            |

{% tab title="Callback Methods and Parameters" %}

| Callback Method            | Parameters                                      |
| -------------------------- | ----------------------------------------------- |
| **`OnAudioConnecting`**    | **`requires (IChannelSession channelSession)`** |
| **`OnAudioConnected`**     | **`requires (IChannelSession channelSession)`** |
| **`OnAudioDisconnecting`** | **`requires (IChannelSession channelSession)`** |
| **`OnAudioDisconnected`**  | **`requires (IChannelSession channelSession)`** |
| {% endtab %}               |                                                 |

{% tab title="Use Case" %}
Subscribe to Voice Channel events if you want to perform actions based on each level of connecting/disconnecting or simply want to implement a **`Debug.Log`** statement to ensure the player is connected to a voice channel
{% endtab %}
{% endtabs %}

###

### **Text Channel Events**

```csharp
 // Subscribe to Channel Related Events
 _events.TextChannelConnecting += OnTextChannelConnecting;
 _events.TextChannelConnected += OnTextChannelConnected;
 _events.TextChannelDisconnecting += OnTextChannelDisconnecting;
 _events.TextChannelDisconnected += OnTextChannelDisconnected;
```

{% tabs %}
{% tab title="Script" %}
Uses **`EasyEvents.cs`** to access **Text Channel** events

You can also access **EasyEvents** by injecting it into your class using Zenject dependency injection. [Read more about it here](https://fullstackindie.gitbook.io/easy-code-for-vivox/dependency-injection/inject-classes#method-injection).
{% endtab %}

{% tab title="Events" %}

| Event                          | Purpose                                                                                             |
| ------------------------------ | --------------------------------------------------------------------------------------------------- |
| **`TextChannelConnecting`**    | Called when **Vivox** starts connecting a user to a channel. Channel must exist for text to connect |
| **`TextChannelConnected`**     | Called when **Vivox** successfully connects a user to a text channel.                               |
| **`TextChannelDisconnecting`** | Called when **Vivox** starts disconnecting a user from a text channel.                              |
| **`TextChannelDisconnected`**  | Called when **Vivox** successfully disconnects a user from a text channel.                          |
| {% endtab %}                   |                                                                                                     |

{% tab title="Callback Methods and Parameters" %}

| Callback Method                  | Parameters                                      |
| -------------------------------- | ----------------------------------------------- |
| **`OnTextChannelConnecting`**    | **`requires (IChannelSession channelSession)`** |
| **`OnTextChannelConnected`**     | **`requires (IChannelSession channelSession)`** |
| **`OnTextChannelDisconnecting`** | **`requires (IChannelSession channelSession)`** |
| **`OnTextChannelDisconnected`**  | **`requires (IChannelSession channelSession)`** |
| {% endtab %}                     |                                                 |

{% tab title="Use Case" %}
Subscribe to Text Channel events if you want to perform actions based on each level of connecting/disconnecting or simply want to implement a **`Debug.Log`** statement to ensure the player is connected to a text channel
{% endtab %}
{% endtabs %}

###

### Message Events

```csharp
 // Subscribe to Channel Message Related Events
_events.ChannelMessageRecieved += OnChannelMessageRecieved;
_events.EventMessageRecieved += OnEventMessageRecieved;

 // Subscribe to Direct Message Related Events
 _events.DirectMessageRecieved += OnDirectMessageRecieved;
 _events.DirectMessageFailed += OnDirectMessageFailed;
```

{% tabs %}
{% tab title="Script" %}
Uses **`EasyEvents.cs`** to access **Channel and Direct message** events

You can also access **EasyEvents** by injecting it into your class using Zenject dependency injection. [Read more about it here](https://fullstackindie.gitbook.io/easy-code-for-vivox/dependency-injection/inject-classes#method-injection).
{% endtab %}

{% tab title="Events" %}

| Event                        | Purpose                                                                                               |
| ---------------------------- | ----------------------------------------------------------------------------------------------------- |
| **`ChannelMessageRecieved`** | Called when a channel message is received. The message is passed to the method parameter              |
| **`EventMessageRecieved`**   | Called when a channel event/hidden message is received. The message is passed to the method parameter |
| **`DirectMessageRecieved`**  | Called when a direct message is received. The message is passed to the method parameter               |
| **`DirectMessageFailed`**    | Called when a message has failed to send. The message is passed to the method parameter               |
| {% endtab %}                 |                                                                                                       |

{% tab title="Callback Methods and Parameters" %}

| Callback Methods               | Parameters                                                |
| ------------------------------ | --------------------------------------------------------- |
| **`OnChannelMessageRecieved`** | **`requires (IChannelTextMessage textMessage)`**          |
| **`OnEventMessageRecieved`**   | **`requires (IChannelTextMessage textMessage)`**          |
| **`OnDirectMessageRecieved`**  | **`requires (IDirectedTextMessage directedTextMessage)`** |
| **`OnDirectMessageFailed`**    | **`requires (IFailedDirectedTextMessage failedMessage)`** |
| {% endtab %}                   |                                                           |

{% tab title="Use Case" %}
These Message events are necessary to receive **channel, event/hidden, or direct** messages. **Event/Hidden** messages can be used if you (very useful if you are not using a Networking Stack) want to pass info to players in the channel. When a message fails to send you can use the **OnDirectMessageFailed** callback to store the message or try and resend it.
{% endtab %}
{% endtabs %}

###

### User Events

The keywords **Fire** and **Called** are used interchangeably

```csharp
_events.UserJoinedChannel += OnUserJoinedChannel;
_events.UserLeftChannel += OnUserLeftChannel;
_events.UserValuesUpdated += OnUserValuesUpdated;
```

{% tabs %}
{% tab title="Script" %}
Uses **`EasyEvents.cs`** to access **User** events

You can also access **EasyEvents** by injecting it into your class using Zenject dependency injection. [Read more about it here](https://fullstackindie.gitbook.io/easy-code-for-vivox/dependency-injection/inject-classes#method-injection).
{% endtab %}

{% tab title="Events" %}

| Event                   | Purpose                                                                                                                                                                                                                                                  |
| ----------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`UserJoinedChannel`** | Called when a user joins a channel. This event will fire for every user that is in the same channel                                                                                                                                                      |
| **`UserLeftChannel`**   | Called when a user leaves a channel. This event will fire for every user that is in the same channel                                                                                                                                                     |
| **`UserValuesUpdated`** | Called when a user values are updated in a channel such as speaking, muted, name change. This event will fire for every user that is in the same channel. This event is called many times by Vivox implement at your own peril :grimacing: . You can set |
| {% endtab %}            |                                                                                                                                                                                                                                                          |

{% tab title="Callback Methods and Parameters" %}

| Callback Methods                | Parameters                                |
| ------------------------------- | ----------------------------------------- |
| **`OnParticipantAdded`**        | **`requires (IParticipant participant)`** |
| **`OnParticipantRemoved`**      | **`requires (IParticipant participant)`** |
| **`OnParticipantValueUpdated`** | **`requires (IParticipant participant)`** |
| {% endtab %}                    |                                           |

{% tab title="Use Case" %}
If you want to know if a user has joined or left a channel
{% endtab %}
{% endtabs %}

```csharp
_events.UserMuted -= OnUserMuted;
_events.UserUnmuted -= OnUserUnmuted;
_events.UserSpeaking -= OnUserSpeaking;
_events.UserNotSpeaking -= OnUserNotSpeaking;
_events.LocalUserMuted -= OnLocalUserMuted;
_events.LocalUserUnmuted -= OnLocalUserUnmuted;
_events.UserCrossMuted -= OnCrossMuted;
_events.UserCrossUnmuted -= OnCrossUnmuted;
```

{% tabs %}
{% tab title="Script" %}
Uses **`EasyEvents.cs`** to access **User** events

You can also access **EasyEvents** by injecting it into your class using Zenject dependency injection. [Read more about it here](https://fullstackindie.gitbook.io/easy-code-for-vivox/dependency-injection/inject-classes#method-injection).
{% endtab %}

{% tab title="Events" %}

| Event                  | Purpose                                                                                                                                   |
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| **`UserMuted`**        | Called when a user is muted                                                                                                               |
| **`UserUnmuted`**      | Called when a user is unmuted                                                                                                             |
| **`UserSpeaking`**     | Called when a user is speaking                                                                                                            |
| **`UserNotSpeaking`**  | Called when a user is no longer speaking                                                                                                  |
| **`LocalUserMuted`**   | Called when local user is muted                                                                                                           |
| **`LocalUserUnmuted`** | Called when local user is unmuted                                                                                                         |
| **`UserCrossMuted`**   | Called when user has been Cross Muted , this action prevents the AccountId from sending or receiving voice or text communications.        |
| **`UserCrossUnmuted`** | Called when user has been Cross Unmuted , this action resumes/allows the AccountId to send or receive ausio/voice or text communications. |
| {% endtab %}           |                                                                                                                                           |

{% tab title="Callback Methods and Parameters" %}

| Callback Method         | Parameters                                |
| ----------------------- | ----------------------------------------- |
| **`OnUserMuted`**       | **`requires (IParticipant participant)`** |
| **`OnUserUnmuted`**     | **`requires (IParticipant participant)`** |
| **`OnUserSpeaking`**    | **`requires (IParticipant participant)`** |
| **`OnUserNotSpeaking`** | **`requires (IParticipant participant)`** |
| {% endtab %}            |                                           |

{% tab title="Use Case" %}
If you want to know if a player is speaking or muted to update your UI with a different image for each event.
{% endtab %}
{% endtabs %}

### Text To Speech ( TTS ) Events

```csharp
 // Subscribe to Text-To-Speech related events
 _events.TTSMessageAdded += OnTTSMessageAdded;
 _events.TTSMessageRemoved += OnTTSMessageRemoved;
 _events.TTSMessageUpdated += OnTTSMessageUpdated;
```

{% tabs %}
{% tab title="Script" %}
Uses **`EasyEvents.cs`** to access **Text-To-Speech** events

You can also access **EasyEvents** by injecting it into your class using Zenject dependency injection. [Read more about it here](https://fullstackindie.gitbook.io/easy-code-for-vivox/dependency-injection/inject-classes#method-injection).
{% endtab %}

{% tab title="Events" %}

| Event                   | Purpose                                                                                           |
| ----------------------- | ------------------------------------------------------------------------------------------------- |
| **`TTSMessageAdded`**   | Called when a message is spoken or added to the TTS queue.                                        |
| **`TTSMessageRemoved`** | Called when a message is removed from the TTS queue.                                              |
| **`TTSMessageUpdated`** | Called when a message is spoken, overridden, removed, added to the TTS queue or TTS voice changed |
| {% endtab %}            |                                                                                                   |

{% tab title="Callback Methods and Parameters" %}

|                           |                                                    |
| ------------------------- | -------------------------------------------------- |
| **`OnTTSMessageAdded`**   | **`requires (ITTSMessageQueueEventArgs ttsArgs)`** |
| **`OnTTSMessageRemoved`** | **`requires (ITTSMessageQueueEventArgs ttsArgs)`** |
| **`OnTTSMessageUpdated`** | **`requires (ITTSMessageQueueEventArgs ttsArgs)`** |
| {% endtab %}              |                                                    |

{% tab title="Use Case" %}
If you want to keep a log of all messages sent thru TTS for accessibility reasons or send notifications to the user using TTS when their message is done playing or wants to send message after hearing it first
{% endtab %}
{% endtabs %}

### **Unsubscribe From Vivox Events**

**Make sure to** unsubscribe from all the events explained above on **`OnApplicationQuit()`** in **Unity**
