# 离开频道

> How to remove a player from a Vivox channel and disconnect from communication.

若要从频道中移除用户，请调用 [`VivoxService.Instance.LeaveChannelAsync(string channelName)`](https://docs.unity3d.com/Packages/com.unity.services.vivox@latest/index.html?subfolder=/api/Unity.Services.Vivox.IVivoxService.html#Unity_Services_Vivox_IVivoxService_LeaveChannelAsync_System_String_) 并指定要离开的频道的名称。或者，也可使用 `VivoxService.Instance.LeaveAllChannelsAsync()` 表示离开用户连接的所有频道。已断开连接的频道对象仍位于 `VivoxService.Instance.ActiveChannels` 列表中，直到成功断开连接之后。

如果会话完全断开连接，则会立即从列表中移除对象。

> **Note:**
>
> 断开连接不是即时操作，可能需要数秒钟时间才能完成。成功完成断开连接操作后，将触发 ChannelLeft 事件。

以下代码示例说明如何执行此操作：

```cs
using UnityEngine;
using Unity.Services.Vivox;

class VivoxBasicsExample : MonoBehaviour
{
    . . .
    void LeaveChannel(string channelNameToLeave)
    {
        . . .
        VivoxService.Instance.LeaveChannelAsync(channelNameToLeave);
        . . .
    }
    . . .
}
```
