UNPKG

@4players/odin

Version:

A cross-platform SDK enabling developers to integrate real-time VoIP chat technology into their projects

123 lines (122 loc) 3.63 kB
import { IOdinMediaEvents } from './types'; /** * Class describing a single media stream inside an `OdinRoom`. */ export declare class OdinMedia { private _id; private _peerId; private _remote; /** * An optional instance of `OdinAudioService` used for handling audio interactions. */ private _audioService?; /** * An instance of `EventTarget` for handling events related to this media. */ private _eventTarget; /** * A boolean that indicates if the media is sending/receiving data or not. */ private _active; /** * A boolean that indicates if the media is paused or not. */ private _paused; /** * Represents the volume of the media stream, default value is 1. */ private _volume; /** * Creates a new `OdinMedia` instance. * * @param _id The ID of the new media * @param _peerId The ID of the peer that owns the new media * @param _remote Wether or not the new media belongs to a remote peer * * @ignore */ constructor(_id: number, _peerId: number, _remote: boolean); /** * The ID of the media. */ get id(): number; /** * The ID of the peer that owns the media. */ get peerId(): number; /** * Indicates wether or not the media belongs to a remote peer. */ get remote(): boolean; /** * Set the paused flag of the media. * * NOTE: Important do not adjust this manually! */ set paused(paused: boolean); /** * Indicates wether or not the media is paused. */ get paused(): boolean; /** * Set the activity status of the media. * * NOTE: Important do not adjust this manually! */ set active(active: boolean); /** * Indicates wether or not the media is currently sending/receiving data. */ get active(): boolean; /** * Indicates whether or not the media is registered in the audio service instance (e.g. started). */ get started(): boolean; /** * An event target handler for the peer. * * @ignore */ get eventTarget(): EventTarget; /** * The individual playback volume of the media stream. */ get volume(): number; /** * Starts the media stream by initiating the encoder/decoder and adding it to the room if it belongs to the local peer. * * @returns A promise which yields when the request is resolved */ start(): Promise<void>; /** * Stops the media stream by terminating the encoder/decoder and removing it from the room if it belongs to the local peer. * * @returns A promise which yields when the request is resolved */ stop(): Promise<void>; /** * Paused the media stream on the server to stop receiving data on it. * * @returns A promise which yields when the request is resolved */ pause(): Promise<void>; /** * Paused the media stream on the server to start receiving data on it. * * @returns A promise which yields when the request is resolved */ resume(): Promise<void>; /** * Changes the playback volume of the media. * * @param volume The new volume (Default is 1) */ changeVolume(volume: number): void; /** * Registers to media events from `IOdinMediaEvents`. * * @param eventName The name of the event to listen to * @param handler The callback to handle the event */ addEventListener<Event extends keyof IOdinMediaEvents>(eventName: Event, handler: IOdinMediaEvents[Event]): void; }