"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Functional_1 = require("../../../../../../Class/Functional");
const _ids_1 = require("../../../../../_ids");
class AudioTarget extends Functional_1.Functional {
    constructor(system) {
        super({
            i: ['id', 'stream'],
            o: [],
        }, {
            input: {
                stream: {
                    ref: true,
                },
            },
        }, system, _ids_1.ID_AUDIO_TARGET);
    }
    async f({ stream, id }, done, fail) {
        const { api: { window: { Audio }, }, } = this.__system;
        this._audio = new Audio();
        this._audio.srcObject = await stream.mediaStream();
        try {
            await this._audio.setSinkId(id);
        }
        catch (err) {
            fail(err.message.toLowerCase());
        }
        try {
            await this._audio.play();
        }
        catch (err) {
            fail(err.message.toLowerCase());
        }
    }
    d() {
        if (this._audio) {
            this._audio.pause();
        }
    }
}
exports.default = AudioTarget;
//# sourceMappingURL=index.js.map