Skip to main content
Version: 2.x

Class OdinRoom

Wrapper class of OdinNative.Wrapper.Room.Room for Unity.

This convenient class provides dispatching of events to Unity with passthrough as well as predefined helper functions to cover for a default usecases where the voice chat is visually and logical represented Unity gameobject 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,PeerJoinedEventArgs) Creates GameObject with OdinNative.Unity.OdinPeer component
  • OdinNative.Unity.OdinRoom.PeerLeftRemoveComponent(System.Object,PeerLeftEventArgs) Destroy GameObject with OdinNative.Unity.OdinPeer component
  • OdinNative.Unity.OdinRoom.RoomStatusState(System.Object,RoomStateChangedEventArgs) Destroy this components GameObject if the connection is closed i.e cleanup

Assembly: cs.temp.dll.dll
Declaration
public class OdinRoom : MonoBehaviour, IRoom

Implements:
Odin.IRoom

Properties

Samplerate

Unity samplerate

Declaration
public uint Samplerate { get; set; }

IsStereo

Unity channel flag

Declaration
public bool IsStereo { get; set; }

Id

Odin room id

Declaration
public ulong Id { get; }

CryptoCipher

Declaration
public Crypto CryptoCipher { get; }

Parent

Default value gameObject parent or Unity root

Declaration
public object Parent { get; }

IsJoined

Declaration
public bool IsJoined { get; }

Fields

Gateway

Odin endpoint server

Declaration
public string Gateway

Token

Odin room token

Declaration
public string Token

AudioMixerGroup

Unity mixer

Declaration
public AudioMixerGroup AudioMixerGroup

CryptoComponent

Odin Crypto cipher component

Declaration
public OdinCrypto CryptoComponent

OnRoomJoined

Declaration
public RoomJoinedProxy OnRoomJoined

OnMediaAdded

Event OdinNative.Wrapper.Room.Room.OnMediaStarted redirected as Unity event

Declaration
public MediaAddedProxy OnMediaAdded

OnMediaRemoved

Event OdinNative.Wrapper.Room.Room.OnMediaStopped redirected as Unity event

Declaration
public MediaRemovedProxy OnMediaRemoved

OnPeerJoined

Event OdinNative.Wrapper.Room.Room.OnPeerJoined redirected as Unity event

Declaration
public PeerJoinedProxy OnPeerJoined

OnPeerLeft

Event OdinNative.Wrapper.Room.Room.OnPeerLeft redirected as Unity event

Declaration
public PeerLeftProxy OnPeerLeft

OnMessageReceived

Event OdinNative.Wrapper.Room.Room.OnMessageReceived redirected as Unity event

Declaration
public MessageReceivedProxy OnMessageReceived

OnRoomStateChanged

Event OdinNative.Wrapper.Room.Room.OnRoomStatusChanged redirected as Unity event

Declaration
public RoomStateChangedProxy OnRoomStateChanged

Methods

GetBaseRoom<T>()

Odin base room

Declaration
public T GetBaseRoom<T>() where T : IRoom
Returns

<T>: wrapper room object##### Type Parameters

  • T

Room_OnDatagram(object, DatagramEventArgs)

Declaration
protected virtual void Room_OnDatagram(object sender, DatagramEventArgs args)
Parameters
TypeName
System.Objectsender
Odin.DatagramEventArgsargs

Room_OnRpc(object, RpcEventArgs)

Declaration
protected virtual void Room_OnRpc(object sender, RpcEventArgs args)
Parameters
TypeName
System.Objectsender
Odin.RpcEventArgsargs

Room_OnMessageReceived(object, ulong, byte[])

Declaration
protected virtual void Room_OnMessageReceived(object sender, ulong peerId, byte[] message)
Parameters
TypeName
System.Objectsender
System.UInt64peerId
System.Byte[]message

Room_OnMediaStarted(object, ulong, MediaRpc)

Declaration
protected virtual void Room_OnMediaStarted(object sender, ulong peerId, MediaRpc media)
Parameters
TypeName
System.Objectsender
System.UInt64peerId
Odin.MediaRpcmedia

MediaAddedPeerCreateComponent(object, MediaAddedEventArgs)

Declaration
protected virtual void MediaAddedPeerCreateComponent(object sender, MediaAddedEventArgs args)
Parameters
TypeName
System.Objectsender
Odin.MediaAddedEventArgsargs

Room_OnMediaStopped(object, ulong, ushort)

Declaration
protected virtual void Room_OnMediaStopped(object sender, ulong peerId, ushort mediaId)
Parameters
TypeName
System.Objectsender
System.UInt64peerId
System.UInt16mediaId

MediaRemovedPeerRemoveComponent(object, MediaRemovedEventArgs)

Declaration
protected virtual void MediaRemovedPeerRemoveComponent(object sender, MediaRemovedEventArgs args)
Parameters
TypeName
System.Objectsender
Odin.MediaRemovedEventArgsargs

Room_OnRoomJoined(object, ulong, string, string, byte[], ushort[], ReadOnlyCollection<PeerRpc>)

Declaration
protected virtual void Room_OnRoomJoined(object sender, ulong ownPeerId, string name, string customer, byte[] roomUserData, ushort[] mediaIds, ReadOnlyCollection<PeerRpc> peers)
Parameters
TypeName
System.Objectsender
System.UInt64ownPeerId
System.Stringname
System.Stringcustomer
System.Byte[]roomUserData
System.UInt16[]mediaIds
System.Collections.ObjectModel.ReadOnlyCollection<OdinNative.Wrapper.Peer.PeerRpc>peers

Room_OnPeerLeft(object, ulong)

Declaration
protected virtual void Room_OnPeerLeft(object sender, ulong peerId)
Parameters
TypeName
System.Objectsender
System.UInt64peerId

PeerLeftRemoveComponent(object, PeerLeftEventArgs)

Removes all child components with the same peer id

Declaration
public void PeerLeftRemoveComponent(object sender, PeerLeftEventArgs args)
Parameters
TypeNameDescription
System.ObjectsenderOdinRoom object
Odin.PeerLeftEventArgsargsleft peer data

RemovePeerComponent(GameObject)

Remove a OdinNative.Unity.OdinPeer from a gameobject

Declaration
public void RemovePeerComponent(GameObject containerObject)
Parameters
TypeName
Odin.GameObjectcontainerObject

Room_OnPeerJoined(object, ulong, string, byte[], MediaRpc[])

Declaration
protected virtual void Room_OnPeerJoined(object sender, ulong peerId, string userId, byte[] userData, MediaRpc[] medias)
Parameters
TypeName
System.Objectsender
System.UInt64peerId
System.StringuserId
System.Byte[]userData
Odin.MediaRpc[]medias

PeerJoinedCreateComponent(object, PeerJoinedEventArgs)

Add a new GameObject with a new OdinNative.Unity.OdinPeer component

Declaration
public void PeerJoinedCreateComponent(object sender, PeerJoinedEventArgs args)
Parameters
TypeNameDescription
System.ObjectsenderOdinRoom object
Odin.PeerJoinedEventArgsargspeer join data

AddPeerComponent(GameObject, ulong, bool)

Add OdinNative.Unity.OdinPeer to a gameobject

Declaration
public OdinPeer AddPeerComponent(GameObject containerObject, ulong peerId, bool enable = true)
Returns

OdinNative.Unity.OdinPeer: created component

Parameters
TypeNameDescription
Odin.GameObjectcontainerObjectgameobject where the component will be added
System.UInt64peerIdid of OdinNative.Wrapper.PeerEntity
System.Booleanenableflag if the new OdinNative.Unity.OdinPeer component is enabled

Room_OnConnectionStatusChanged(object, string)

Declaration
protected virtual void Room_OnConnectionStatusChanged(object sender, string connectionStatus)
Parameters
TypeName
System.Objectsender
System.StringconnectionStatus

RoomStatusState(object, RoomStateChangedEventArgs)

Check status if the room should destroy the gameobject

Declaration
public virtual void RoomStatusState(object sender, RoomStateChangedEventArgs status)
Parameters
TypeNameDescription
System.ObjectsenderOdinRoom object
Odin.RoomStateChangedEventArgsstatusnew status

Join(string)

Room join

Declaration
public bool Join(string token)
Returns

System.Boolean: result of Join or false

Parameters
TypeName
System.Stringtoken

Join(string, OdinCipherHandle)

Room join with optional encryption

Declaration
public bool Join(string token, OdinCipherHandle cipher)
Returns

System.Boolean: result of Join or false

Parameters
TypeNameDescription
System.Stringtoken
Odin.OdinCipherHandleciphercrypto cipher

ProxyAudio(float[], int, bool)

Redirects audio to all media encoders in the corresponding room.

Declaration
public virtual void ProxyAudio(float[] buffer, int position, bool isSilent = false)
Parameters
TypeName
System.Single[]buffer
System.Int32position
System.BooleanisSilent

LinkInputMedia(uint, bool, out MediaEncoder)

Add a input media encoder to the corresponding room.

Declaration
public virtual bool LinkInputMedia(uint samplerate, bool stereo, out MediaEncoder encoder)
Returns

System.Boolean: true on start or false

Parameters
TypeNameDescription
System.UInt32samplerateencoder samplerate
System.Booleanstereoencoder channel flag
Odin.MediaEncoderencoderstarted encoder or null

UnlinkInputMedia(MediaEncoder, bool)

Remove a input media encoder from the corresponding room.

Declaration
public virtual bool UnlinkInputMedia(MediaEncoder encoder, bool free = true)
Returns

System.Boolean: true on stop or false

Parameters
TypeNameDescription
Odin.MediaEncoderencoderinput media
System.Booleanfreeflag if the freed up encoder id will be available for the room again

ResumeOutputMedia(OdinMedia)

Start a stopped remote output decoder

Declaration
public virtual bool ResumeOutputMedia(OdinMedia media)
Returns

System.Boolean: true on start or false

Parameters
TypeNameDescription
OdinNative.Unity.OdinMediamediaoutput wrapper

ResumeOutputMedia(MediaDecoder)

Start a stopped remote output decoder

Declaration
public virtual bool ResumeOutputMedia(MediaDecoder decoder)
Returns

System.Boolean: true on start or false

Parameters
TypeNameDescription
Odin.MediaDecoderdecoderoutput

PauseOutputMedia(OdinMedia)

Stop a started remote output decoder

Declaration
public virtual bool PauseOutputMedia(OdinMedia media)
Returns

System.Boolean: true on stop or false

Parameters
TypeNameDescription
OdinNative.Unity.OdinMediamediaoutput wrapper

PauseOutputMedia(MediaDecoder)

Stop a started remote output decoder

Declaration
public virtual bool PauseOutputMedia(MediaDecoder decoder)
Returns

System.Boolean: true on stop or false

Parameters
TypeNameDescription
Odin.MediaDecoderdecoderoutput

GenerateTestToken(string, string, double, string)

Generate a test token from a test key

Declaration
public static string GenerateTestToken(string roomId, string userId, double lifetimeMinutes = 5, string testKey = "")
Returns

System.String: Token or empty

Parameters
TypeNameDescription
System.StringroomIdRoom name
System.StringuserIdUser name
System.DoublelifetimeMinutestoken valid timeframe
System.StringtestKeyoptional test accesskey

WebRequestToken(string, string)

Uses UnityWebRequest with POST data as json to get a response from a token-server

Declaration
public IEnumerator WebRequestToken(string url, string jsonPayload)
Returns

Odin.IEnumerator: IEnumerator for Coroutine

Parameters
TypeNameDescription
System.StringurlToken-Server endpoint
System.StringjsonPayloadRequest data

WebRequestToken(string, string, UnityAction<DownloadHandler>)

Uses UnityWebRequest with POST data as json to get a response from a token-server

Declaration
public IEnumerator WebRequestToken(string url, string jsonPayload, UnityAction<DownloadHandler> response)
Returns

Odin.IEnumerator: IEnumerator for Coroutine

Parameters
TypeNameDescription
System.StringurlToken-Server endpoint
System.StringjsonPayloadRequest data
Odin.UnityAction<DownloadHandler>responseResponse callback

Implements

  • Odin.IRoom