Class OdinRoom
Wrapper class of OdinNative.Wrapper.Room.Room for Unity.
This convenient class provides dispatching of events to Unity with passthrough UnityEngine.Events.UnityEvent
as well as predefined helper functions to cover default use cases where the voice chat is visually and logically represented by
Unity gameobjects that are manageable with the Unity editor like Context menu, Inspector and/or Hierarchy window.
Default Unity GameObject altering event callback functions:
OdinNative.Unity.OdinRoom.PeerJoinedCreateComponent(System.Object,OdinNative.Wrapper.Room.PeerJoinedEventArgs)Creates GameObject with OdinNative.Unity.OdinPeer componentOdinNative.Unity.OdinRoom.PeerLeftRemoveComponent(System.Object,OdinNative.Wrapper.Room.PeerLeftEventArgs)Destroy GameObject with OdinNative.Unity.OdinPeer componentOdinNative.Unity.OdinRoom.RoomStatusState(System.Object,OdinNative.Wrapper.Room.RoomStateChangedEventArgs)Destroy this components GameObject if the connection is closed i.e cleanup
Inheritance: System.Object -> UnityEngine.Object -> UnityEngine.Component -> UnityEngine.Behaviour -> UnityEngine.MonoBehaviour
Implements:
OdinNative.Wrapper.IRoom
Properties
Samplerate
Unity samplerate
OutputSampleRate
Playback samplerate reported by Unity, or OdinNative.Unity.OdinRoom.DefaultSampleRate when the Unity audio engine is disabled.
IsStereo
Unity channel flag
Id
Odin room id
CryptoCipher
Encryption handle container
Parent
Default value gameObject parent or Unity root
IsJoined
Indicates whether the room is currently joined
Self
The local peer for this client in this room. Null until the room is joined.
Fields
Gateway
Odin endpoint server
Token
Odin room token
InitialUserData
User data of the local peer that is sent together with the join request
AudioMixerGroup
Unity mixer
DefaultSampleRate
Fallback samplerate for setups that run without the Unity audio engine.
PeerPrefab
Prefab instantiated per joining peer. Falls back to a blank GameObject when null.
CryptoComponent
Odin Crypto cipher component
AutoCreateMedia
Automatically create default medias: an input encoder when audio is pushed via OdinNative.Unity.OdinRoom.ProxyAudio(System.Single[],System.Int32,System.Boolean)
and a decoder when audio arrives from a peer that has no decoder with a matching listen channel mask.
AutoDecoderMediaId
Media id used for default medias created by OdinNative.Unity.OdinRoom.AutoCreateMedia
OnRoomJoined
Event OdinNative.Wrapper.Room.Room.OnRoomJoined redirected as Unity event
OnDecoderAdded
Event raised when a decoder is added for a peer, redirected as Unity event
OnDecoderRemoved
Event raised when a decoder is removed for a peer, redirected as Unity event
OnPeerJoined
Event OdinNative.Wrapper.Room.Room.OnPeerJoined redirected as Unity event
OnPeerLeft
Event OdinNative.Wrapper.Room.Room.OnPeerLeft redirected as Unity event
OnMessageReceived
Event OdinNative.Wrapper.Room.Room.OnMessageReceived redirected as Unity event
OnRoomStateChanged
Event OdinNative.Wrapper.Room.Room.OnRoomStatusChanged redirected as Unity event
Methods
GetBaseRoom<T>()
Odin base room
Returns
<T>: wrapper room object
Type Parameters
T
SendAudio(float[], MediaEncoder)
Push audio samples to the room via a specific encoder.
Returns
System.Boolean
Parameters
| Type | Name |
|---|---|
System.Single[] | samples |
| OdinNative.Wrapper.MediaEncoder | encoder |
SendAudio(float[], MediaEncoder, bool)
Push audio samples to the room via a specific encoder with a silence flag.
Returns
System.Boolean
Parameters
| Type | Name |
|---|---|
System.Single[] | samples |
| OdinNative.Wrapper.MediaEncoder | encoder |
System.Boolean | isSilent |
Room_OnAutoCreateDecoder(object, DatagramEventArgs)
Creates a default decoder for a peer on incoming audio if the peer has no decoder with a matching listen channel mask.
Parameters
| Type | Name | Description |
|---|---|---|
System.Object | sender | Room object |
| OdinNative.Wrapper.Room.DatagramEventArgs | args | datagram data |
Room_OnDatagram(object, DatagramEventArgs)
Parameters
| Type | Name |
|---|---|
System.Object | sender |
| OdinNative.Wrapper.Room.DatagramEventArgs | args |
Room_OnRpc(object, RpcEventArgs)
Parameters
| Type | Name |
|---|---|
System.Object | sender |
| OdinNative.Wrapper.Room.RpcEventArgs | args |
Room_OnSocket(object, SocketMessageEventArgs)
Parameters
| Type | Name |
|---|---|
System.Object | sender |
| OdinNative.Wrapper.Socket.SocketMessageEventArgs | args |
Room_OnMessageReceived(object, uint, byte[])
Parameters
| Type | Name |
|---|---|
System.Object | sender |
System.UInt32 | peerId |
System.Byte[] | message |
ExtraOnNativeDecoderCreated(object, uint, ulong)
Called by OdinNative.Wrapper.Room.Room when the native SDK creates a decoder for a peer
Parameters
| Type | Name | Description |
|---|---|---|
System.Object | sender | Room object |
System.UInt32 | peerId | peer that started streaming |
System.UInt64 | mediaId | media id of the created decoder |
DecoderAddedPeerCreateComponent(object, DecoderAddedEventArgs)
Dispatches OdinNative.Unity.OdinRoom.OnDecoderAdded to the matching OdinNative.Unity.OdinPeer
Parameters
| Type | Name | Description |
|---|---|---|
System.Object | sender | OdinRoom object |
| OdinNative.Unity.Events.DecoderAddedEventArgs | args | decoder data |
ExtraOnNativeDecoderRemoved(object, uint, ulong)
Called by OdinNative.Wrapper.Room.Room when the native SDK removes a decoder for a peer
Parameters
| Type | Name | Description |
|---|---|---|
System.Object | sender | Room object |
System.UInt32 | peerId | peer that stopped streaming |
System.UInt64 | mediaId | media id of the removed decoder |
DecoderRemovedPeerRemoveComponent(object, DecoderRemovedEventArgs)
Dispatches OdinNative.Unity.OdinRoom.OnDecoderRemoved to the matching OdinNative.Unity.OdinPeer
Parameters
| Type | Name | Description |
|---|---|---|
System.Object | sender | OdinRoom object |
| OdinNative.Unity.Events.DecoderRemovedEventArgs | args | decoder data |
Room_OnRoomJoined(object, JoinedObjectContainer)
Parameters
| Type | Name |
|---|---|
System.Object | sender |
| OdinNative.Wrapper.Room.Rpc.JoinedObjectContainer | args |
Room_OnPeerLeft(object, PeerLeftObjectContainer)
Parameters
| Type | Name |
|---|---|
System.Object | sender |
| OdinNative.Wrapper.Peer.Rpc.PeerLeftObjectContainer | args |
PeerLeftRemoveComponent(object, PeerLeftEventArgs)
Removes all child components with the same peer id
Parameters
| Type | Name | Description |
|---|---|---|
System.Object | sender | OdinRoom object |
| OdinNative.Wrapper.Room.PeerLeftEventArgs | args | left peer data |
RemovePeerComponent(GameObject)
Remove a OdinNative.Unity.OdinPeer from a gameobject
Parameters
| Type | Name |
|---|---|
UnityEngine.GameObject | containerObject |
Room_OnPeerJoined(object, PeerJoinedObjectContainer)
Parameters
| Type | Name |
|---|---|
System.Object | sender |
| OdinNative.Wrapper.Peer.Rpc.PeerJoinedObjectContainer | args |
PeerJoinedCreateComponent(object, PeerJoinedEventArgs)
Add a new GameObject with a new OdinNative.Unity.OdinPeer component. Uses OdinNative.Unity.OdinRoom.PeerPrefab if set.
Parameters
| Type | Name | Description |
|---|---|---|
System.Object | sender | OdinRoom object |
| OdinNative.Wrapper.Room.PeerJoinedEventArgs | args | peer join data |
AddPeerComponent(GameObject, uint, bool)
Add OdinNative.Unity.OdinPeer to a gameobject, detecting an existing component on a prefab
Returns
OdinNative.Unity.OdinPeer: created component
Parameters
| Type | Name | Description |
|---|---|---|
UnityEngine.GameObject | containerObject | gameobject where the component will be added |
System.UInt32 | peerId | id of OdinNative.Wrapper.PeerEntity |
System.Boolean | enable | flag if the new OdinNative.Unity.OdinPeer component is enabled |
Room_OnConnectionStatusChanged(object, string)
Parameters
| Type | Name |
|---|---|
System.Object | sender |
System.String | connectionStatus |
RoomStatusState(object, RoomStateChangedEventArgs)
Check status if the room should destroy the gameobject
Parameters
| Type | Name | Description |
|---|---|---|
System.Object | sender | OdinRoom object |
| OdinNative.Wrapper.Room.RoomStateChangedEventArgs | status | new status |
MediaAddedPeerCreateComponent(object, DecoderAddedEventArgs)
Forward for serialized UnityEvents of previous versions
Parameters
| Type | Name |
|---|---|
System.Object | sender |
| OdinNative.Unity.Events.DecoderAddedEventArgs | args |
MediaRemovedPeerRemoveComponent(object, DecoderRemovedEventArgs)
Forward for serialized UnityEvents of previous versions
Parameters
| Type | Name |
|---|---|
System.Object | sender |
| OdinNative.Unity.Events.DecoderRemovedEventArgs | args |
ConnectionStatusState(object, RoomStateChangedEventArgs)
Forward for serialized UnityEvents of previous versions
Parameters
| Type | Name |
|---|---|
System.Object | sender |
| OdinNative.Wrapper.Room.RoomStateChangedEventArgs | status |
Join(string)
Room join
Returns
System.Boolean: result of Join or false
Parameters
| Type | Name |
|---|---|
System.String | token |
Join(string, OdinCipherHandle)
Room join with optional encryption
Returns
System.Boolean: result of Join or false
Parameters
| Type | Name | Description |
|---|---|---|
System.String | token | |
| OdinNative.Core.Imports.OdinCipherHandle | cipher | crypto cipher |
ProxyAudio(float[], int, bool)
Redirects audio to all media encoders in the corresponding room.
Parameters
| Type | Name |
|---|---|
System.Single[] | buffer |
System.Int32 | position |
System.Boolean | isSilent |
LinkInputMedia(uint, bool, out MediaEncoder)
Add a input media encoder to the corresponding room.
Returns
System.Boolean: true on start or false
Parameters
| Type | Name | Description |
|---|---|---|
System.UInt32 | samplerate | encoder samplerate |
System.Boolean | stereo | encoder channel flag |
| OdinNative.Wrapper.MediaEncoder | encoder | started encoder or null |
UnlinkInputMedia(MediaEncoder)
Remove a input media encoder from the corresponding room.
Returns
System.Boolean: true on stop or false
Parameters
| Type | Name | Description |
|---|---|---|
| OdinNative.Wrapper.MediaEncoder | encoder | input media |
RegisterDecoder(OdinDecoder, uint)
Register an OdinNative.Unity.OdinDecoder with the scene-wide decoder registry for the given peer.
Called automatically from OdinNative.Unity.OdinDecoder.OnEnable .
Parameters
| Type | Name | Description |
|---|---|---|
| OdinNative.Unity.OdinDecoder | decoder | decoder to register |
System.UInt32 | peerId | peer this decoder belongs to |
UnregisterDecoder(OdinDecoder)
Unregister an OdinNative.Unity.OdinDecoder from the scene-wide decoder registry.
Called automatically from OdinNative.Unity.OdinDecoder.OnDestroy .
Parameters
| Type | Name | Description |
|---|---|---|
| OdinNative.Unity.OdinDecoder | decoder | decoder to unregister |
DestroyDecodersForPeer(uint)
Destroy all OdinNative.Unity.OdinDecoder instances registered for the given peer, regardless of where they live in the scene hierarchy.
Parameters
| Type | Name | Description |
|---|---|---|
System.UInt32 | peerId | peer whose decoders should be destroyed |
CreateMediaDecoder(uint)
Manually create a decoder for a peer and notify OdinNative.Unity.OdinRoom.OnDecoderAdded listeners.
Returns
OdinNative.Wrapper.MediaDecoder: new OdinNative.Wrapper.MediaDecoder or null
Parameters
| Type | Name | Description |
|---|---|---|
System.UInt32 | peerId | peer to create the decoder for |
RemoveMediaDecoder(uint, ulong)
Manually remove a decoder of a peer and notify OdinNative.Unity.OdinRoom.OnDecoderRemoved listeners.
Parameters
| Type | Name | Description |
|---|---|---|
System.UInt32 | peerId | peer the decoder belongs to |
System.UInt64 | mediaId | media id of the removed decoder |
GenerateTestToken(string, string, double, string)
Generate a test token from a test key
Returns
System.String: Token or empty
Parameters
| Type | Name | Description |
|---|---|---|
System.String | roomId | Room name |
System.String | userId | User name |
System.Double | lifetimeMinutes | token valid timeframe |
System.String | testKey | optional test accesskey |
WebRequestToken(string, string)
Uses UnityWebRequest with POST data as json to get a response from a token-server
Returns
System.Collections.IEnumerator: IEnumerator for Coroutine
Parameters
| Type | Name | Description |
|---|---|---|
System.String | url | Token-Server endpoint |
System.String | jsonPayload | Request data |
WebRequestToken(string, string, UnityAction<DownloadHandler>)
Uses UnityWebRequest with POST data as json to get a response from a token-server
Returns
System.Collections.IEnumerator: IEnumerator for Coroutine
Parameters
| Type | Name | Description |
|---|---|---|
System.String | url | Token-Server endpoint |
System.String | jsonPayload | Request data |
UnityEngine.Events.UnityAction<UnityEngine.Networking.DownloadHandler> | response | Response callback |