Skip to main content
Version: 0.11.x

Class: OdinRoom

The OdinRoom class. Use createRoom from OdinClient instance to create a room. The OdinRoom requires a token to connect to a room. OdinClients handles token creation for you, so its easier to just use OdinClient for room creation. Typical procedure is to create an OdinClient instance with an access key and call its createRoom function to create a room with a name and for a user id. Then add event listeners to the room and call join to connect to the room.

Constructors​

new OdinRoom()​

new OdinRoom(token): OdinRoom

Creates a new instance of a room with a token. Use OdinClient if you don't want to manage tokens yourself. Important: Don't use this function directly, use OdinClient instead.

Parameters​

• token: string

The token to use for this room.

Returns​

OdinRoom

Defined in​

odin.room.d.ts:519

Accessors​

connected​

get connected(): boolean

Gets whether the room is currently connected.

Returns​

boolean

Defined in​

odin.room.d.ts:631


id​

get id(): string

Gets the ID of the room.

Returns​

string

Defined in​

odin.room.d.ts:612


ownPeerId​

get ownPeerId(): number

Gets the ID of the local peer joined to the room.

Returns​

number

Defined in​

odin.room.d.ts:617

Methods​

addEventListener()​

addEventListener<Event>(eventName, handler): void

Adds an event listener to the room for specific events.

Type Parameters​

• Event extends keyof OdinEvents

Parameters​

• eventName: Event

The event to listen for (see keys of OdinEvents for possible values)

• handler: OdinEvents[Event]

The callback to call when the event is fired.

Returns​

void

Defined in​

odin.room.d.ts:540


close()​

close(): void

Closes the room and disconnects from the server.

This method emits the 'Left' event before closing the native connection, ensuring that cleanup callbacks registered via onLeft() are triggered. The event payload will contain { reason: 'ClientDisconnect' } to distinguish it from server-initiated disconnects.

This provides a single, consistent cleanup path for session state management, as the onLeft handler will fire for both:

  • Client-initiated disconnects (calling close())
  • Server-initiated disconnects (kicked, timeout, etc.)

Returns​

void

Defined in​

odin.room.d.ts:607


createAudioStream()​

createAudioStream(sampleRate, channels, apmSettings?): OdinMedia

Creates a local audio stream and adds it to the room. An OdinMedia object will be returned that allows you to send audio data.

Parameters​

• sampleRate: number

The sample rate of the audio stream. Can be between 8000 and 48000.

• channels: number

The number of channels of the audio stream. Can be 1 or 2.

• apmSettings?: OdinAPMSettings

Returns​

OdinMedia

The OdinMedia object that allows you to send audio data.

Defined in​

odin.room.d.ts:626


getConnectionId()​

getConnectionId(): number

Retrieves the underlying connection identifier for the room.

Returns​

number

The connection ID, or 0 if not connected.

Defined in​

odin.room.d.ts:730


getConnectionStats()​

getConnectionStats(): null | OdinConnectionStats

Retrieves detailed connection statistics for the room. Useful for monitoring network quality and debugging connectivity issues.

Returns​

null | OdinConnectionStats

Connection statistics object, or null if not connected.

Defined in​

odin.room.d.ts:724


getJitterStats()​

getJitterStats(mediaId): null | OdinJitterStats

Retrieves jitter buffer statistics for a specific media stream. Useful for debugging audio quality issues.

Parameters​

• mediaId: number

The media ID to get jitter stats for.

Returns​

null | OdinJitterStats

Jitter statistics object, or null if decoder not found.

Defined in​

odin.room.d.ts:738


join()​

join(gatewayOrServerUrl, userData?): void

Joins the room with the given gateway URL and optional user data.

Parameters​

• gatewayOrServerUrl: string

• userData?: Uint8Array

The user data to send to the room. This can be used to identify the user.

Returns​

void

Defined in​

odin.room.d.ts:526


onAudioDataReceived()​

onAudioDataReceived(handler): void

Set handler for audio data events (for recording/processing).

Parameters​

• handler: OdinAudioDataReceivedEvent

Handler receiving { peerId, mediaId, samples16, samples32 }

Returns​

void

Defined in​

odin.room.d.ts:689


onConnectionStateChanged()​

onConnectionStateChanged(handler): void

Set handler for connection state changes.

Parameters​

• handler: OdinConnectionStateChangedEvent

Handler receiving { state, message }

Returns​

void

Defined in​

odin.room.d.ts:683


onJoined()​

onJoined(handler): void

Set handler for when room is successfully joined.

Parameters​

• handler: OdinJoinedEvent

Handler receiving { roomId, ownPeerId, room }

Returns​

void

Defined in​

odin.room.d.ts:641


onLeft()​

onLeft(handler): void

Set handler for when room is left.

Parameters​

• handler: OdinLeftEvent

Handler receiving { reason }

Returns​

void

Defined in​

odin.room.d.ts:647


onMediaActivity()​

onMediaActivity(handler): void

Set handler for media activity events (voice activity detection).

Parameters​

• handler: OdinMediaActivityEvent

Handler receiving { peerId, mediaId, state }

Returns​

void

Defined in​

odin.room.d.ts:707


onMediaStarted()​

onMediaStarted(handler): void

Set handler for media started events (when a peer starts streaming audio).

Parameters​

• handler: OdinMediaAddedEvent

Handler receiving { peerId, media }

Returns​

void

Defined in​

odin.room.d.ts:665


onMediaStopped()​

onMediaStopped(handler): void

Set handler for media stopped events.

Parameters​

• handler: OdinMediaRemovedEvent

Handler receiving { peerId, mediaId }

Returns​

void

Defined in​

odin.room.d.ts:671


onMessageReceived()​

onMessageReceived(handler): void

Set handler for message received events.

Parameters​

• handler: OdinMessageReceivedEvent

Handler receiving { senderPeerId, message }

Returns​

void

Defined in​

odin.room.d.ts:677


onPeerJoined()​

onPeerJoined(handler): void

Set handler for peer joined events.

Parameters​

• handler: OdinPeerJoinedEvent

Handler receiving { peerId, peer, userId, userData }

Returns​

void

Defined in​

odin.room.d.ts:653


onPeerLeft()​

onPeerLeft(handler): void

Set handler for peer left events.

Parameters​

• handler: OdinPeerLeftEvent

Handler receiving { peerId }

Returns​

void

Defined in​

odin.room.d.ts:659


onPeerTagsChanged()​

onPeerTagsChanged(handler): void

Set handler for peer tags changed events.

Parameters​

• handler: OdinPeerTagsChangedEvent

Handler receiving { peerId, tags }

Returns​

void

Defined in​

odin.room.d.ts:713


onPeerUserDataChanged()​

onPeerUserDataChanged(handler): void

Set handler for peer user data changed events.

Parameters​

• handler: OdinPeerUserDataChangedEvent

Handler receiving { peerId, userData }

Returns​

void

Defined in​

odin.room.d.ts:695


onRoomUserDataChanged()​

onRoomUserDataChanged(handler): void

Set handler for room user data changed events.

Parameters​

• handler: OdinRoomUserDataChangedEvent

Handler receiving { userData }

Returns​

void

Defined in​

odin.room.d.ts:701


removeEventListener()​

removeEventListener<Event>(eventName): void

Removes an event listener from the room for specific events.

Type Parameters​

• Event extends keyof OdinEvents

Parameters​

• eventName: Event

The event to remove the listener from (see keys of OdinEvents for possible values)

Returns​

void

Defined in​

odin.room.d.ts:546


sendMessage()​

sendMessage(message, peerIdList?): void

Sends a message to the room.

Parameters​

• message: Uint8Array

The message to send as a byte array.

• peerIdList?: number[]

The list of peer IDs to send the message to. If this is undefined, the message will be sent to all peers. If the list is defined and empty an error will be thrown.

Returns​

void

Defined in​

odin.room.d.ts:533


setCipher()​

setCipher(cipher): void

Sets the cipher for end-to-end encryption.

Parameters​

• cipher: OdinCipher

The cipher instance.

Returns​

void

Defined in​

odin.room.d.ts:592


setEventListener()​

setEventListener(callback): void

Sets a global event listener that received all events, this can be helpful for debugging. Please use addEventListener instead for production code.

Parameters​

• callback

The callback to call when the event is fired.

Returns​

void

Defined in​

odin.room.d.ts:552


setPositionScale()​

setPositionScale(scale): void

Sets the scaling factor for coordinates supplied to updatePosition, facilitating adaptation to your game's unique coordinate system requirements. Peers are visible to each other only within a unit circle of radius 1.0. When altering a peer's position, ensure the position is scaled such that the maximum distance remains one or less. This scaling can be performed manually or by specifying the multiplicative scale here.

Note: It's crucial to maintain consistent scaling across all client applications.

Parameters​

• scale: number

The new scaling factor to use.

Returns​

void

Defined in​

odin.room.d.ts:586


updateOwnUserData()​

updateOwnUserData(userData): void

Updates the peer user data of the local peer

Parameters​

• userData: Uint8Array

The new user data to set.

Returns​

void

Defined in​

odin.room.d.ts:558


updatePosition()​

updatePosition(x, y, z): void

Updates the three-dimensional position of the current peer in this room. The server utilizes the provided coordinates to perform automatic culling among peers in the same room, based on unit circles with a radius of 1.0. This feature is particularly beneficial in scenarios involving a large number of peers within the same room, enabling peers to interact or 'see' each other only when in close proximity. To modify the distance sensitivity for position updates, use setPositionScale.

Note: Use this before calling join to set the initial peer position upon connect.

Parameters​

• x: number

The new x position of the peer.

• y: number

The new y position of the peer.

• z: number

The new z position of the peer.

Returns​

void

Defined in​

odin.room.d.ts:574