Skip to main content
Version: 1.x

Class OdinHandler

The OdinHandler class is the global ODIN manager within Unity. It’s built as a singleton. Create an empty game object in your scene and add this script to it. OdinHandler uses DontDestroyOnLoad to keep the singleton alive even if the scene changes.

Declaration
public class OdinHandler : MonoBehaviour

Properties

HasConnections

True if any OdinNative.Odin.Room.Room is joined

Declaration
public bool HasConnections { get; }

Rooms

Declaration
public RoomCollection Rooms { get; }

Config

Static reference to the global OdinNative.Unity.OdinEditorConfig

Declaration
public static OdinEditorConfig Config { get; }

Instance

Singleton reference to this OdinHandler

Declaration
public static OdinHandler Instance { get; }

Fields

Microphone

Unity Component that handles one Microphone where data gets routed through (n) OdinNative.Odin.Media.MediaStream

Declaration
public MicrophoneReader Microphone

OnRoomJoin

Called before an actual room join

Declaration
public RoomJoinProxy OnRoomJoin

OnRoomJoined

Called after a room is joined successfully

Declaration
public RoomJoinedProxy OnRoomJoined

OnRoomLeave

Called before a room leave

Declaration
public RoomLeaveProxy OnRoomLeave

OnRoomLeft

Called after a room is destroyed

Declaration
public RoomLeftProxy OnRoomLeft

OnPeerJoined

Called on every Peer that joins the room(s) we're connected to

Declaration
public PeerJoinedProxy OnPeerJoined

OnPeerUserDataChanged

Called on every Peer that updates his UserData in the same room(s)

Declaration
public PeerUserDataChangedProxy OnPeerUserDataChanged

OnPeerLeft

Called on every Peer that left in the same room(s)

Declaration
public PeerLeftProxy OnPeerLeft

OnMediaAdded

Called on every Peer that created a media in the same room(s)

Declaration
public MediaAddedProxy OnMediaAdded

OnMediaRemoved

Called on every Peer that closed/destroyed one of his own media in the same room(s)

Declaration
public MediaRemovedProxy OnMediaRemoved

OnMediaActiveStateChanged

Called on every activity change of a media in the same room(s)

Declaration
public MediaActiveStateChangedProxy OnMediaActiveStateChanged

OnRoomUserDataChanged

Called on the Room that updates his UserData

Declaration
public RoomUserDataChangedProxy OnRoomUserDataChanged

OnMessageReceived

Called on every Peer that received message from a peer by OdinNative.Odin.Room.Room.SendMessage(System.UInt64[],System.Byte[])

Declaration
public MessageReceivedProxy OnMessageReceived

OnConnectionStateChanged

Called on the Room that changed the connection state

Declaration
public ConnectionStateChangedProxy OnConnectionStateChanged

OnCreatedMediaObject

Called if this OdinHandler created a MediaStream that was requested by the MediaQueue

Declaration
public UnityCreatedMediaObject OnCreatedMediaObject

OnDeleteMediaObject

Called if this OdinHandler destroyed a MediaStream that was closed by a remote peer and was requested by the MediaQueue

Declaration
public UnityDeleteMediaObject OnDeleteMediaObject

UnityAudioSourceTag

Identify by Unity-Tag to attach a OdinNative.Unity.Audio.PlaybackComponent

Declaration
public readonly string UnityAudioSourceTag

Use3DAudio

Enable 3D Audio via preset OdinNative.Odin.UserData

Declaration
public bool Use3DAudio

CreatePlayback

Creates OdinNative.Unity.Audio.PlaybackComponent on OdinHandler.Room_OnMediaAdded(System.Object,MediaAddedEventArgs) events

Declaration
public bool CreatePlayback

PlaybackAudioMixer

Declaration
public AudioMixer PlaybackAudioMixer

PlaybackAudioMixerGroup

Declaration
public AudioMixerGroup PlaybackAudioMixerGroup

Methods

GetUserData()

Declaration
public IUserData GetUserData()
Returns

Global.IUserData

JoinRoom(string, IUserData, Action<Room>)

Join or create a room by name and attach a OdinNative.Odin.Media.MicrophoneStream

Declaration
public void JoinRoom(string roomName, IUserData userData = null, Action<Room> setup = null)
Parameters
TypeNameDescription
System.StringroomNameRoom name
Global.IUserDatauserDataOverride OdinClient default UserData
System.Action<Room>setupOverride default Room setup

JoinRoom(string, string, UserData, Action<Room>)

Join or create a room by name and attach a OdinNative.Odin.Media.MicrophoneStream

Declaration
public void JoinRoom(string roomAlias, string token, UserData userData = null, Action<Room> setup = null)
Parameters
TypeNameDescription
System.StringroomAliasRoom name
System.Stringtoken
Global.UserDatauserDataOverride OdinClient default UserData
System.Action<Room>setupOverride default Room setup

LeaveRoom(string)

Leave and free the OdinNative.Odin.Room.Room by name

Declaration
public void LeaveRoom(string roomName)
Parameters
TypeNameDescription
System.StringroomNameRoom name

Room_OnPeerJoined(object, PeerJoinedEventArgs)

Peer joined the room

Declaration
protected virtual void Room_OnPeerJoined(object sender, PeerJoinedEventArgs e)
Parameters
TypeNameDescription
System.ObjectsenderOdinNative.Odin.Room.Room object
Global.PeerJoinedEventArgsePeerJoined Args

Room_OnPeerLeft(object, PeerLeftEventArgs)

Peer left the room

Declaration
protected virtual void Room_OnPeerLeft(object sender, PeerLeftEventArgs e)
Parameters
TypeNameDescription
System.ObjectsenderOdinNative.Odin.Room.Room object
Global.PeerLeftEventArgsePeerLeft Args

Room_OnPeerUserDataChanged(object, PeerUserDataChangedEventArgs)

User data of a peer was updated

Declaration
protected virtual void Room_OnPeerUserDataChanged(object sender, PeerUserDataChangedEventArgs e)
Parameters
TypeNameDescription
System.ObjectsenderOdinNative.Odin.Room.Room object
Global.PeerUserDataChangedEventArgsePeerUpdated Args

Room_OnMediaAdded(object, MediaAddedEventArgs)

A new media (audio/video stream) was added to the room by a peer

Declaration
protected virtual void Room_OnMediaAdded(object sender, MediaAddedEventArgs e)
Parameters
TypeNameDescription
System.ObjectsenderOdinNative.Odin.Room.Room object
Global.MediaAddedEventArgseMediaAdded Args

Room_OnMediaRemoved(object, MediaRemovedEventArgs)

A media (audio/video stream) was removed from the room by a peer

Declaration
protected virtual void Room_OnMediaRemoved(object sender, MediaRemovedEventArgs e)
Parameters
TypeNameDescription
System.ObjectsenderOdinNative.Odin.Room.Room object
Global.MediaRemovedEventArgseMediaRemoved Args with MediaId

Room_OnRoomUserDataChanged(object, RoomUserDataChangedEventArgs)

Declaration
protected virtual void Room_OnRoomUserDataChanged(object sender, RoomUserDataChangedEventArgs e)
Parameters
TypeName
System.Objectsender
Global.RoomUserDataChangedEventArgse

Room_OnMediaActiveStateChanged(object, MediaActiveStateChangedEventArgs)

Declaration
protected virtual void Room_OnMediaActiveStateChanged(object sender, MediaActiveStateChangedEventArgs e)
Parameters
TypeName
System.Objectsender
Global.MediaActiveStateChangedEventArgse

Room_OnMessageReceived(object, MessageReceivedEventArgs)

Arbitrary data was sent by a peer

Declaration
protected virtual void Room_OnMessageReceived(object sender, MessageReceivedEventArgs e)
Parameters
TypeNameDescription
System.ObjectsenderOdinNative.Odin.Room.Room object
Global.MessageReceivedEventArgseMessageReceivedEventArgs with peer ID and data

AddPlaybackComponent(string, string, ulong, long, bool)

Tries to identifiy a gameobject by tag to assign the PlaybackComponent

Declaration
public PlaybackComponent AddPlaybackComponent(string gameObjectTag, string roomName, ulong peerId, long mediaStreamId, bool autoDestroySource = true)
Returns

Global.PlaybackComponent: ScriptReference of OdinNative.Unity.Audio.PlaybackComponent from the GameObject or null

Parameters
TypeNameDescription
System.StringgameObjectTagTag string to find with FindGameObjectsWithTag
System.StringroomNamePlaybackComponent room
System.UInt64peerIdPlaybackComponent peer
System.Int64mediaStreamIdPlaybackComponent media
System.BooleanautoDestroySourceoptionally enable or disable on destroy of PlaybackComponent the destroy of the linked AudioSource

AddPlaybackComponent(GameObject, string, ulong, long, bool)

Adds a new PlaybackComponent to the specified GameObject

Declaration
public PlaybackComponent AddPlaybackComponent(GameObject peerContainer, string roomName, ulong peerId, long mediaStreamId, bool autoDestroySource = true)
Returns

Global.PlaybackComponent: ScriptReference of OdinNative.Unity.Audio.PlaybackComponent from the GameObject or null

Parameters
TypeNameDescription
Global.GameObjectpeerContainerGameObject to attach to
System.StringroomNamePlaybackComponent room
System.UInt64peerIdPlaybackComponent peer
System.Int64mediaStreamIdPlaybackComponent media
System.BooleanautoDestroySourceoptionally enable or disable on destroy of PlaybackComponent the destroy of the linked AudioSource

GetOrCreateMicrophoneStream(string, OdinMediaConfig)

Returns the attached OdinNative.Odin.Media.MicrophoneStream used by OdinNative.Unity.Audio.MicrophoneReader

Declaration
public MicrophoneStream GetOrCreateMicrophoneStream(string roomName, OdinMediaConfig config = null)
Returns

Global.MicrophoneStream: OdinNative.Odin.Media.MicrophoneStream or null if there is no room

Parameters
TypeNameDescription
System.StringroomNameRoom name
OdinNative.Core.OdinMediaConfigconfigOdinNative.Odin.Media.MicrophoneStream config

RoomsSetPositionScale(float)

Configures the allowed 'view' distance for proximity calculation of peers in each room

Declaration
public void RoomsSetPositionScale(float scale)
Parameters
TypeNameDescription
System.SinglescalePer default, the room will use a distance of 1.0 fo proximity calculation

RoomsUpdatePosition(float, float)

Updates the two-dimensional position of our own peer in each room

Declaration
public void RoomsUpdatePosition(float x, float y)
Parameters
TypeNameDescription
System.Singlexx postition
System.Singleyy postition

UpdateUserData(IUserData)

Updates the OdinNative.Odin.UserData for all OdinHandler.Rooms

Declaration
public void UpdateUserData(IUserData userData)
Parameters
TypeNameDescription
Global.IUserDatauserDataOdinNative.Odin.IUserData

GetRoom(string)

Gets the room object from OdinNative.Odin.OdinClient

Declaration
public Room GetRoom(string id)
Returns

Global.Room: Room or null

Parameters
TypeNameDescription
System.StringidRoom identifier e.g name or token

GetPeer(string, ulong)

Gets the a Peer object from a specified room matching a peer ID

Declaration
public Peer GetPeer(string roomId, ulong peerId)
Returns

OdinNative.Odin.Peer.Peer: Peer or null

Parameters
TypeNameDescription
System.StringroomIdRoom identifier e.g name or token
System.UInt64peerIdpeer ID

GetMedia(string, long)

Get the PlaybackStream of a peer in the room

Declaration
public PlaybackStream GetMedia(string roomId, long mediaStreamId)
Returns

Global.PlaybackStream: PlaybackStream or null

Parameters
TypeNameDescription
System.StringroomIdRoom identifier e.g name or token
System.Int64mediaStreamIdmedia handle ID

GetPeers(string, bool)

Get all remote peers inside a room

Declaration
public IEnumerable<Peer> GetPeers(string roomId, bool includeSelf = false)
Returns

Global.IEnumerable<OdinNative.Odin.Peer.Peer>: IEnumerable of RemotePeers

Parameters
TypeNameDescription
System.StringroomIdRoom identifier e.g name or token
System.BooleanincludeSelfoptionally include Self in peers result

BroadcastMessage(byte[])

Sends arbitrary data to a all remote peers in all rooms

Declaration
public void BroadcastMessage(byte[] data)
Parameters
TypeNameDescription
System.Byte[]dataarbitrary byte array

GetPlaybackComponents()

Gets all OdinNative.Unity.Audio.PlaybackComponent across all rooms

Declaration
public PlaybackComponent[] GetPlaybackComponents()
Returns

Global.PlaybackComponent[]: The array of objects found matching the type PlaybackComponent.### GetPlaybackComponents(string) Gets all OdinNative.Unity.Audio.PlaybackComponent filtered by room

Declaration
public PlaybackComponent[] GetPlaybackComponents(string roomId)
Returns

Global.PlaybackComponent[]: The filtered array of objects found matching the type PlaybackComponent.

Parameters
TypeNameDescription
System.StringroomIdRoom identifier e.g name or token

GetPlaybackComponents(ulong)

Gets all OdinNative.Unity.Audio.PlaybackComponent across rooms filtered by peer

Declaration
public PlaybackComponent[] GetPlaybackComponents(ulong peerId)
Returns

Global.PlaybackComponent[]: The filtered array of objects found matching the type PlaybackComponent.

Parameters
TypeNameDescription
System.UInt64peerIdpeer ID

GetPlaybackComponents(long)

Gets all OdinNative.Unity.Audio.PlaybackComponent across rooms filtered by media

Declaration
public PlaybackComponent[] GetPlaybackComponents(long mediaStreamId)
Returns

Global.PlaybackComponent[]: The filtered array of objects found matching the type PlaybackComponent.

Parameters
TypeNameDescription
System.Int64mediaStreamIdmedia handle ID

GetPlaybackComponent(string, ulong, long)

Gets a OdinNative.Unity.Audio.PlaybackComponent

Declaration
public PlaybackComponent GetPlaybackComponent(string roomId, ulong peerId, long mediaStreamId)
Returns

Global.PlaybackComponent: PlaybackComponent or null

Parameters
TypeNameDescription
System.StringroomIdRoom identifier e.g name or token
System.UInt64peerIdpeer ID
System.Int64mediaStreamIdmedia handle ID

DestroyPlaybackComponents()

Destroys all OdinNative.Unity.Audio.PlaybackComponent instances

Declaration
public void DestroyPlaybackComponents()

DestroyPlaybackComponents(string)

Destroys all OdinNative.Unity.Audio.PlaybackComponent filtered by room

Declaration
public void DestroyPlaybackComponents(string roomId)
Parameters
TypeNameDescription
System.StringroomIdRoom identifier e.g name or token

DestroyPlaybackComponents(ulong)

Destroys all OdinNative.Unity.Audio.PlaybackComponent filtered by peer

Declaration
public void DestroyPlaybackComponents(ulong peerId)
Parameters
TypeNameDescription
System.UInt64peerIdpeer ID

DestroyPlaybackComponents(long)

Destroys all OdinNative.Unity.Audio.PlaybackComponent filtered by media

Declaration
public void DestroyPlaybackComponents(long mediaStreamId)
Parameters
TypeNameDescription
System.Int64mediaStreamIdmedia handle ID