OdinHandler.JoinRoom

public async void JoinRoom(string roomName, IUserData userData = null, Action<Room> setup = null)
public async void JoinRoom(string roomAlias, string token, UserData userData = null, Action<Room> setup = null)

Join or create a room by name and attach a Media

Info

Configure Room-Apm i.e VadEnable, … or Odin-Event-Listeners i.e PeerJoinedEvent, … with Config

Parameters

NameTypeDescription
roomNameStringRoom name
userDataIUserDataOverride OdinClient default UserData
setupAction<Room>Override default Room setup
roomAliasStringRoom name
tokenString
userDataUserDataOverride OdinClient default UserData

Discussion

ODIN does not require any bookkeeping from your side. ODIN automatically creates a room when a user joins it (by name) and deletes the room once the last user has left the room.

Provide a room name as a string in roomName. It can be anything you like. Remember, that all users that have joined the same room can talk to each other (or at least listen to what others are saying). If you have two teams of users in your game, and each team should only talk to other team members, you could have two rooms: Team_A and Team_B. We have created a couple of use-cases explaining various methods of defining room names in this document.

userData is of type UserData and is basically just a byte array. You can set any user data you like. The best way is to create a class and serialize that class to whatever you like. We provide a sample of such a class in the guide Understanding User Data.

Use the setup callback to adjust room settings before data is sent to ODIN and the room is created on the ODIN servers.

public class Radio: MonoBehaviour
{
    private string _currentRoom;
    public int currentChannel = 1;
    
    void Start()
    {
        UpdateRadioConnection();
    }
    
    public void ChangeChannel(newChannel) 
    {
        currentChannel = newChannel;
        UpdateRadioConnection();
    }
    
    void UpdateRadioConnection()
    {
        // Leave the current radio room
        if (_currentRoom) {
            OdinHandler.Instance.LeaveRoom(_currentRoom);
        }
        
        _currentRoom = "Radio_" + currentChannel.ToString();
        OdinHandler.Instance.JoinRoom(_currentRoom, null, room => {
            // Activate Voice Activity Detection 
            room.Config.ApmConfig.VadEnable = true;
        });
    }
}

Variants

JoinRoom(roomName, userData, setup)

public async void JoinRoom(string roomName, IUserData userData = null, Action<Room> setup = null)

Join or create a room by name and attach a Media

Warning

Configure Room-Apm i.e VadEnable, … or Odin-Event-Listeners i.e PeerJoinedEvent, … with Config

Parameters

NameTypeDescription
roomNameStringRoom name
userDataIUserDataOverride OdinClient default UserData
setupAction<Room>Override default Room setup

JoinRoom(roomAlias, token, userData, setup)

public async void JoinRoom(string roomAlias, string token, UserData userData = null, Action<Room> setup = null)

Join or create a room by name and attach a Media

Warning

Configure Room-Apm i.e VadEnable, … or Odin-Event-Listeners i.e PeerJoinedEvent, … with Config

Parameters

NameTypeDescription
roomAliasStringRoom name
tokenString
userDataUserDataOverride OdinClient default UserData
setupAction<Room>Override default Room setup