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.
Properties
HasConnections
True if any OdinNative.Odin.Room.Room is joined
Rooms
Config
Static reference to the global OdinNative.Unity.OdinEditorConfig
Instance
Singleton reference to this OdinHandler
Fields
Microphone
Unity Component that handles one Microphone where data gets routed through (n) OdinNative.Odin.Media.MediaStream
OnRoomJoin
Called before an actual room join
OnRoomJoined
Called after a room is joined successfully
OnRoomLeave
Called before a room leave
OnRoomLeft
Called after a room is destroyed
OnPeerJoined
Called on every Peer that joins the room(s) we're connected to
OnPeerUserDataChanged
Called on every Peer that updates his UserData in the same room(s)
OnPeerLeft
Called on every Peer that left in the same room(s)
OnMediaAdded
Called on every Peer that created a media in the same room(s)
OnMediaRemoved
Called on every Peer that closed/destroyed one of his own media in the same room(s)
OnMediaActiveStateChanged
Called on every activity change of a media in the same room(s)
OnRoomUserDataChanged
Called on the Room that updates his UserData
OnMessageReceived
Called on every Peer that received message from a peer by OdinNative.Odin.Room.Room.SendMessage(System.UInt64[],System.Byte[])
OnConnectionStateChanged
Called on the Room that changed the connection state
OnCreatedMediaObject
Called if this OdinHandler created a MediaStream that was requested by the MediaQueue
OnDeleteMediaObject
Called if this OdinHandler destroyed a MediaStream that was closed by a remote peer and was requested by the MediaQueue
UnityAudioSourceTag
Identify
Use3DAudio
Enable 3D Audio via preset OdinNative.Odin.UserData
CreatePlayback
Creates OdinNative.Unity.Audio.PlaybackComponent on OdinHandler.Room_OnMediaAdded(System.Object,MediaAddedEventArgs)
events
PlaybackAudioMixer
PlaybackAudioMixerGroup
Methods
GetUserData()
Returns
Global.IUserData
JoinRoom(string, IUserData, Action<Room>)
Join or create a room by name and attach a OdinNative.Odin.Media.MicrophoneStream
Parameters
Type | Name | Description |
---|---|---|
System.String | roomName | Room name |
Global.IUserData | userData | Override OdinClient default UserData |
System.Action<Room> | setup | Override default Room setup |
JoinRoom(string, string, UserData, Action<Room>)
Join or create a room by name and attach a OdinNative.Odin.Media.MicrophoneStream
Parameters
Type | Name | Description |
---|---|---|
System.String | roomAlias | Room name |
System.String | token | |
Global.UserData | userData | Override OdinClient default UserData |
System.Action<Room> | setup | Override default Room setup |
LeaveRoom(string)
Leave and free the OdinNative.Odin.Room.Room by name
Parameters
Type | Name | Description |
---|---|---|
System.String | roomName | Room name |
Room_OnPeerJoined(object, PeerJoinedEventArgs)
Peer joined the room
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | OdinNative.Odin.Room.Room object |
Global.PeerJoinedEventArgs | e | PeerJoined Args |
Room_OnPeerLeft(object, PeerLeftEventArgs)
Peer left the room
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | OdinNative.Odin.Room.Room object |
Global.PeerLeftEventArgs | e | PeerLeft Args |
Room_OnPeerUserDataChanged(object, PeerUserDataChangedEventArgs)
User data of a peer was updated
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | OdinNative.Odin.Room.Room object |
Global.PeerUserDataChangedEventArgs | e | PeerUpdated Args |
Room_OnMediaAdded(object, MediaAddedEventArgs)
A new media (audio/video stream) was added to the room by a peer
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | OdinNative.Odin.Room.Room object |
Global.MediaAddedEventArgs | e | MediaAdded Args |
Room_OnMediaRemoved(object, MediaRemovedEventArgs)
A media (audio/video stream) was removed from the room by a peer
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | OdinNative.Odin.Room.Room object |
Global.MediaRemovedEventArgs | e | MediaRemoved Args with MediaId |
Room_OnRoomUserDataChanged(object, RoomUserDataChangedEventArgs)
Parameters
Type | Name |
---|---|
System.Object | sender |
Global.RoomUserDataChangedEventArgs | e |
Room_OnMediaActiveStateChanged(object, MediaActiveStateChangedEventArgs)
Parameters
Type | Name |
---|---|
System.Object | sender |
Global.MediaActiveStateChangedEventArgs | e |
Room_OnMessageReceived(object, MessageReceivedEventArgs)
Arbitrary data was sent by a peer
Parameters
Type | Name | Description |
---|---|---|
System.Object | sender | OdinNative.Odin.Room.Room object |
Global.MessageReceivedEventArgs | e | MessageReceivedEventArgs with peer ID and data |
AddPlaybackComponent(string, string, ulong, long, bool)
Tries to identifiy a gameobject by tag to assign the PlaybackComponent
Returns
Global.PlaybackComponent
: ScriptReference of OdinNative.Unity.Audio.PlaybackComponent from the GameObject or null
Parameters
Type | Name | Description |
---|---|---|
System.String | gameObjectTag | Tag string to find with FindGameObjectsWithTag |
System.String | roomName | PlaybackComponent room |
System.UInt64 | peerId | PlaybackComponent peer |
System.Int64 | mediaStreamId | PlaybackComponent media |
System.Boolean | autoDestroySource | optionally 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
Returns
Global.PlaybackComponent
: ScriptReference of OdinNative.Unity.Audio.PlaybackComponent from the GameObject or null
Parameters
Type | Name | Description |
---|---|---|
Global.GameObject | peerContainer | GameObject to attach to |
System.String | roomName | PlaybackComponent room |
System.UInt64 | peerId | PlaybackComponent peer |
System.Int64 | mediaStreamId | PlaybackComponent media |
System.Boolean | autoDestroySource | optionally 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
Returns
Global.MicrophoneStream
: OdinNative.Odin.Media.MicrophoneStream or null if there is no room
Parameters
Type | Name | Description |
---|---|---|
System.String | roomName | Room name |
OdinNative.Core.OdinMediaConfig | config | OdinNative.Odin.Media.MicrophoneStream config |
RoomsSetPositionScale(float)
Configures the allowed 'view' distance for proximity calculation of peers in each room
Parameters
Type | Name | Description |
---|---|---|
System.Single | scale | Per 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
Parameters
Type | Name | Description |
---|---|---|
System.Single | x | x postition |
System.Single | y | y postition |
UpdateUserData(IUserData)
Updates the OdinNative.Odin.UserData for all OdinHandler.Rooms
Parameters
Type | Name | Description |
---|---|---|
Global.IUserData | userData | OdinNative.Odin.IUserData |
GetRoom(string)
Gets the room object from OdinNative.Odin.OdinClient
Returns
Global.Room
: Room or null
Parameters
Type | Name | Description |
---|---|---|
System.String | id | Room identifier e.g name or token |
GetPeer(string, ulong)
Gets the a Peer object from a specified room matching a peer ID
Returns
OdinNative.Odin.Peer.Peer: Peer or null
Parameters
Type | Name | Description |
---|---|---|
System.String | roomId | Room identifier e.g name or token |
System.UInt64 | peerId | peer ID |
GetMedia(string, long)
Get the PlaybackStream of a peer in the room
Returns
Global.PlaybackStream
: PlaybackStream or null
Parameters
Type | Name | Description |
---|---|---|
System.String | roomId | Room identifier e.g name or token |
System.Int64 | mediaStreamId | media handle ID |
GetPeers(string, bool)
Get all remote peers inside a room
Returns
Global.IEnumerable<OdinNative.Odin.Peer.Peer>
: IEnumerable of RemotePeers
Parameters
Type | Name | Description |
---|---|---|
System.String | roomId | Room identifier e.g name or token |
System.Boolean | includeSelf | optionally include Self in peers result |
BroadcastMessage(byte[])
Sends arbitrary data to a all remote peers in all rooms
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | arbitrary byte array |
GetPlaybackComponents()
Gets all OdinNative.Unity.Audio.PlaybackComponent across all rooms
Returns
Global.PlaybackComponent[]
: The array of objects found matching the type PlaybackComponent.### GetPlaybackComponents(string)
Gets all OdinNative.Unity.Audio.PlaybackComponent filtered by room
Returns
Global.PlaybackComponent[]
: The filtered array of objects found matching the type PlaybackComponent.
Parameters
Type | Name | Description |
---|---|---|
System.String | roomId | Room identifier e.g name or token |
GetPlaybackComponents(ulong)
Gets all OdinNative.Unity.Audio.PlaybackComponent across rooms filtered by peer
Returns
Global.PlaybackComponent[]
: The filtered array of objects found matching the type PlaybackComponent.
Parameters
Type | Name | Description |
---|---|---|
System.UInt64 | peerId | peer ID |
GetPlaybackComponents(long)
Gets all OdinNative.Unity.Audio.PlaybackComponent across rooms filtered by media
Returns
Global.PlaybackComponent[]
: The filtered array of objects found matching the type PlaybackComponent.
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | mediaStreamId | media handle ID |
GetPlaybackComponent(string, ulong, long)
Gets a OdinNative.Unity.Audio.PlaybackComponent
Returns
Global.PlaybackComponent
: PlaybackComponent or null
Parameters
Type | Name | Description |
---|---|---|
System.String | roomId | Room identifier e.g name or token |
System.UInt64 | peerId | peer ID |
System.Int64 | mediaStreamId | media handle ID |
DestroyPlaybackComponents()
Destroys all OdinNative.Unity.Audio.PlaybackComponent instances
DestroyPlaybackComponents(string)
Destroys all OdinNative.Unity.Audio.PlaybackComponent filtered by room
Parameters
Type | Name | Description |
---|---|---|
System.String | roomId | Room identifier e.g name or token |
DestroyPlaybackComponents(ulong)
Destroys all OdinNative.Unity.Audio.PlaybackComponent filtered by peer
Parameters
Type | Name | Description |
---|---|---|
System.UInt64 | peerId | peer ID |
DestroyPlaybackComponents(long)
Destroys all OdinNative.Unity.Audio.PlaybackComponent filtered by media
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | mediaStreamId | media handle ID |