# Main Methods

### Work In Progress

### Main methods in EasyManager.cs you will be calling from derived class or referenced using GetComponent<> covered here

Another preprocessor directive but this is used by your **IDE** (Integrated Development Environment) \[such as VS Code, VS 2022, Rider] of choice to help separate code functionality in long scripts

```csharp
 #region Main Vivox Methods For Implementing In UI or call from code
```

### Login / Logout

{% tabs %}
{% tab title="Login" %}
Logs into Vivox if the username is valid(EasyCode validates username) and no one else currently logged In has the same name, *Developer is responsible for checking/implementing this*. Takes string username as a parameter. Sets the transmission mode to all so any Voice or Text chat automatically switches to a new channel whenever a channel is joined or switched.

```csharp
public void LoginToVivox(string userName, bool joinMuted = false)
{
    _login.LoginToVivox(userName, joinMuted);
}
```

{% endtab %}

{% tab title="Logout" %}
Logout of current Vivox login session.

```csharp
public void LogoutOfVivox(string userName)
{
    _login.Logout(userName);
}
```

{% endtab %}

{% tab title="Update Login Properties" %}
Updates the current logged in user's frequency for state changes when user is using Audio/Voice channels. If user isn't logged in then set the **VivoxParticipantPropertyUpdateFrequency** in **EasySettings**

```csharp
public void UpdateLoginProperties(string userName, ParticipantPropertyUpdateFrequency updateFrequency)
{
    _login.UpdateLoginProperties(EasySession.LoginSessions[userName], updateFrequency);
}
```

{% endtab %}
{% endtabs %}

### Join Channel

**Development Code**

{% tabs %}
{% tab title="Echo" %}
Join an Echo channel. Used mainly to test microphone input and speaker output. Will echo back what you speak in the mic onto your device. **Development Code**

```csharp
 public void VivoxJoinChannelEcho(string channelName, bool includeVoice, bool includeText, bool switchToThisChannel)
 {
     if (FilterChannelAndUserName(channelName))
     {
     JoinChannelEcho(channelName, includeVoice, includeText, switchToThisChannel);
     }
 }
```

{% endtab %}

{% tab title="Non Positional" %}
Join a Non-Positional channel. Similar to talking on the phone. **Development Code**

```csharp
 public void VivoxJoinChannel(string channelName, bool includeVoice, bool includeText, bool switchToThisChannel)
 {
     if (FilterChannelAndUserName(channelName))
     {
         JoinChannel(channelName, includeVoice, includeText, switchToThisChannel);
     }
 }
```

{% endtab %}

{% tab title="3D Positional" %}
Join a 3D Positional Channel. This channel is created with the recommended default 3D audio settings. Based on the settings you will only hear voice chat or receive text messages in the channel based on how close you are to other players in the same channel as you. If 2 players are close you can hear each other clearly but the farther you get away from each other the audio will fade out based on the chosen settings. More in Vivox Documentation. **Development Code**

```csharp
 public void VivoxJoin3DPositional(string channelName, bool includeVoice, bool includeText, bool switchToThisChannel)
 {
     this.DebugLog($"{mainLoginSession.Presence.Status} {mainLoginSession.Presence.Message}");
     Channel3DProperties channel3DProperties = new Channel3DProperties();
     JoinChannel3DPositional(channelName, includeVoice, includeText, switchToThisChannel, channel3DProperties);
 }
```

{% endtab %}

{% tab title="3D Positional" %}
Join a 3D Positional Channel. This channel is created with 3D audio settings based on the parameter inputs you choose. Based on the settings you will only hear voice chat or receive text messages in the channel based on how close you are to other players in the same channel as you. If 2 players are close you can hear each other clearly but the farther you get away from each other the audio will fade out based on the chosen settings. More in Vivox Documentation. **Development Code**

```csharp
 public void VivoxJoin3DPositional(string channelName, bool includeVoice, bool includeText, bool switchToThisChannel,
 int maxHearingDistance, int minHearingDistance, float voiceFadeOutOverDistance, AudioFadeModel audioFadeModel)
 {
     this.DebugLog($"{mainLoginSession.Presence.Status} {mainLoginSession.Presence.Message}");
     Channel3DProperties channel3DProperties = new Channel3DProperties(maxHearingDistance, minHearingDistance, voiceFadeOutOverDistance, audioFadeModel);
     JoinChannel3DPositional(channelName, includeVoice, includeText, switchToThisChannel, channel3DProperties);
 }
```

{% endtab %}
{% endtabs %}

**Production Code**

{% tabs %}
{% tab title="Join Non Positional" %}
Join a Non-Positional channel. Similar to talking on the phone. **Production Code**.

```csharp
public void VivoxJoinChannelProductionNonPositional(string channelName, bool includeVoice, bool includeText, bool switchToThisChannel, bool joinMuted = false)
 {
     if (FilterChannelAndUserName(channelName))
     {
         JoinChannelProduction(channelName, includeVoice, includeText, switchToThisChannel, joinMuted);
     }
 }
```

{% endtab %}

{% tab title="Join Echo" %}
Join an Echo channel. Used mainly to test microphone input and speaker output. Will echo back what you speak in the mic onto your device. **Production Code**

```csharp
 public void VivoxJoinChannelProductionEcho(string channelName, bool includeVoice, bool includeText, bool switchToThisChannel, bool joinMuted = false)
 {
     if (FilterChannelAndUserName(channelName))
     {
         JoinChannelProductionEcho(channelName, includeVoice, includeText, switchToThisChannel, joinMuted);
     }
 }
```

{% endtab %}

{% tab title="Join 3D Positional" %}
Join a 3D Positional Channel. This channel is created with 3D audio settings. Based on the settings you will only hear voice chat or receive text messages in the channel based on how close you are to other players in the same channel as you. If 2 players are close you can hear each other clearly but the farther you get away from each other the audio will fade out based on the chosen settings. More in Vivox Documentation. **Production Code**

```csharp
 public void VivoxJoinChannelProduction3DPositional(string channelName, bool includeVoice, bool includeText, bool switchToThisChannel,
 Channel3DProperties channel3DProperties = null, bool joinMuted = false)
 {
     if (FilterChannelAndUserName(channelName))
     {
         JoinChannelProduction3DPositional(channelName, includeVoice, includeText, switchToThisChannel, channel3DProperties, joinMuted);
     }
 }
```

{% endtab %}

{% tab title="Join 3D Positional MMO" %}
Join a 3D Positional Channel. This channel is created with 3D audio settings. Based on the settings you will only hear voice chat or receive text messages in the channel based on how close you are to other players in the same channel as you. If 2 players are close you can hear each other clearly but the farther you get away from each other the audio will fade out based on the chosen settings.

* This Method is designed for MMO games where you will have different players in different regions. To have all the players in a region on the same server/shard the region parameter will add the region name to the player SIP address. Recommended to hash the channel name for all players in the channel.
* You must use the private bool FilterChannelAndUserName(string nameToFilter) to filter the channel name before hashing. This method doesn't do it for you in the event your channel name is hashed
* You can also add a squad name to better keep track of all the channels in the Vivox server/shard. Can be null
* Region and squad name are appeneded to the channel name in this format $"{region}.{channelNameOrHash}.{squadName}";

  or

  $"region.channelName.squad1";

  If region or squad name is null then use this format

  $"channelNameOrHash.squadName";

  or

  $"region.channelNameOrHash";

&#x20;More in Vivox Documentation. **Production Code**

```csharp
 public void VivoxJoinChannelProduction3DPositionalMMO(bool includeVoice, bool includeText, bool switchToThisChannel,
 string region, string channelNameOrHash, string squadName, Channel3DProperties channel3DProperties = null, bool joinMuted = false)
 {
 if (FilterChannelAndUserName(channelNameOrHash))
 {
 JoinChannelProduction3DPositionalMMO(includeVoice, includeText, switchToThisChannel, region, channelNameOrHash, squadName, channel3DProperties, joinMuted);
 }
 }
```

{% endtab %}
{% endtabs %}

Leave a channel by providing the channel name. If using the MMO method public void VivoxJoinChannelProduction3DPositionalMMO() then you should pass channel name should be in this format

```csharp
 public void VivoxLeaveChannel(string channelname)
 {
     LeaveChannel(channelname);
 }
```

### Toggle Voice / Text

{% tabs %}
{% tab title="Toggle Voice" %}
Toggle Voice Chat on or off in a channel. Must be connected to a channel or you will receive an error

```csharp
 public void VivoxToggleVoiceInChannel(string channelName, bool toggleOn)
 {
     SetVoiceActiveInChannel(channelName, toggleOn);
 }
```

{% endtab %}

{% tab title="Toggle Text" %}
Toggle Text Chat on or off in a channel. Must be connected to a channel or you will receive an error

```csharp
 public void VivoxToggleTextInChannel(string channelName, bool toggleOn)
 {
     SetTextActiveInChannel(channelName, toggleOn);
 }
```

{% endtab %}
{% endtabs %}

### Send Messages

{% tabs %}
{% tab title="Send Channel Message" %}
Send messages in a Text Channel. Must be connected to an active Text channel. Provide channel name and message. You can also provide secret messages that only the developer can see unless you wish your players to see these messages. In the **Vivox Documentation** this is referred to as **applicationStanzaNamespace** and **applicationStanzaBody**

```csharp
 public void VivoxSendChannelMessage(string channelName, string msg, string commandNameSpace = null, string commandBody = null)
 {
     SendChannelMessage(channelName, msg, commandNameSpace, commandBody);
 }
```

{% endtab %}

{% tab title="Send Direct Message" %}
Send *direct messages* to a logged in user. Both players must be connected to Vivox servers or the message will fail. Provide user name of player to send message to and message. You can also provide secret messages that only the developer can see unless you wish your players to see these messages. In the **Vivox Documentation** this is referred to as **applicationStanzaNamespace** and **applicationStanzaBody**

```csharp
 public void VivoxSendDirectMessage(string userToMsg, string msg, string commandNameSpace = null, string commandBody = null)
 {
     SendDirectMessage(userToMsg, msg, commandNameSpace, commandBody);
 }
```

{% endtab %}
{% endtabs %}

### Toggle Mute

{% tabs %}
{% tab title="Toggle Mute" %}
Toggle the local players audio on or off. This will stop Vivox from transmitting any audio to any channels the user is connected to.

```csharp
 public void VivoxToggleMuteSelf(bool mute)
 {
     ToggleMuteSelf(mute);
 }
```

{% endtab %}

{% tab title="Toggle Mute Remote User" %}
Toggle any remote players audio on or off. This will block any audio that the muted player is speaking in the channel in which they were blocked. Only mutes them for the local user, not everyone in the channel.

```csharp
 public void VivoxToggleMuteUser(string userName, string channelName)
 {
     ToggleMuteRemoteUser(userName, channelName);
 }
```

{% endtab %}
{% endtabs %}

### Volume Adjustment

{% tabs %}
{% tab title="Adjust Volume" %}
Adjust the Voice volume of local player/user on the machine

```csharp
 public void VivoxAdjustLocalUserVoiceVolume(int volume)
 {
     AdjustLocalUserVolume(volume);
 }
```

{% endtab %}

{% tab title="Adjust Remote Volume" %}
Adjust the Voice volume of remote players/users

```csharp
 public void VivoxAdjustRemoteUserVolume(string userName, string channelName, float volume)
 {
     AdjustRemoteUserVolume(userName, channelName, volume);
 }
```

{% endtab %}
{% endtabs %}

### Text To Speech  ( TTS )

{% tabs %}
{% tab title="TTS Local" %}
Speak any text locally \[TTS = Text-To-Speech] Will not send over the Vivox network

```csharp
 public void VivoxTTSSpeakMsgLocal(string msgToSpeak)
 {
     SpeakTTS(msgToSpeak);
 }
```

{% endtab %}

{% tab title="TTS Choose Mode" %}
Speak any text locally, remotely, or both with options to Queue messages or override old messages when a new message is played. **`TTSDestination`** will give you the options to play TTS accordingly

```csharp
 public void VivoxTTSSpeakMsg(string msgToSpeak, TTSDestination playMode)
 {
     SpeakTTS(msgToSpeak, playMode);
 }
```

{% endtab %}
{% endtabs %}

This method allows you to choose male or female voice

{% hint style="warning" %}
(**\*\***&#x49;f your a Christian the male voice doesn’t pronounce Jesus’s name correctly so I recommend using the female voice or you can provide your players with the option to choose)
{% endhint %}

```csharp
 public void VivoxChooseTTSVoiceGender(VoiceGender voiceGender)
 {
     ChooseVoiceGender(voiceGender);
 }
```

```csharp
End of the #If region explained in the beginning of this documentation
 #endregion
```
