UNPKG

@4players/odin

Version:

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

103 lines (102 loc) 3.89 kB
var _VideoOutput_isPaused, _VideoOutput_isStarted, _VideoOutput_starting, _VideoOutput_mediaData; import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; export class VideoOutput { constructor(mediaData, playback, peer, room) { this.playback = playback; this.peer = peer; this.room = room; this.kind = 'video-output'; _VideoOutput_isPaused.set(this, true); _VideoOutput_isStarted.set(this, false); _VideoOutput_starting.set(this, false); _VideoOutput_mediaData.set(this, void 0); __classPrivateFieldSet(this, _VideoOutput_mediaData, mediaData, "f"); } /** * Indicates whether the process has started. * * @return {boolean} True if the process has started, otherwise false. */ get isStarted() { return __classPrivateFieldGet(this, _VideoOutput_isStarted, "f"); } /** * Starts the video output process if it is not already started. * Ensures the method is not re-triggered while in progress. * * @return {Promise<void>} A promise that resolves once the video output process is successfully started. */ async start() { if (__classPrivateFieldGet(this, _VideoOutput_starting, "f") || __classPrivateFieldGet(this, _VideoOutput_isStarted, "f")) return; __classPrivateFieldSet(this, _VideoOutput_starting, true, "f"); try { await this.room.startVideoOutput(this); __classPrivateFieldSet(this, _VideoOutput_isStarted, true, "f"); __classPrivateFieldSet(this, _VideoOutput_isPaused, false, "f"); } finally { __classPrivateFieldSet(this, _VideoOutput_starting, false, "f"); } } get isPaused() { return __classPrivateFieldGet(this, _VideoOutput_isPaused, "f"); } async resume() { if (__classPrivateFieldGet(this, _VideoOutput_starting, "f") || !__classPrivateFieldGet(this, _VideoOutput_isPaused, "f")) return; __classPrivateFieldSet(this, _VideoOutput_starting, true, "f"); try { await this.room.startVideoOutput(this); __classPrivateFieldSet(this, _VideoOutput_isStarted, true, "f"); __classPrivateFieldSet(this, _VideoOutput_isPaused, false, "f"); } catch (e) { console.error(e); } finally { __classPrivateFieldSet(this, _VideoOutput_starting, false, "f"); } } async pause() { await this.room.pauseMedia(this.mediaId); this.room.stopVideoOutput(this); __classPrivateFieldSet(this, _VideoOutput_isPaused, true, "f"); } /** * Retrieves the unique identifier (UID) associated with the playback. * * @return {string} The UID of the playback. */ get uid() { return this.playback.uid; } /** * Retrieves the media ID associated with this instance. * * @return {number} The unique identifier of the media. */ get mediaId() { return __classPrivateFieldGet(this, _VideoOutput_mediaData, "f").id; } get id() { return this.playback.id; } /** * GEt the current MediaStream associated with playback. * * @return {MediaStream | undefined} The current MediaStream if available, otherwise undefined. */ get mediaStream() { return this.playback.mediaStream; } /** * The custom type can be provided by the remote's VideoInput to help understanding its purpose. * * @return {string | undefined} The custom type value if available; otherwise, undefined. */ get customType() { return this.playback.customType; } } _VideoOutput_isPaused = new WeakMap(), _VideoOutput_isStarted = new WeakMap(), _VideoOutput_starting = new WeakMap(), _VideoOutput_mediaData = new WeakMap();