Skip to main content

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:408

Accessors

id

get id(): string

Gets the ID of the room.

Returns

string

Defined in

odin.room.d.ts:485


ownPeerId

get ownPeerId(): number

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

Returns

number

Defined in

odin.room.d.ts:490

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:429


close()

close(): void

Closes the room and disconnects from the server.

Returns

void

Defined in

odin.room.d.ts:480


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:499


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:415


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:435


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:422


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:441


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:475


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:447


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:463