Important: This is documentation for the legacy version of the Vivox Unity SDK. This documentation will be removed after July 2025. Refer to the v16 documentation for the new version of the SDK.
Leave a channel
To remove a user from a channel, call the channels IChannelSession.Disconnect
method. The disconnected channel object remains in the ILoginSession.ChannelSessions list after disconnection.
Optionally, you can use the ILoginSession.DeleteChannelSession
method to remove the disconnected channel object from the list; it is safe to do so immediately after disconnecting.
If the session is completely disconnected, the object is immediately removed from the list.
If the session is still in the process of disconnecting, the object is removed when the disconnection process is complete.
Note: Disconnection is not an immediate operation and can take several seconds to complete.
The following code is an example of how to perform this operation:
using UnityEngine;
using VivoxUnity;
class VivoxBasicsExample : MonoBehaviour
{
// For this example, _loginSession is a signed in ILoginSession and channelIdToLeave is the ChannelId to leave.
. . .
void LeaveChannel(ChannelId channelIdToLeave)
{
. . .
var channelSession = _loginSession.GetChannelSession(channelIdToLeave);
if (channelSession != null)
{
// Disconnect from channel
channelSession.Disconnect();
// (Optionally) deleting the channel entry from the channel list
_loginSession.DeleteChannelSession(channelIdToLeave);
}
. . .
}
. . .
}