Files
discord-decomp/_bundle/ConnectionEventFramerateReducer.js
T
2026-11-01 12:12:55 +02:00

62 lines
2.1 KiB
JavaScript

// Metro module 4300 (f4301).
import { SpeakingFlags, VIDEO_QUALITY_FRAMRATE_NOT_SPEAKING_TIMEOUT } from "./Module4250";
import { Logger } from "./log";
import { BaseConnectionEvent } from "./Module4286";
let c2535_4 = new Logger("ConnectionEventFramerateReducer");
class ConnectionEventFramerateReducer {
handleSpeaking = (a0, a1) => {
if (a0 === this.connection.userId) {
this.userSpeakingChange(a1 === SpeakingFlags.NONE);
}
};
handleSelfMute = (a0) => {
if (!this.connection.hasDesktopSource()) {
this.destroyFramerateScaleFactorTimers();
this.sinkWants.isMuted = a0;
this.updateRemoteWantsFramerate();
}
};
constructor(a0, a1) {
this.connection = a0;
this.sinkWants = a1;
c2535_4.enableNativeLogger(true);
a0.on(BaseConnectionEvent.Speaking, this.handleSpeaking);
a0.on(BaseConnectionEvent.Mute, this.handleSelfMute);
this.initialize();
}
initialize() {
this.userSpeakingChange(true);
}
userSpeakingChange(a0) {
if (!this.connection.hasDesktopSource()) {
this.destroyFramerateScaleFactorTimers();
if (a0) {
this.framerateReductionTimeout = setTimeout(() => {
if (!this.connection.destroyed) {
c2535_4.info(`BaseConnection.userSpeakingChange: Reduced framerate after ${VIDEO_QUALITY_FRAMRATE_NOT_SPEAKING_TIMEOUT} ms.`);
this.framerateReductionTimeout = void 0;
this.sinkWants.isMuted = true;
this.updateRemoteWantsFramerate();
}
}, VIDEO_QUALITY_FRAMRATE_NOT_SPEAKING_TIMEOUT);
} else if (this.sinkWants.isMuted) {
this.sinkWants.isMuted = false;
this.updateRemoteWantsFramerate();
}
}
}
destroyFramerateScaleFactorTimers() {
if (typeof this.framerateReductionTimeout === "number") {
clearTimeout(this.framerateReductionTimeout);
this.framerateReductionTimeout = void 0;
}
}
updateRemoteWantsFramerate() {
this.connection.updateVideoQuality(["remoteSinkWantsMaxFramerate"]);
}
destroy() {
this.destroyFramerateScaleFactorTimers();
}
}
export default ConnectionEventFramerateReducer;