201 lines
7.0 KiB
TypeScript
201 lines
7.0 KiB
TypeScript
// Metro module 12877 (f12878).
|
|
import { TimeStampProducer, StopWatch, DurationEnabled } from "../_bundle/sleep";
|
|
import { BaseConnectionEvent } from "../_bundle/Module4301";
|
|
let c8877_2 = [1, 100, 1000, 10000];
|
|
let c8877_3 = [100, 500, 1000, 5000];
|
|
class VoiceDuration {
|
|
constructor(a0, a1, timestampProducer = TimeStampProducer) {
|
|
const r19 = {
|
|
__proto__: new.target.prototype,
|
|
listeningUsers: new Set(),
|
|
timesUntilSpeakingDurationMilestonesMs: null,
|
|
speakingMinimumChunks: null,
|
|
speakingMinimumChunkCounts: null,
|
|
speechEventCount: 0
|
|
};
|
|
r19.timesUntilSpeakingDurationMilestonesMs = new Map();
|
|
r19.speakingMinimumChunks = new Map();
|
|
r19.speakingMinimumChunkCounts = new Map();
|
|
r19.userId = a0;
|
|
r19.connection = a1;
|
|
r19.timestampProducer = timestampProducer;
|
|
r19.listening = new StopWatch(r19.timestampProducer);
|
|
r19.speaking = new StopWatch(r19.timestampProducer);
|
|
r19.participation = new StopWatch(r19.timestampProducer);
|
|
r19.connected = new StopWatch(r19.timestampProducer);
|
|
r19.muted = new StopWatch(r19.timestampProducer);
|
|
r19.deafened = new StopWatch(r19.timestampProducer);
|
|
r19.noiseCancellation = new DurationEnabled(a1.getNoiseCancellation(), r19.timestampProducer);
|
|
r19.spatialAudio = new DurationEnabled(a1.getSpatialAudioEnabled(), r19.timestampProducer);
|
|
return r19;
|
|
}
|
|
start(r9 = false, r8 = false) {
|
|
this.listeningUsers.clear();
|
|
this.listening.reset();
|
|
this.speaking.reset();
|
|
this.participation.reset();
|
|
this.muted.reset();
|
|
this.deafened.reset();
|
|
this.connected.reset();
|
|
this.noiseCancellation.reset();
|
|
this.spatialAudio.reset();
|
|
this.timesUntilSpeakingDurationMilestonesMs.clear();
|
|
this.speakingMinimumChunks.clear();
|
|
this.speakingMinimumChunkCounts.clear();
|
|
this.speechEventCount = 0;
|
|
this.connected.start();
|
|
this.connection.on(BaseConnectionEvent.Speaking, (a0, a1) => {
|
|
if (this.userId === a0) {
|
|
this.onSpeaking(a1 !== 0);
|
|
} else {
|
|
this.onListening(a1 !== 0, a0);
|
|
}
|
|
});
|
|
this.onMuted(r9);
|
|
this.onDeafened(r8);
|
|
this.connection.on(BaseConnectionEvent.Mute, (a0) => {
|
|
this.onMuted(a0);
|
|
});
|
|
this.connection.on(BaseConnectionEvent.Deafen, (a0) => {
|
|
this.onDeafened(a0);
|
|
});
|
|
}
|
|
onSpeaking(a0) {
|
|
if (a0) {
|
|
this.speaking.start();
|
|
this.participation.start();
|
|
this.speechEventCount = this.speechEventCount + 1;
|
|
} else {
|
|
const lastStartTime2 = this.connected.lastStartTime;
|
|
const lastStartTime = this.speaking.lastStartTime;
|
|
const lastElapsed = this.speaking.lastElapsed;
|
|
this.addSpeechChunk();
|
|
this.speaking.stop();
|
|
if (!this.listening.isRunning()) {
|
|
this.participation.stop();
|
|
}
|
|
this.computeSpeakingDurationMilestones(lastStartTime2, lastStartTime, lastElapsed);
|
|
}
|
|
}
|
|
onListening(a0, a1) {
|
|
const listeningUsers = this.listeningUsers;
|
|
if (a0) {
|
|
listeningUsers.add(a1);
|
|
this.listening.start();
|
|
this.participation.start();
|
|
} else if (listeningUsers.delete(a1) && this.listeningUsers.size === 0) {
|
|
this.listening.stop();
|
|
if (!this.speaking.isRunning()) {
|
|
this.participation.stop();
|
|
}
|
|
}
|
|
}
|
|
onMuted(a0) {
|
|
const muted = this.muted;
|
|
if (a0) {
|
|
muted.start();
|
|
} else {
|
|
muted.stop();
|
|
}
|
|
}
|
|
onDeafened(a0) {
|
|
const deafened = this.deafened;
|
|
if (a0) {
|
|
deafened.start();
|
|
} else {
|
|
deafened.stop();
|
|
}
|
|
}
|
|
computeSpeakingDurationMilestones(a0, a1, c20281_3) {
|
|
let c20281_0;
|
|
if (a0 != null && a1 != null) {
|
|
c20281_0 = this.speaking.elapsed().asMilliseconds();
|
|
c8877_2.filter((item) => !this.timesUntilSpeakingDurationMilestonesMs.has(item)).filter((item) => c20281_0 >= item).forEach((item) => {
|
|
this.timesUntilSpeakingDurationMilestonesMs.set(item, a1 - a0 + item - c20281_3);
|
|
});
|
|
}
|
|
}
|
|
addSpeechChunk() {
|
|
let c20282_0;
|
|
const lastStartTime = this.speaking.lastStartTime;
|
|
if (lastStartTime != null) {
|
|
c20282_0 = this.timestampProducer.now() - lastStartTime;
|
|
c8877_3.filter((item) => c20282_0 >= item).forEach((item) => {
|
|
let r7 = this.speakingMinimumChunks.get(item);
|
|
if (r7 == null) {
|
|
r7 = 0;
|
|
}
|
|
this.speakingMinimumChunks.set(item, r7 + c20282_0);
|
|
let r15 = this.speakingMinimumChunkCounts.get(item);
|
|
if (r15 == null) {
|
|
r15 = 0;
|
|
}
|
|
this.speakingMinimumChunkCounts.set(item, r15 + 1);
|
|
});
|
|
}
|
|
}
|
|
setNoiseCancellationEnabled(a0) {
|
|
this.noiseCancellation.value = a0;
|
|
}
|
|
setSpatialAudioEnabled(a0) {
|
|
this.spatialAudio.value = a0;
|
|
}
|
|
stop() {
|
|
this.addSpeechChunk();
|
|
const lastStartTime2 = this.connected.lastStartTime;
|
|
const lastStartTime = this.speaking.lastStartTime;
|
|
const lastElapsed = this.speaking.lastElapsed;
|
|
this.speaking.stop();
|
|
this.listening.stop();
|
|
this.participation.stop();
|
|
this.connected.stop();
|
|
this.muted.stop();
|
|
this.noiseCancellation.value = false;
|
|
this.spatialAudio.value = false;
|
|
this.computeSpeakingDurationMilestones(lastStartTime2, lastStartTime, lastElapsed);
|
|
}
|
|
getDurationStats() {
|
|
const lastStartTime = this.speaking.lastStartTime;
|
|
const r12 = this.timestampProducer.now();
|
|
let c20283_0 = lastStartTime != null ? r12 - lastStartTime : 0;
|
|
this.computeSpeakingDurationMilestones(this.connected.lastStartTime, this.speaking.lastStartTime, this.speaking.lastElapsed);
|
|
return {
|
|
duration_listening_ms: this.listening.elapsed().asMilliseconds(),
|
|
duration_speaking_ms: this.speaking.elapsed().asMilliseconds(),
|
|
duration_participation_ms: this.participation.elapsed().asMilliseconds(),
|
|
duration_connected_ms: this.connected.elapsed().asMilliseconds(),
|
|
duration_muted_ms: this.muted.elapsed().asMilliseconds(),
|
|
duration_deafened_ms: this.deafened.elapsed().asMilliseconds(),
|
|
duration_noise_cancellation_enabled_ms: this.noiseCancellation.totalDuration(),
|
|
duration_spatial_ms: this.spatialAudio.totalDuration(),
|
|
speech_event_count: this.speechEventCount,
|
|
...c8877_2.filter((item) => this.timesUntilSpeakingDurationMilestonesMs.has(item)).reduce((acc, item) => {
|
|
const r0 = {
|
|
...acc
|
|
};
|
|
r0[`time_to_first_${item}ms_speech_ms`] = this.timesUntilSpeakingDurationMilestonesMs.get(item);
|
|
return r0;
|
|
}, {}),
|
|
...c8877_3.filter((item) => this.speakingMinimumChunks.has(item) || c20283_0 >= item).reduce((acc, item) => {
|
|
const r4 = {
|
|
...acc
|
|
};
|
|
const r16 = `duration_speaking_gte_${item}ms_ms`;
|
|
let r19 = this.speakingMinimumChunks.get(item);
|
|
if (r19 == null) {
|
|
r19 = 0;
|
|
}
|
|
r4[r16] = r19 + (c20283_0 >= item ? c20283_0 : 0);
|
|
const r27 = `speech_event_count_gte_${item}ms`;
|
|
let r30 = this.speakingMinimumChunkCounts.get(item);
|
|
if (r30 == null) {
|
|
r30 = 0;
|
|
}
|
|
r4[r27] = r30 + (c20283_0 >= item ? 1 : 0);
|
|
return r4;
|
|
}, {})
|
|
};
|
|
}
|
|
}
|
|
export default VoiceDuration;
|