@4players/odin
Version:
A cross-platform SDK enabling developers to integrate real-time VoIP chat technology into their projects
279 lines (278 loc) • 9.26 kB
TypeScript
import { IOdinAudioSettings, IOdinRoomEvents, OdinConnectionState } from './types';
import { OdinPeer } from './peer';
import { OdinMedia } from './media';
import { OdinStream } from './stream';
/**
* Class describing an `OdinRoom`.
*/
export declare class OdinRoom {
private _id;
private _user_id;
private _address;
private _mainStream;
/**
* An optional instance of `OdinAudioService` used for handling audio interactions.
*/
private _audioService?;
/**
* An instance of `EventTarget` for handling events related to this room.
*/
private _eventTarget;
/**
* The `OdinStream` instance representing the main connection for the room.
*/
private _roomStream;
/**
* The `OdinPeer` instance representing the current user within the room.
*/
private _ownPeer;
/**
* The three-dimensional position of the current user within the room.
*/
private _position;
/**
* The current connection state of the room, defaulting to 'disconnected'.
*/
private _connectionState;
/**
* The arbitrary user data for the room.
*/
private _data;
/**
* A Map storing all remote `OdinPeer` instances within the room, using the peer ID as the key.
*/
private _remotePeers;
/**
* The customer identifier to which this room is assigned.
*/
private _customer;
/**
* Creates a new `OdinRoom` instance.
*
* @param _id The ID of the new room
* @param _user_id The user ID specified in the authentication token
* @param _address The address of the ODIN SFU this room lives on
* @param _mainStream The main stream connection this room is based on
* @ignore
*/
constructor(_id: string, _user_id: string, _address: string, _mainStream: OdinStream);
/**
* The ID of the room.
*/
get id(): string;
/**
* The customer identifier this room is assigned to.
*/
get customer(): string;
/**
* The arbitrary user data of the room.
*/
get data(): Uint8Array;
/**
* The current state of the room stream connection.
*/
get connectionState(): OdinConnectionState;
/**
* Update the connection state of the room.
*/
private set connectionState(value);
/**
* An instance of your own `OdinPeer` in the room.
*/
get ownPeer(): OdinPeer;
/**
* A map of all remote `OdinPeer` instances in the room using the peer ID as index.
*/
get remotePeers(): Map<number, OdinPeer>;
/**
* The current three-dimensional position of our own `OdinPeer` in the room.
*/
get position(): [number, number, number];
/**
* An event target handler for the room.
*
* @ignore
*/
get eventTarget(): EventTarget;
/**
* The address of the voice server this room is living on.
*/
get serverAddress(): string;
/**
* Joins the room and returns your own peer instance after the room was successfully joined.
*
* @param userData Optional user data to set for the peer when connecting
* @param position Optional coordinates to set the three-dimensional position of the peer in the room when connecting
* @returns A promise of the own OdinPeer which yields when the room was joined
*/
join(userData?: Uint8Array, position?: [number, number, number]): Promise<OdinPeer>;
/**
* Changes the active capture stream (e.g. when switching to another input device).
*
* @param mediaStream The capture stream of the input device
*/
changeMediaStream(mediaStream: MediaStream): Promise<void>;
/**
* Creates a new local media using the specified stream.
*
* @param mediaStream The capture stream of the input device
* @param audioSettings Optional audio settings like VAD or master volume used to initialize audio
* @returns A promise of the newly created OdinMedia
*/
createMedia(mediaStream: MediaStream, audioSettings?: IOdinAudioSettings): Promise<OdinMedia>;
/**
* Adds a local media stream to the room.
*
* @param media The media instance to be added
* @ignore
*/
addMedia(media: OdinMedia): Promise<void>;
/**
* Removes a local media stream from the room.
*
* @param media The media instance to be removed
* @ignore
*/
removeMedia(media: OdinMedia): Promise<void>;
/**
* Pauses a media stream and stops receiving data on it.
*
* @param media The remote media instance or ID to be paused
* @ignore
*/
pauseMedia(media: OdinMedia): Promise<void>;
/**
* Pauses a media stream and stops receiving data on it.
*
* @param media The remote media instance to be paused
* @ignore
*/
resumeMedia(media: OdinMedia): Promise<void>;
/**
* Returns the `OdinMedia` instance matching the specified ID.
*
* @param id The media ID to search for
* @returns The media instance if available
*/
getMediaById(id: number): OdinMedia | undefined;
/**
* Returns the `OdinPeer` instance matching the specified ID.
*
* @param id The peer ID to search for
* @returns The peer instance if available
*/
getPeerById(id: number): OdinPeer | undefined;
/**
* Updates the three-dimensional position of our own `OdinPeer` in the room to apply server-side culling.
*
* @param offsetX The new X coordinate for the peers position in the room
* @param offsetY The new Y coordinate for the peers position in the room
* @param offsetZ The new Z coordinate for the peers position in the room
*/
setPosition(offsetX: number, offsetY: number, offsetZ: number): void;
/**
* Sends updated user data of your own peer to the server.
*/
flushOwnPeerDataUpdate(): Promise<void>;
/**
* Sends a message with arbitrary data to all peers in the room or optionally to a list of specified peers.
*
* @param message Byte array of arbitrary data to send
* @param targetPeerIds Optional list of target peer IDs
*/
sendMessage(message: Uint8Array, targetPeerIds?: number[]): Promise<void>;
/**
* Leaves the room and closes the connection to the server.
*
* @ignore
*/
disconnect(state?: OdinConnectionState): void;
/**
* Internal handler for room stream events.
*
* @private
*/
private streamHandler;
/**
* Internal handler for room updates.
*
* @private
*/
private roomUpdated;
/**
* Internal handler for peer updates.
*
* @private
*/
private peerUpdated;
/**
* Change the global master volume for the room (should be between 0 and 2).
*
* @param volume The new volume
*/
changeVolume(volume: number): void;
/**
* Creates a new peer instance and adds it to the room.
*
* @param peerId The ID of the peer
* @param userId The identifier of the peer specified during authentication
* @param medias A list of media IDs to initialize for the peer
* @param data The user data for the peer
*/
private addRemotePeer;
/**
* Removes the peer with the specified ID from the room.
*
* @param peerId The id of the peer to remove
*/
private removePeer;
/**
* Disables RNN-based voice activity detection.
*/
disableVAD(): void;
/**
* Enables RNN-based voice activity detection.
*/
enableVAD(): void;
/**
* Enables emitting of RNN-based voice activity detection statistics.
*/
startVADMeter(): void;
/**
* Disables emitting of RNN-based voice activity detection statistics.
*/
stopVADMeter(): void;
/**
* Updates thresholds for vice activity detection (between 0 and 1).
*
* @param attackProbability Voice probability value when the VAD should engage
* @param releaseProbability Voice probability value when the VAD should disengage
*/
updateVADThresholds(attackProbability: number, releaseProbability?: number): void;
/**
* Disables RNN-based voice activity detection.
*/
disableVolumeGate(): void;
/**
* Enables RNN-based voice activity detection.
*/
enableVolumeGate(): void;
/**
* Updates thresholds for the input volume gate (between -90 and 0).
*
* @param attackLoudness Root mean square power (dBFS) when the volume gate should engage
* @param releaseLoudness Root mean square power (dBFS) when the volume gate should disengage
*/
updateVolumeGateThresholds(attackLoudness: number, releaseLoudness?: number): void;
/**
* Returns the current voice processing config for VAD and volume gate.
*/
getAudioSettings(): IOdinAudioSettings | undefined;
/**
* Register to peer events from `IOdinRoomEvents`.
*
* @param eventName The name of the event to listen to
* @param handler The callback to handle the event
*/
addEventListener<OdinEvent extends keyof IOdinRoomEvents>(eventName: OdinEvent, handler: IOdinRoomEvents[OdinEvent]): void;
}