@4players/odin
Version:
A cross-platform SDK enabling developers to integrate real-time VoIP chat technology into their projects
119 lines (118 loc) • 5.04 kB
JavaScript
"use strict";
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _VideoOutput_isPaused, _VideoOutput_isStarted, _VideoOutput_isStarting, _VideoOutput_mediaData;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VideoOutput = void 0;
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;
}
}
exports.VideoOutput = VideoOutput;
_VideoOutput_isPaused = new WeakMap(), _VideoOutput_isStarted = new WeakMap(), _VideoOutput_isStarting = new WeakMap(), _VideoOutput_mediaData = new WeakMap();