# 5. Hooking Vivox to Lobby Sessions Part of [[Voice Chat with Vivox]]. Back: [[4. Mute Transmission Volume and Roster]]. Next: [[6. Quest Classroom Voice and Pitfalls]]. > [!warning] Code not compiled in Unity > `ISession.Id`, `ISession.Code`, and `LeaveAsync` are the official Multiplayer Services types already cited in [[Lobby, Relay and Multiplayer Services]] (2.3.3 Scripting API, checked 2026-11-10). This hook has not been compiled against either that SDK or Vivox. ## 5.1 One session, one group channel Players already create or join a Session in [[2. Sessions as the Lobby]]. Voice should not invent a second room code. Official `ISession` (Lobby series): `Id` is the stable identifier; `Code` is the player-visible join string — prefer **Code** when you *show* something, prefer **Id** when you need a unique, stable key. Use `Id` as the Vivox channel name suffix. Official Vivox constraint (part 3): channel names must be unique across echo / group / positional types. Prefix the type so a typo cannot collide: ```text session-{ISession.Id} ``` Do not use `Code` as the channel name. Codes can be reissued or shown on a whiteboard; `Id` is the join key you already treat as unique. Join **after** the Session is up and Vivox login has succeeded. Leave the channel when the Session leaves, then decide whether to stay logged into Vivox (a "browse another session" lobby can keep the login) or call `LogoutAsync`. ## 5.2 SessionVoiceHook ```csharp using System; using System.Threading.Tasks; using Unity.Services.Multiplayer; using UnityEngine; /// <summary> /// Joins a Vivox group channel named session-{ISession.Id} after a Multiplayer /// Services session is available, and leaves that channel when asked to follow /// ISession.LeaveAsync. /// </summary> public sealed class SessionVoiceHook : MonoBehaviour { [SerializeField] VivoxLifecycle lifecycle; [SerializeField] VivoxGroupChannel channel; public string BoundSessionId { get; private set; } = string.Empty; public string BoundSessionCode { get; private set; } = string.Empty; public async Task BindAndJoinAsync(ISession session, string displayName) { if (session == null) throw new ArgumentNullException(nameof(session)); if (lifecycle == null || channel == null) throw new InvalidOperationException("Assign VivoxLifecycle and VivoxGroupChannel."); await lifecycle.InitializeAndLoginAsync(displayName); var channelName = ChannelNameFor(session); await channel.JoinGroupAsync(channelName); BoundSessionId = session.Id; BoundSessionCode = session.Code ?? string.Empty; } public async Task LeaveVoiceAndSessionAsync(ISession session) { if (channel != null) await channel.LeaveAsync(); BoundSessionId = string.Empty; BoundSessionCode = string.Empty; if (session != null) await session.LeaveAsync(); } public static string ChannelNameFor(ISession session) { if (session == null || string.IsNullOrEmpty(session.Id)) throw new ArgumentException("Session Id is required to name the voice channel."); return "session-" + session.Id; } } ``` Call `BindAndJoinAsync` from the same place you already proceed from "session joined" to starting NGO ([[3. Relay and Netcode Integration]]). Call `LeaveVoiceAndSessionAsync` from the existing leave/disconnect button so voice cannot outlive the session UI. If `LeaveAsync` on the session already ran (for example a `RemovedFromSession` path in the Lobby pitfalls note), still call `channel.LeaveAsync()` — leaving Vivox is not implied by leaving the Session. ## 5.3 What not to wire - Do not put Vivox join inside `WithRelayNetwork()` or the NGO network handler. Relay is transport for Netcode, not for Vivox. Vivox has its own connection. - Do not join voice before Authentication has signed in — `LoginAsync` will not have a UAS `PlayerId`. - Do not re-use the echo channel name `"Lobby"` from the official quickstart as your session channel. That sample name is for a local echo test (part 3). - Host migration mid-channel is **not verified**. If the Session host changes, keep the same `session-{Id}` channel and do not "restart voice" unless you have tested that path. Next: [[6. Quest Classroom Voice and Pitfalls]].