Developer Documentation

OdinRoom

export 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.

Constructor

NameTypeDescription
constructorOdinRoomCreates 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.

Properties

NameTypeDescription
idstringGets the ID of the room.
ownPeerIdnumberGets the ID of the local peer joined to the room.

Public Methods

NameTypeDescription
addEventListenervoidAdds an event listener to the room for specific events.
closevoidCloses the room and disconnects from the server.
createAudioStreamOdinMediaCreates a local audio stream and adds it to the room. An OdinMedia object will be returned that allows you to send audio data.
joinvoidJoins the room with the given gateway URL and optional user data.
removeEventListenervoidRemoves an event listener from the room for specific events.
sendMessagevoidSends a message to the room.
setEventListenervoidSets a global event listener that received all events, this can be helpful for debugging. Please use addEventListener instead for production code.
setPositionScalevoidSets 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.
updateOwnUserDatavoidUpdates the peer user data of the local peer
updatePositionvoidUpdates 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.