const { Readable: e } = require("streamx"),
t = require("hypercore-id-encoding"),
i = require("b4a"),
s = require("./call"),
r = require("./presence"),
c = require("./local/tracks"),
a = require("./local/devices"),
{ createResourceManager: o } = require("../lib/common")
module.exports = class {
constructor(e, h) {
;((this.api = e),
(this.swarmId = i.isBuffer(h) ? t.encode(h) : h),
(this.local = new c()),
(this.devices = new a()),
(this.presence = new r(this.api, this.swarmId)))
const { collection: u, method: l, subscription: n } = o((e) => new s(this, e))
;((this._callsById = u),
(this.authorize = this._authorize.bind(this)),
(this.deauthorize = this._deauthorize.bind(this)),
(this.subscribeActivateCall = n(this._subscribeActivateCall.bind(this))),
(this.subscribeRemoteStream = n(this._subscribeRemoteStream.bind(this))),
(this.getRemoteSrcObject = l(this._getRemoteSrcObject.bind(this))))
}
close() {
this.devices.close()
for (const { value: e } of this._callsById.values()) e.close()
}
_authorize(e, t) {
return this.api.authorize(e, t)
}
_deauthorize(e, t) {
return this.api.deauthorize(e, t)
}
_subscribeActivateCall() {
return new e()
}
_subscribeRemoteStream(e, t) {
return e.subscribeRemoteStream(t)
}
_getRemoteSrcObject(e, t) {
return e.getRemoteSrcObject(t)
}
}