"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 });
const Element_1 = require("../../../../../Class/Element");
const _ids_1 = require("../../../../_ids");
class Video extends Element_1.Element_ {
    constructor(system) {
        super({
            i: ['src', 'stream', 'style', 'controls', 'currentTime'],
            o: [],
        }, {
            input: {
                stream: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_VIDEO);
        this.__ = [...this.__, 'CS', 'PS', 'IM', 'ME'];
        this._defaultState = {};
    }
    captureStream({ frameRate }) {
        return __awaiter(this, void 0, void 0, function* () {
            // TODO
            // const stream = await this._element.captureStream({ frameRate })
            // throw new APINotSupportedError('Video Capture')
            const localComponents = this.__system.getLocalComponents(this.__global_id);
            const firstLocalComponent = localComponents[0];
            if (firstLocalComponent) {
                return firstLocalComponent.$element.captureStream({ frameRate });
            }
            return new Promise((resolve) => {
                this.__system.emitter.addListener(this.__global_id, (localComponent) => {
                    resolve(localComponent.$element.captureStream({ frameRate }));
                });
            });
        });
    }
    image() {
        return __awaiter(this, void 0, void 0, function* () {
            const { getLocalComponents } = this.__system;
            const localComponents = getLocalComponents(this.__global_id);
            if (localComponents.length === 0) {
                return null;
            }
            const localComponent = localComponents[0];
            return localComponent.$element;
        });
    }
    requestPictureInPicture(callback) {
        // TODO
    }
    mediaPlay() {
        this.emit('call', { method: 'play', data: [] });
    }
    mediaPause() {
        this.emit('call', { method: 'pause', data: [] });
    }
}
exports.default = Video;
//# sourceMappingURL=index.js.map