@4players/odin
Version:
A cross-platform SDK enabling developers to integrate real-time VoIP chat technology into their projects
133 lines (132 loc) • 3.77 kB
TypeScript
import { IOdinPeerEvents } from './types';
import { OdinMedia } from './media';
import { OdinStream } from './stream';
/**
* Class describing a single peer inside an `OdinRoom`.
*/
export declare class OdinPeer {
private _roomStream;
private _id;
private _userId;
private _remote;
/**
* An optional instance of `OdinAudioService` used for handling audio interactions.
*/
private _audioService?;
/**
* An instance of `EventTarget` for handling events related to this peer.
*/
private _eventTarget;
/**
* Free media IDs available to this peer.
*/
private _freeMediaIds;
/**
* Map of currently active media instances associated with this peer.
*/
private _activeMedias;
/**
* User data associated with the peer.
*/
private _data;
/**
* Creates a new `OdinPeer` instance.
*
* @param _id The ID of the new peer
* @param _userId The user ID of the new peer
* @param _remote Indicates, whether the peer is a remote peer or not
* @ignore
*/
constructor(_roomStream: OdinStream, _id: number, _userId: string, _remote: boolean);
/**
* The ID of the peer.
*/
get id(): number;
/**
* The identifier of the peer.
*/
get userId(): string;
/**
* Indicates, whether the peer is a remote peer or not.
*/
get remote(): boolean;
/**
* A list of media instances owned by the peer.
*/
get medias(): Map<number, OdinMedia>;
/**
* Set updated user data for the peer.
*/
set data(data: Uint8Array);
/**
* The arbitrary user data of the peer.
*/
get data(): Uint8Array;
/**
* An event target handler for the peer.
*
* @ignore
*/
get eventTarget(): EventTarget;
/**
* Set the list of media IDs assigned by the server.
*
* @ignore
*/
setFreeMediaIds(ids: number[]): void;
/**
* Creates a local media, configures audio capture/playback and returns the new `OdinMedia` instance.
*/
createMedia(): OdinMedia;
/**
* Adds a media to the list of active medias and starts decoding.
*
* @param media The media instance to add
*/
addMedia(media: OdinMedia): void;
/**
* Removes a media from the list of active medias and stops decoding.
*
* @param media The media instance to remove
*/
removeMedia(media: OdinMedia): void;
/**
* Removes a media from the list of active medias by the given ID and stops decoding.
*
* @param id The media ID to remove
*/
removeMediaById(id: number): void;
/**
* Pops the next media from the free medias array.
*/
private takeFreeMedia;
/**
* Starts all active medias or a list of specific active medias.
*
* @param mediaIds Optional list of media IDs to start
*/
startMedias(mediaIds?: number[]): Promise<void>;
/**
* Stops all active medias or a list of specific active medias.
*
* @param mediaIds Optional list of media IDs to stop
*/
stopMedias(mediaIds?: number[]): Promise<void>;
/**
* Sends a message with arbitrary data to this peer.
*
* @param message Byte array of arbitrary data to send
*/
sendMessage(message: Uint8Array): Promise<void>;
/**
* Sends user data of the peer to the server.
*/
update(): Promise<void>;
/**
* Registers to peer events from `IOdinPeerEvents`.
*
* @param eventName The name of the event to listen to
* @param handler The callback to handle the event
*/
addEventListener<Event extends keyof IOdinPeerEvents>(eventName: Event, handler: IOdinPeerEvents[Event]): void;
}