Class: Room
Represents a room within the Odin framework, managing connections, peers, and media.
The Room
class provides functionality to join and interact with an audio/video room,
monitor its state, handle events, and manage media streams.
This class extends OdinEventTarget
to handle custom event types and listeners.
Extends
Constructors
new Room()
new Room():
Room
Returns
Overrides
Defined in
ari/lib/api/room/index.d.ts:184
Properties
defaultGateway
readonly
defaultGateway:"https://gateway.odin.4players.io"
="https://gateway.odin.4players.io"
The default gateway if no gateway was specified when joining the room.
Defined in
ari/lib/api/room/index.d.ts:43
onAudioActivity()?
optional
onAudioActivity: (payload
) =>void
A callback function that is invoked when audio activity occurs and voice activity detection (VAD) was set to true.
Parameters
• payload: AudioActivityPayload
An object containing the AudioMedia.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:102
onAudioInputStarted()?
optional
onAudioInputStarted: (payload
) =>void
A callback function that gets invoked when an AudioInput was started.
Parameters
• payload: AudioInputPayload
An object containing the AudioInput that was started.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:141
onAudioInputStopped()?
optional
onAudioInputStopped: (payload
) =>void
A callback function that gets invoked when an AudioInput was stopped.
Parameters
• payload: AudioInputPayload
An object containing the AudioInput that was stopped.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:147
onAudioOutputStarted()?
optional
onAudioOutputStarted: (payload
) =>void
A callback function that gets invoked when an AudioOutput was started.
Parameters
• payload: AudioOutputPayload
An object containing the AudioOutput that was started.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:153
onAudioOutputStopped()?
optional
onAudioOutputStopped: (payload
) =>void
A callback function that gets invoked when an AudioOutput was stopped.
Parameters
• payload: AudioOutputPayload
An object containing the AudioOutput that was stopped.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:159
onAudioPowerLevel()?
optional
onAudioPowerLevel: (payload
) =>void
A callback function invoked when there is an update to the audio power level in rmsDBFS. This function can be used to handle or process audio activity, such as monitoring sound levels or visualizing audio input.
Parameters
• payload: AudioActivityPayload
An object containing the AudioMedia.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:110
onAudioStats()?
optional
onAudioStats: (payload
) =>void
Parameters
• payload: JitterStats
Returns
void
Defined in
ari/lib/api/room/index.d.ts:117
onConnectionStats()?
optional
onConnectionStats: (payload
) =>void
A callback function invoked to handle connection statistics.
Parameters
• payload: ConnectionStats
An object containing the connection statistics details.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:123
onDataChanged()?
optional
onDataChanged: (payload
) =>void
A callback function that is invoked whenever the data of the room changed. This can only be done via admin tokens.
Parameters
• payload: RoomDataChangedPayload
An object containing the room.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:78
onJoined()?
optional
onJoined: (payload
) =>void
A callback function that is invoked when this room was joined. Also gets called after a reconnect was successfully performed.
Parameters
• payload: JoinedPayload
An object containing the peer and the room.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:58
onLeft()?
optional
onLeft: (payload
) =>void
A callback function that is invoked, when the room was disconnected by the server.
Parameters
• payload: LeftPayload
An object containing the room and the reason.
Returns
void
TODO
Check if it makes sense to call this method also by user disconnects.
Defined in
ari/lib/api/room/index.d.ts:65
onMediaStarted()?
optional
onMediaStarted: (payload
) =>void
A callback function that gets invoked when a new audio or video media was started.
Parameters
• payload: MediaPayload
An object containing the media that was started.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:129
onMediaStopped()?
optional
onMediaStopped: (payload
) =>void
A callback function that gets invoked when an audio or video media was stopped.
Parameters
• payload: MediaPayload
An object containing the media that was stopped.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:135
onMessageReceived()?
optional
onMessageReceived: (payload
) =>void
A callback function that gets invoked when a message is received.
Parameters
• payload: MessageReceivedPayload
An object containing the room, peer and message.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:116
onPeerJoined()?
optional
onPeerJoined: (payload
) =>void
A callback function that is invoked when a new peer joins.
Parameters
• payload: PeerJoinedPayload
An object containing the peer and the room.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:84
onPeerLeft()?
optional
onPeerLeft: (payload
) =>void
A callback function that is invoked when a peer leaves.
Parameters
• payload: PeerLeftPayload
An object containing the peer and the room.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:90
onStatusChanged()?
optional
onStatusChanged: (payload
) =>void
A callback function invoked whenever the status of a room changes.
Parameters
• payload: RoomStatusChangedPayload
The payload containing details about the room's status change.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:71
onUserDataChanged()?
optional
onUserDataChanged: (payload
) =>void
A callback function invoked when user data is changed.
Parameters
• payload: UserDataChangedPayload
An object containing the peer and the room.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:96
onVideoInputStarted()?
optional
onVideoInputStarted: (payload
) =>void
A callback function that gets invoked when a VideoInput was started.
Parameters
• payload: VideoInputPayload
An object containing the VideoInput that was started.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:177
onVideoInputStopped()?
optional
onVideoInputStopped: (payload
) =>void
A callback function that gets invoked when a VideoInput was stopped.
Parameters
• payload: VideoInputPayload
An object containing the VideoInput that was stopped.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:183
onVideoOutputStarted()?
optional
onVideoOutputStarted: (payload
) =>void
A callback function that gets invoked when a VideoOutput was started.
Parameters
• payload: VideoOutputPayload
An object containing the VideoOutput that was started.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:165
onVideoOutputStopped()?
optional
onVideoOutputStopped: (payload
) =>void
A callback function that gets invoked when a VideoOutput was stopped.
Parameters
• payload: VideoOutputPayload
An object containing the VideoOutput that was stopped.
Returns
void
Defined in
ari/lib/api/room/index.d.ts:171
outputActivityInterval
outputActivityInterval:
number
Interval how often the AudioActivity of Outputs is dispatched. The lower the value, the more accurate the indicator is at the cost of performance.
Defined in
ari/lib/api/room/index.d.ts:52
rmsDBFSInterval
rmsDBFSInterval:
number
Interval how often the AudioPowerLevel Event is dispatched.
Defined in
ari/lib/api/room/index.d.ts:47
Accessors
address
get
address():string
Address of the SFU (Voice Server) which was either assigned by the gateway or provided by the token when joining the room.
Returns
string
The address of the sfu if available, otherwise returns an empty string.
Defined in
ari/lib/api/room/index.d.ts:221
audioInputs
get
audioInputs():AudioInput
[]
Retrieves the available audio input devices that are assigned to this room.
Returns
An array of AudioInput objects representing the currently available audio inputs.
Defined in
ari/lib/api/room/index.d.ts:310
audioOutputs
get
audioOutputs():AudioOutput
[]
Retrieves a list of all AudioOutputs that are assigned to this room.
Returns
An array of AudioOutput devices filtered from the outputs list.
Defined in
ari/lib/api/room/index.d.ts:288
cipher
get
cipher():Cipher
Retrieves the cipher associated with the current room, if available.
Returns
Cipher
The cipher object if it exists; otherwise, undefined.
Defined in
ari/lib/api/room/index.d.ts:203
connectionStats
get
connectionStats():ConnectionStats
Retrieves connection statistics for the current room.
Returns
ConnectionStats
An object containing the connection statistics, including:
bytesSent
: Total bytes sent.bytesReceived
: Total bytes received.packetsSent
: Total packets sent.packetsReceived
: Total packets received.rtt
: Round-trip time in milliseconds. If the room isn't connected, returns default stats with all values set to 0.
Defined in
ari/lib/api/room/index.d.ts:215
customer
get
customer():string
Retrieves the customer ID associated with the current token, if available.
Returns
string
The customer ID as a string if present, otherwise undefined.
Defined in
ari/lib/api/room/index.d.ts:246
id
get
id():string
The id of the room. If the room was not joined, the id is undefined as the id is provided by the token provided when joining.
Returns
string
The unique identifier of the object.
Defined in
ari/lib/api/room/index.d.ts:191
ownPeer
get
ownPeer():LocalPeer
Retrieves the "own" Peer instance associated with the current ownPeerId
while connected.
Returns
The Peer instance if it exists, or undefined
if not found.
Defined in
ari/lib/api/room/index.d.ts:239
ownPeerId
get
ownPeerId():number
The id of the own peer. Id 0 means not connected.
Returns
number
The ID of the own peer.
Defined in
ari/lib/api/room/index.d.ts:227
peers
get
peers():Map
<number
,LocalPeer
|RemotePeer
>
A collection of peers.
Returns
Map
<number
, LocalPeer
| RemotePeer
>
A map containing peers with their numeric IDs as keys.
Defined in
ari/lib/api/room/index.d.ts:233
position
get
position(): [number
,number
,number
]
Retrieves the current position as a 3D coordinate.
Returns
[number
, number
, number
]
An array containing three numbers representing the x, y, and z coordinates of the position.
Defined in
ari/lib/api/room/index.d.ts:252
remotePeers
get
remotePeers():Map
<number
,RemotePeer
>
Returns
Map
<number
, RemotePeer
>
Defined in
ari/lib/api/room/index.d.ts:240
roomData
get
roomData():Uint8Array
Gets the room data.
Returns
Uint8Array
The room data as a Uint8Array or undefined if no data is available.
Defined in
ari/lib/api/room/index.d.ts:258
status
get
status():RoomStatus
Retrieves the current status of the room.
set
status(value
):void
Parameters
• value: RoomStatus
Returns
The current status of the room.
Defined in
ari/lib/api/room/index.d.ts:282
token
get
token():RoomToken
The latest token (inclusive reconnect tokens).
Returns
RoomToken
The current RoomToken if available, otherwise undefined.
Defined in
ari/lib/api/room/index.d.ts:197
userData
get
userData():Uint8Array
Retrieves the own user data.
set
userData(data
):void
Sets the user data of the own peer with the provided Uint8Array.
Parameters
• data: Uint8Array
The data to be set as user data.
Returns
Uint8Array
The user data as a Uint8Array.
Defined in
ari/lib/api/room/index.d.ts:270
videoOutputs
get
videoOutputs():VideoOutput
[]
Retrieves a list of VideoOutput devices that are assigned to this room.
This method filters the available outputs to return only those categorized as VideoOutput devices.
Returns
An array of VideoOutput devices.
Defined in
ari/lib/api/room/index.d.ts:297
volume
get
volume():OutputVolume
Retrieves the volume of the current instance.
Returns
The current volume value.
Defined in
ari/lib/api/room/index.d.ts:276
Methods
addAudioInput()
addAudioInput(
input
):Promise
<void
>
Adds an AudioInput to start streaming.
Parameters
• input: AudioInput
The AudioInput instance to be added.
Returns
Promise
<void
>
Resolves when the AudioInput is successfully added.
Throws
Will throw an error if no audio plugin is available.
Defined in
ari/lib/api/room/index.d.ts:339
addEventListener()
addEventListener<
OdinEventType
>(eventName
,handler
,options
?):void
Type Parameters
• OdinEventType extends keyof RoomEvents
Parameters
• eventName: OdinEventType
• handler: RoomEvents
[OdinEventType
]
• options?: boolean
| AddEventListenerOptions
Returns
void
Inherited from
OdinEventTarget
.addEventListener
Defined in
ari/lib/utils/odin-event-target.d.ts:26
addVideoInput()
addVideoInput(
input
):Promise
<void
>
Adds a vVideoInput to start streaming.
Parameters
• input: VideoInput
The VideoInput source to be added.
Returns
Promise
<void
>
Resolves when the VideoInput has been successfully added to the room.
Defined in
ari/lib/api/room/index.d.ts:331
dispatchEvent()
dispatchEvent<
T
>(event
):void
Type Parameters
• T extends OdinEvent
<any
>
Parameters
• event: T
Returns
void
Inherited from
Defined in
ari/lib/utils/odin-event-target.d.ts:27
flushUserData()
flushUserData():
Promise
<void
>
Flushes the current user's data by sending an update request to the server. Ensures the room is joined before proceeding with the operation.
Returns
Promise
<void
>
A promise that resolves once the user data update request is completed.
Defined in
ari/lib/api/room/index.d.ts:414
getAudioOutputById()
getAudioOutputById(
mediaId
):AudioOutput
Retrieves an AudioOutput device by its media ID.
Parameters
• mediaId: number
The media id of the desired AudioOutput.
Returns
The AudioOutput object if found, otherwise undefined.
Defined in
ari/lib/api/room/index.d.ts:317
getVideoOutputById()
getVideoOutputById(
mediaId
):VideoOutput
Retrieves an VideoOutput device by its media ID.
Parameters
• mediaId: number
The media id of the desired VideoOutput.
Returns
The VideoOutput object if found, otherwise undefined.
Defined in
ari/lib/api/room/index.d.ts:324
join()
join(
token
,options
?):Promise
<void
>
Joins the room using the provided token and options.
Parameters
• token: string
The token that was generated with an access key and provided to the app.
• options?: JoinParams
An optional object containing additional parameters for joining the room.
Returns
Promise
<void
>
Resolves when the join request is successful and the room is connected.
Throws
Throws an error if the room joining process fails.
Defined in
ari/lib/api/room/index.d.ts:400
leave()
leave(
reason
?):void
Disconnects the room resets the connection state.
Parameters
• reason?: string
The reason for leaving the room.
Returns
void
Does not return a value.
Defined in
ari/lib/api/room/index.d.ts:407
pauseMedia()
pauseMedia(
mediaId
):Promise
<void
>
Pauses a remote media on the audio server that was paused before. The MediaID can be found at the AudioOutput of a peer.
Parameters
• mediaId: number
The id of the media to be paused.
Returns
Promise
<void
>
Resolves when the media is successfully paused or logs a warning if an error occurs.
TODO
Add a pause method to peers.
Defined in
ari/lib/api/room/index.d.ts:449
removeAudioInput()
removeAudioInput(
input
):void
Removes the specified AudioInput and stops streaming.
Parameters
• input: AudioInput
The AudioInput instance to be removed.
Returns
void
Does not return a value.
Defined in
ari/lib/api/room/index.d.ts:346
removeEventListener()
removeEventListener<
OdinEventType
>(type
,callback
):void
Type Parameters
• OdinEventType extends keyof RoomEvents
Parameters
• type: string
| OdinEventType
• callback: EventListenerOrEventListenerObject
| RoomEvents
[OdinEventType
]
Returns
void
Inherited from
OdinEventTarget
.removeEventListener
Defined in
ari/lib/utils/odin-event-target.d.ts:28
removeVideoInput()
removeVideoInput(
input
):void
Removes the specified VideoInput and stops streaming.
Parameters
• input: VideoInput
The VideoInput instance to be removed.
Returns
void
Does not return a value.
Defined in
ari/lib/api/room/index.d.ts:353
request()
request<
Name
>(name
,properties
):Promise
<void
>
Send a rpc to the SFU.
Type Parameters
• Name extends "Hello"
| "UpdatePeer"
| "StartMedia"
| "StopMedia"
| "PauseMedia"
| "ResumeMedia"
| "SetPeerPosition"
| "SendMessage"
Parameters
• name: Name
The name of the command to be executed. Must be a key of RoomCommands.
• properties: TypeOf
<object
[Name
]["request"
]>
The properties required for the specified command.
Returns
Promise
<void
>
A promise that resolves when the request is successfully processed.
Defined in
ari/lib/api/room/index.d.ts:422
resumeMedia()
resumeMedia(
mediaId
):Promise
<void
>
Resumes a remote media on the audio server that was paused before. The MediaID can be found at the AudioOutput of a peer.
Parameters
• mediaId: number
The unique identifier of the media to resume.
Returns
Promise
<void
>
A promise that resolves when the media is successfully resumed or rejects with an error.
Defined in
ari/lib/api/room/index.d.ts:440
sendMessage()
sendMessage(
message
,targetPeerIds
?):Promise
<void
>
Sends a message with arbitrary data to all peers in the room or optionally to a list of specified peers.
Parameters
• message: Uint8Array
The message content to be sent.
• targetPeerIds?: number
[]
An optional array of peer IDs to specify the message recipients. If not provided, the message will be broadcasted to all peers.
Returns
Promise
<void
>
A promise that resolves once the message has been successfully sent. If the client is not connected or not in the room, an error will be thrown.
Defined in
ari/lib/api/room/index.d.ts:432
setAudioOutputDevice()
setAudioOutputDevice(
device
?):Promise
<void
>
Sets the audio output device to the specified device. Currently, the same audio output is used across all rooms (in the same plugin that was used).
Parameters
• device?: DeviceParameters
The parameters of the audio output device to be set.
Returns
Promise
<void
>
A promise that resolves when the audio output device has been successfully set.
Defined in
ari/lib/api/room/index.d.ts:375
setPosition()
setPosition(
offsetX
,offsetY
,offsetZ
):Promise
<void
>
Updates the position of the peer within the room.
Parameters
• offsetX: number
The X-coordinate of the new position.
• offsetY: number
The Y-coordinate of the new position.
• offsetZ: number
The Z-coordinate of the new position.
Returns
Promise
<void
>
A promise that resolves when the position has been successfully updated.
Throws
If the room is not joined.
Defined in
ari/lib/api/room/index.d.ts:385
setVolume()
setVolume(
value
):Promise
<void
>
Sets the volume for the audio outputs.
Parameters
• value: number
| OutputVolume
The volume level to set.
Returns
Promise
<void
>
A promise that resolves when the volume is set for all audio outputs.
Defined in
ari/lib/api/room/index.d.ts:304
startVideoOutput()
startVideoOutput(
output
):Promise
<void
>
Starts the specified VideoOutput. After the VideoOutput was started, its MediaStream will be available.
Parameters
• output: VideoOutput
The VideoOutput object to start. The output must already exist in the room.
Returns
Promise
<void
>
A promise that resolves when the video output is successfully started.
Defined in
ari/lib/api/room/index.d.ts:360
stopVideoOutput()
stopVideoOutput(
output
):void
Stops the VideoOutput and stops streaming.
Parameters
• output: VideoOutput
The VideoOutput object containing the media and playback information.
Returns
void
No return value.
Defined in
ari/lib/api/room/index.d.ts:367