"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Functional_1 = require("../../../../../../Class/Functional");
const MediaStream_1 = require("../../../../../../wrap/MediaStream");
const _ids_1 = require("../../../../../_ids");
class AudioSource extends Functional_1.Functional {
    constructor(system) {
        super({
            i: ['src'],
            o: ['stream'],
        }, {}, system, _ids_1.ID_AUDIO_SOURCE);
        this._audio = new Audio();
        this._audio.volume = 0;
        this._audio.play();
        this.addListener('destroy', () => {
            this._audio.srcObject = null;
        });
    }
    f({ src }, done) {
        this._audio.src = src;
        const { srcObject } = this._audio;
        let stream;
        if (srcObject instanceof MediaStream) {
            stream = (0, MediaStream_1.wrapMediaStream)(srcObject, this.__system);
        }
        else {
            done(undefined, '');
            return;
        }
        done({
            stream,
        });
    }
    d() {
        this._audio.src = null;
    }
}
exports.default = AudioSource;
//# sourceMappingURL=index.js.map