JoinRoom

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;
        });
    }
}