Initiate a channel join

The following code is an example of how to initiate a channel join.

using System;
using System.ComponentModel;
using UnityEngine;
using Unity.Services.Vivox;

class JoinChannelExample : MonoBehaviour
{
    // For this example, _loginSession is a signed in ILoginSession.
    . . .
    void OnLoggedIn()
    {
        //These events can be bound anywhere, but keeping them within the lifecycle of an active LoginSession is typically best
        VivoxService.Instance.ChannelJoined += OnChannelJoined
        VivoxService.Instance.ChannelLeft += OnChannelLeft
    }

    void OnChannelJoined(string channelName)
    {
        //Perform actions to react to joining the specific channel with name channelName
        //UI switches, participant UI setup, etc
    }

    void OnChannelLeft(string channelName)
    {
        //Perform cleanup to react to leaving a specific channel with name channelName
    }

    async void JoinChannelAsync(string channelName)
    {
        //Join channel with name channelName and capability for text and audio transmission
        VivoxService.Instance.JoinGroupChannelAsync(channelName, ChatCapability.TextAndAudio);
    }
    . . .
}

To determine when the channel is joined, the VivoxService.Instance.ChannelJoined event must be bound to. The event itself will fire with the name of the channel, which should be used to trigger the specific events required for that channel. Using a structure for channel names that can help differentiate how different channels will be processed is suggested.

ChannelLeft is an action that will fire upon leaving a channel, with the name of the channel that was left as a parameter.

VivoxService.Instance.JoinGroupChannelAsync, VivoxService.Instance.JoinEchoChannelAsync, and VivoxService.Instance.JoinPositionalChannelAsync have an optional parameter called ChannelOptions. Use ChannelOptions to set behaviour, such as making the channel the active channel being transmitted into when the channel join finishes.