UNPKG

@skyway-sdk/core

Version:

The official Next Generation JavaScript SDK for SkyWay

81 lines 3.62 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LocalVideoStream = void 0; const common_1 = require("@skyway-sdk/common"); const errors_1 = require("../../../errors"); const util_1 = require("../../../util"); const media_1 = require("./media"); const log = new common_1.Logger('packages/core/src/media/stream/local/video.ts'); class LocalVideoStream extends media_1.LocalMediaStreamBase { constructor(track, options = {}) { super(track, 'video', options); this.contentType = 'video'; this._isEnabled = true; this._promiseQueue = new common_1.PromiseQueue(); if (track.kind !== 'video') { throw (0, util_1.createError)({ operationName: 'LocalVideoStream.constructor', path: log.prefix, info: errors_1.errors.invalidTrackKind, payload: { track }, }); } log.debug('LocalVideoStream spawned', this.toJSON()); } /**@internal */ setEnabled(enabled) { return __awaiter(this, void 0, void 0, function* () { yield this._promiseQueue.push(() => __awaiter(this, void 0, void 0, function* () { // mute if (this._isEnabled === true && enabled === false) { this._isEnabled = enabled; this._disable('video'); log.debug('stopped', this.toJSON()); } // unmute else if (this._isEnabled === false && enabled === true) { this._isEnabled = enabled; if (this._options.stopTrackWhenDisabled) { const track = this._options.isDisplayMedia === true ? yield this.enableDisplay() : yield this.enableCamera(); this._updateTrack(track); this._onEnableChanged.emit(track); } else if (this._oldTrack) { this._updateTrack(this._oldTrack); this._onEnableChanged.emit(this._oldTrack); } log.debug('resumed', this.toJSON()); } })); }); } enableCamera() { return __awaiter(this, void 0, void 0, function* () { const [track] = (yield navigator.mediaDevices.getUserMedia({ video: this.trackConstraints, })).getVideoTracks(); return track; }); } enableDisplay() { return __awaiter(this, void 0, void 0, function* () { const [track] = (yield navigator.mediaDevices.getDisplayMedia({ video: this.trackConstraints, })).getVideoTracks(); return track; }); } } exports.LocalVideoStream = LocalVideoStream; //# sourceMappingURL=video.js.map