Skip to main content
Version: 2.x

Class OdinPeer

Wrapper class of OdinNative.Wrapper.PeerEntity 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.

Default Unity GameObject altering event callback functions:

  • OdinNative.Unity.OdinPeer.Peer_DecoderAdded(System.Object,OdinNative.Unity.Events.DecoderAddedEventArgs) Creates GameObject with OdinNative.Unity.OdinDecoder component and attach media
  • OdinNative.Unity.OdinPeer.Peer_DecoderRemoved(System.Object,OdinNative.Unity.Events.DecoderRemovedEventArgs) Destroy GameObject with OdinNative.Unity.OdinDecoder component
Declaration
[HelpURL("https://docs.4players.io/voice/unity/next/api/OdinNative.Unity/OdinPeer/")]
[AddComponentMenu("Odin/Instance/OdinPeer")]
public class OdinPeer : MonoBehaviour, IPeer

Inheritance: System.Object -> UnityEngine.Object -> UnityEngine.Component -> UnityEngine.Behaviour -> UnityEngine.MonoBehaviour

Implements:
OdinNative.Wrapper.IPeer

Properties

Parent

Default value null indicates root or not set

Declaration
public IRoom Parent { get; set; }

Id

peer id

Declaration
public uint Id { get; set; }

UserId

token user id

Declaration
public string UserId { get; }

UserData

peer userdata

Declaration
public IUserData UserData { get; }

Tags

user tags

Declaration
public List<string> Tags { get; }

Fields

DecoderPrefab

Prefab instantiated per decoder.

Declaration
public GameObject DecoderPrefab

OnDecoderAdded

Additional event redirect from OdinNative.Unity.OdinRoom

Declaration
[FormerlySerializedAs("OnMediaAdded")]
public DecoderAddedProxy OnDecoderAdded

OnDecoderRemoved

Additional event redirect from OdinNative.Unity.OdinRoom

Declaration
[FormerlySerializedAs("OnMediaRemoved")]
public DecoderRemovedProxy OnDecoderRemoved

Methods

GetBasePeer()

Get the underlying OdinNative.Wrapper.PeerEntity

Declaration
public PeerEntity GetBasePeer()
Returns

OdinNative.Wrapper.PeerEntity: native wrapper peer

GetRoomApi()

Get the underlying OdinNative.Wrapper.Room.Room

Declaration
public Room GetRoomApi()
Returns

OdinNative.Wrapper.Room.Room: native wrapper room

GetEncoder()

Get encoder

Declaration
public MediaEncoder GetEncoder()
Returns

OdinNative.Wrapper.MediaEncoder: input media encoder of the peer or null

GetDecoder()

Get decoder

Declaration
public MediaDecoder GetDecoder()
Returns

OdinNative.Wrapper.MediaDecoder: output media decoder of the peer or null

Peer_DecoderAdded(object, DecoderAddedEventArgs)

Event trigger to create a OdinNative.Unity.OdinDecoder component

Declaration
public virtual void Peer_DecoderAdded(object sender, DecoderAddedEventArgs args)
Parameters
TypeNameDescription
System.ObjectsenderOdinRoom object
OdinNative.Unity.Events.DecoderAddedEventArgsargsstarted media data

AddDecoderComponent(GameObject, ulong, bool)

Create a OdinNative.Unity.OdinDecoder component

Declaration
public OdinDecoder AddDecoderComponent(GameObject containerObject, ulong mediaId, bool enable = true)
Returns

OdinNative.Unity.OdinDecoder: created component

Parameters
TypeNameDescription
UnityEngine.GameObjectcontainerObjectgameobject where the component will be added
System.UInt64mediaIdid of OdinNative.Wrapper.MediaDecoder
System.Booleanenableflag if the new OdinNative.Unity.OdinDecoder component is enabled

AddDecoderComponent(GameObject, ulong, uint, bool, bool)

Create a OdinNative.Unity.OdinDecoder component

Declaration
public OdinDecoder AddDecoderComponent(GameObject containerObject, ulong mediaId, uint samplerate, bool stereo, bool enable = true)
Returns

OdinNative.Unity.OdinDecoder: created component

Parameters
TypeNameDescription
UnityEngine.GameObjectcontainerObjectgameobject where the component will be added
System.UInt64mediaIdid of OdinNative.Wrapper.MediaDecoder
System.UInt32sampleratedecoder samplerate
System.Booleanstereodecoder channel flag
System.Booleanenableflag if the new OdinNative.Unity.OdinDecoder component is enabled

Peer_DecoderRemoved(object, DecoderRemovedEventArgs)

Event trigger to remove a OdinNative.Unity.OdinDecoder component

Declaration
public virtual void Peer_DecoderRemoved(object sender, DecoderRemovedEventArgs args)
Parameters
TypeNameDescription
System.ObjectsenderOdinRoom object
OdinNative.Unity.Events.DecoderRemovedEventArgsargsstopped media data

Peer_MediaAdded(object, DecoderAddedEventArgs)

Forward for serialized UnityEvents of previous versions

Declaration
[Obsolete("Renamed to Peer_DecoderAdded; kept so serialized UnityEvents from previous versions keep working")]
public void Peer_MediaAdded(object sender, DecoderAddedEventArgs args)
Parameters
TypeName
System.Objectsender
OdinNative.Unity.Events.DecoderAddedEventArgsargs

Peer_MediaRemoved(object, DecoderRemovedEventArgs)

Forward for serialized UnityEvents of previous versions

Declaration
[Obsolete("Renamed to Peer_DecoderRemoved; kept so serialized UnityEvents from previous versions keep working")]
public void Peer_MediaRemoved(object sender, DecoderRemovedEventArgs args)
Parameters
TypeName
System.Objectsender
OdinNative.Unity.Events.DecoderRemovedEventArgsargs

RemoveDecoderComponent(GameObject, ulong, bool)

Removes all child components with the same media id

Declaration
public bool RemoveDecoderComponent(GameObject containerObject, ulong mediaId, bool componentOnly = false)
Returns

System.Boolean: true on removed decoder or false

Parameters
TypeNameDescription
UnityEngine.GameObjectcontainerObjectchild components
System.UInt64mediaIddecoder id
System.BooleancomponentOnlyon false will destroy gameobject

AddSocketComponent(GameObject, OdinSocketKind, int, int)

Declaration
public OdinSocket AddSocketComponent(GameObject containerObject, NativeBindings.OdinSocketKind kind, int label, int priority = 0)
Returns

OdinNative.Unity.OdinSocket

Parameters
TypeName
UnityEngine.GameObjectcontainerObject
OdinNative.Core.Imports.NativeBindings.OdinSocketKindkind
System.Int32label
System.Int32priority

RemoveSocketComponent(GameObject, ulong, bool)

Declaration
public bool RemoveSocketComponent(GameObject containerObject, ulong socketId, bool componentOnly = false)
Returns

System.Boolean

Parameters
TypeName
UnityEngine.GameObjectcontainerObject
System.UInt64socketId
System.BooleancomponentOnly

Implements