"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Holder_1 = require("../../../../../Class/Holder");
const Source_1 = require("../../../../../Source");
const MediaStream_1 = require("../../../../../wrap/MediaStream");
const _ids_1 = require("../../../../_ids");
class CaptureStream extends Holder_1.Holder {
    constructor(system) {
        super({
            fi: ['source', 'opt'],
            fo: ['stream'],
            i: [],
            o: [],
        }, {
            input: {
                source: {
                    ref: true,
                },
            },
            output: {
                stream: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_CAPTURE_STREAM, 'stop');
        this.__ = ['U'];
        this._stream = new Source_1.Source();
    }
    async f({ source, opt }, done, fail) {
        let _stream;
        try {
            _stream = await source.captureStream(opt);
        }
        catch (err) {
            fail(err.message);
            return;
        }
        const stream = (0, MediaStream_1.wrapMediaStream)(_stream, this.__system);
        done({ stream });
    }
    d() {
        this._stream.set(null);
    }
    mediaStream(callback) {
        return this._stream.connect(callback);
    }
}
exports.default = CaptureStream;
//# sourceMappingURL=index.js.map