"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 Semifunctional_1 = require("../../../../../Class/Semifunctional");
const ImageCapture_1 = require("../../../../../wrap/ImageCapture");
const _ids_1 = require("../../../../_ids");
class ImageCapture_ extends Semifunctional_1.Semifunctional {
    constructor(system) {
        super({
            fi: ['init', 'track'],
            fo: ['camera'],
            i: ['done'],
            o: [],
        }, {
            input: {
                track: {
                    ref: true,
                },
            },
            output: {
                camera: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_IMAGE_CAPTURE);
        this.addListener('destroy', () => { });
    }
    f({ init, track }, done) {
        return __awaiter(this, void 0, void 0, function* () {
            const { api: { window: { ImageCapture }, }, } = this.__system;
            if (!ImageCapture) {
                done(undefined, 'ImageCapture API is not supported');
                return;
            }
            const _track = yield track.mediaStreamTrack();
            _track.onmute = () => {
                // console.log('onmute')
            };
            _track.onunmute = () => {
                // console.log('onunmute')
            };
            _track.onended = () => {
                // console.log('onended')
            };
            // @ts-ignore
            const imageCapture = new ImageCapture(_track);
            const camera = (0, ImageCapture_1.wrapImageCapture)(imageCapture, this.__system);
            done({ camera });
        });
    }
    onIterDataInputData(name, data) {
        // if (name === 'done') {
        this._forward_all_empty();
        this._backward_all();
        this._backward('done');
        // }
    }
}
exports.default = ImageCapture_;
//# sourceMappingURL=index.js.map