const { EventEmitter: t } = require("events")
module.exports = class extends t {
constructor() {
;(super(), (this._statusById = new Map()), (this._clientsBySwarmId = new Map()))
}
addClient(t, e) {
this._clientsBySwarmId.set(t, e)
}
getClient(t) {
return this._clientsBySwarmId.get(t) || null
}
deleteClient(t) {
this._clientsBySwarmId.delete(t)
}
clients() {
return this._clientsBySwarmId.values()
}
updateStatus(t, e, s = null, a = null) {
let d = this._statusById.get(e)
const l = null === t ? null : this._clientsBySwarmId.get(t) || null
d ||
((d = { ready: !1, stream: new MediaStream(), videoMuted: !1 !== s, audioMuted: !1 !== a }),
this._statusById.set(e, d))
let n = !1
;(null !== s && ((n = n || d.videoMuted !== s), (d.videoMuted = s)),
null !== a && ((n = n || d.audioMuted !== a), (d.audioMuted = a)))
const i = null !== l && null !== d.stream
if (i) {
const t = l.remoteStreams.get(e)
if (t) {
const e = d.stream
t.getTracks().forEach((t) => {
e.getTrackById(t.id) || e.addTrack(t)
})
} else l.remoteStreams.set(e, d.stream)
}
return (d.ready !== i && ((n = !0), (d.ready = i)), n && this.emit("change", e, d), d)
}
getStatus(t) {
let e = this._statusById.get(t)
return (e || (e = this.updateStatus(null, t)), e)
}
deleteStatus(t) {
this._statusById.delete(t)
}
emitChangeOnTrackAdded(t) {
const e = this._statusById.get(t)
e && e.ready && 0 !== e.stream.getVideoTracks().length && this.emit("change", t, e)
}
}