UNPKG

@4players/odin

Version:

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

105 lines (104 loc) 3.89 kB
var _VideoOutput_isPaused, _VideoOutput_isStarted, _VideoOutput_isStarting, _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_isStarting.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_isStarting, "f") || __classPrivateFieldGet(this, _VideoOutput_isStarted, "f")) return; __classPrivateFieldSet(this, _VideoOutput_isStarting, true, "f"); try { await this.room.startVideoOutput(this); __classPrivateFieldSet(this, _VideoOutput_isStarted, true, "f"); __classPrivateFieldSet(this, _VideoOutput_isPaused, false, "f"); } finally { __classPrivateFieldSet(this, _VideoOutput_isStarting, false, "f"); } } get isPaused() { return __classPrivateFieldGet(this, _VideoOutput_isPaused, "f"); } async resume() { if (!__classPrivateFieldGet(this, _VideoOutput_isPaused, "f") || !this.isStarted) { return; } try { __classPrivateFieldSet(this, _VideoOutput_isPaused, false, "f"); await this.room.resumeMedia(this.mediaId); } catch (e) { __classPrivateFieldSet(this, _VideoOutput_isPaused, true, "f"); console.error(e); } } async pause() { if (__classPrivateFieldGet(this, _VideoOutput_isPaused, "f") || !this.isStarted) { return; } try { __classPrivateFieldSet(this, _VideoOutput_isPaused, true, "f"); await this.room.pauseMedia(this.mediaId); } catch (e) { __classPrivateFieldSet(this, _VideoOutput_isPaused, false, "f"); console.error(e); } } /** * 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 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_isStarting = new WeakMap(), _VideoOutput_mediaData = new WeakMap();