by Pivec Labs
Group Video Call Voice & Video

Group Video Call

The finished LiveCallDemo scene: up to six players in a video grid with push-to-talk.

01

Run it#

  1. Deploy the Chat Definition's server code (Code → Server Code → Generate + Deploy) and restart SmartFoxServer.
  2. Open Assets/PivecLabs/Examples/Live/Scenes/LiveCallDemo.unity (or Live → Setup & Demos → Open Group Call Demo).
  3. Run two or more copies (a build, or Multiplayer Play Mode), type names and click Connect.
  4. Hold Space or the Hold to talk button to speak. Mute, Camera off and Leave call are along the bottom.
02

What is in the scene#

  • ConnectionManager — the Chat Definition's prefab (ChatRoomZone).
  • NetCrafterEventDispatcher — routes server messages.
  • LiveCallDemo — NetCrafterLiveCall (Push To Talk on) and LiveCallDemoController, which builds the whole UI in code.
03

How the controller works#

Connect finds the ConnectionManager through INetCrafterSession and logs in; when the room is joined it calls JoinRoomCall(); every call event refreshes the grid:

csharp
void Connect()   => LiveDemoUi.FindSession().ConnectAndLogin(playerName);
void OnRoomJoined() => _call.JoinRoomCall();

void Refresh()
{
    // tile 0 = you, then everyone else
    var others = _call.Participants.Where(id => id != _call.LocalUserId).ToList();
    for (int i = 1; i < tiles.Count; i++)
    {
        int id = others[i - 1];
        tiles[i].video.texture = _call.GetRemoteVideo(id);
        tiles[i].label.text    = _call.GetParticipantName(id);
        tiles[i].state.text    = _call.GetPeerState(id).ToString();
    }
}

Full source: Examples/Live/Scripts/LiveCallDemoController.cs.

04

Ideas#

  • Team channels: JoinCall("team-" + teamName).
  • Positional voice: set call.ResolveVoiceAnchor = id => FindAvatar(id); and call RefreshVoiceAnchors() after avatars spawn.
  • Use the 1-to-1 InviteToPrivateCall(userId) from a player list.