Vivox integration

Note: You must be using a Vivox package version of at least 16.0.0 for the integration to work.

The Vivox service offers a way for game developers to enable voice and text communications between users without investing in a self-hosted solution. Vivox protects users by requiring you to securely authenticate and authorize users before they can perform authoritative actions such as joining a channel, muting, or kicking another player.

In the past, Vivox required clients to implement a server token that securely generates a Vivox Access Token (VAT) similar to a JSON Web Token (JWT) for each authoritative action. Generating a VAT for each authoritative action is cumbersome, and often presents a significant hurdle for securely implementing voice communication in games. Lobby simplifies implementing secure voice communication with Vivox by acting as a token provider for users connected to a lobby.

Note: You must have both the Vivox and the Lobby packages installed to use the two services together. You can install these packages from the Unity Cloud Dashboard. See the Vivox SDK documentation to learn how to set up Vivox.

Keep reading for a quick guide on using Vivox and Lobby together.

Join a voice channel

Once you enable Vivox in your project:

  1. Authenticate yourself using the Unity Authentication package. The following code sample illustrates how to authenticate and initialize Vivox.

    C#

    using System;
       using UnityEngine;
       using Unity.Services.Authentication;
       using Unity.Services.Core;
       using Unity.Services.Vivox;
       using VivoxUnity;
    ​
       async void Start()
       {
           // Authenticate with Unity services
           await UnityServices.InitializeAsync();
           await AuthenticationService.Instance.SignInAnonymouslyAsync();
    ​
           await VivoxService.Instance.InitializeAsync();
    
           // Log in to Vivox services
           await VivoxService.Instance.LoginAsync();
       }
  2. Create a new lobby, or join an existing lobby. The Lobby SDK automatically registers itself as a token provider for Vivox using the Lobby ID.

  3. Join the voice channel for a lobby. When you attempt to join a Vivox channel, it calls the token provider. If the channel ID matches the lobby ID, then it generates a token.

    The following code sample shows you how to create a Lobby and then join the voice channel associated with it.

    C#

    using System;
       using UnityEngine;
       using Unity.Services.Core;
       using Unity.Services.Lobbies;
       using Unity.Services.Lobbies.Models;
       using Unity.Services.Vivox;
       using VivoxUnity;
    ​
       async void CreateLobbyAndJoinVoice()
       {
                 // Create a new lobby (or join an existing one)
           Lobby myLobby = await LobbyService.Instance.CreateLobbyAsync(
               lobbyName: "myLobby",
               maxPlayers: 5,
               options: new CreateLobbyOptions()
               {
                   IsPrivate = false,
    
               });
    ​
           // Join the voice channel
           await VivoxService.Instance.JoinGroupChannelAsync(myLobby.Id, ChatCapability.AudioOnly);
       }
  4. Use Vivox events to be notified of the channel change. For example, VivoxService.Instance.ChannelJoined += channelName => { ... }.

Other interactions with Lobby

Apart from creating or joining a lobby, you can interact with Vivox channels using the Vivox SDK. However, certain actions should be performed using the Lobby SDK instead to keep the Lobby and Voice channels synchronized. The following list contains example actions that you must perform through the Lobby SDK:

Important notes:​

  • Use VivoxService.Instance.JoinGroupChannelAsync(...) to join channels.
  • Before joining a channel, the VivoxService.Instance.JoinGroupChannelAsync(...) line in the previous code sample requires you to await VivoxService.Instance.LoginAsync()
  • Server-side muting is not supported. You can control local muting through the Vivox SDK.