// Metro module 12874 (f12875). import { Histogram } from "./Histogram"; import TypedEventEmitter from "../_bundle/TypedEventEmitter"; import NetworkQuality from "./NetworkQuality"; import SystemResources from "./SystemResources"; import { BaseConnectionEvent } from "../_bundle/Module4286"; import Module12 from "../_bundle/Module12"; import { now } from "../_bundle/sleep"; let c8874_4 = { InputDeviceSampleRateChanged: "input-device-sample-rate-changed" }; class VoiceQuality extends TypedEventEmitter { constructor(a0) { super(); const _this = this; this.sampleAudioDevice = (a0, a1) => { if (a0 !== void 0) { if (a0.restartCount !== void 0) { const restartCount = a0.restartCount; let restartCount2 = a1.restartCount; if (restartCount2 == null) { restartCount2 = { accumulated: 0, lastValue: 0 }; } const { accumulated, lastValue } = restartCount2; a1.restartCount = { accumulated: lastValue > restartCount ? accumulated + restartCount : accumulated + (restartCount - lastValue), lastValue: restartCount }; } if (a0.bufferViolations !== void 0) { const bufferViolations = a0.bufferViolations; let bufferViolations2 = a1.bufferViolations; if (bufferViolations2 == null) { bufferViolations2 = { accumulated: 0, lastValue: 0 }; } const { accumulated: accumulated2, lastValue: lastValue2 } = bufferViolations2; a1.bufferViolations = { accumulated: lastValue2 > bufferViolations ? accumulated2 + bufferViolations : accumulated2 + (bufferViolations - lastValue2), lastValue: bufferViolations }; } let timeToFirstCallbackMs = a0.timeToFirstCallbackMs; if (timeToFirstCallbackMs == null) { timeToFirstCallbackMs = 0; } if (timeToFirstCallbackMs !== 0 && a1.timeToFirstCallbackMs === void 0) { a1.timeToFirstCallbackMs = a0.timeToFirstCallbackMs; } let sessionSampleRate = a0.sessionSampleRate; if (sessionSampleRate == null) { sessionSampleRate = 0; } if (sessionSampleRate !== 0) { if (a1.sessionSampleRate !== a0.sessionSampleRate) { const InputDeviceSampleRateChanged = c8874_4.InputDeviceSampleRateChanged; let sessionSampleRate2 = a0.sessionSampleRate; if (sessionSampleRate2 == null) { sessionSampleRate2 = 0; } _this.emit(InputDeviceSampleRateChanged, sessionSampleRate2); } a1.sessionSampleRate = a0.sessionSampleRate; } if (a0.timeFromConnectToFirstCallbackMs !== void 0 && a1.timeFromConnectToFirstCallbackMs === void 0) { a1.timeFromConnectToFirstCallbackMs = a0.timeFromConnectToFirstCallbackMs; } } }; this.appendTargetRates = function appendTargetRates(a0, r8 = 0, r7 = 0) { if (a0.previousTimestampMs !== 0) { const previousTimestampMs = performance.now(); a0.aggregationDurationMs = a0.aggregationDurationMs + (previousTimestampMs - a0.previousTimestampMs); const r2 = (previousTimestampMs - a0.previousTimestampMs) / 1000; a0.bytesAvailable = a0.bytesAvailable + r8 / 8 * r2; a0.bytesTarget = a0.bytesTarget + r7 / 8 * r2; a0.previousTimestampMs = previousTimestampMs; } else { a0.previousTimestampMs = performance.now(); } }; this.sampleStats = (a0) => { let c27375_1; let c27375_0 = a0; if (a0 != null) { _this.networkQuality.incrementNetworkStats(now()); _this.systemResources.takeSample(); const duration = _this.duration; duration.connected = duration.connected + 1; const packetsSent = _this.outboundStats.packetsSent; const r34 = Module12.reduce(_this.inboundStats, (a0, a1) => { a0.packetsReceived = a0.packetsReceived + a1.packetsReceived; return a0; }, { packetsReceived: 0 }); c27375_1 = 0; Module12.forEach(a0.rtp.outbound, (a0) => { if (a0.type === "audio") { let bitrateTarget = a0.bitrateTarget; if (bitrateTarget == null) { bitrateTarget = 0; } c27375_1 = bitrateTarget; let packetsLost = a0.packetsLost; if (packetsLost == null) { packetsLost = 0; } let passthroughCount = a0.passthroughCount; if (passthroughCount == null) { passthroughCount = 0; } let encryptSuccessCount = a0.encryptSuccessCount; if (encryptSuccessCount == null) { encryptSuccessCount = 0; } let encryptFailureCount = a0.encryptFailureCount; if (encryptFailureCount == null) { encryptFailureCount = 0; } let encryptDuration = a0.encryptDuration; if (encryptDuration == null) { encryptDuration = 0; } let encryptAttempts = a0.encryptAttempts; if (encryptAttempts == null) { encryptAttempts = 0; } let encryptMaxAttempts = a0.encryptMaxAttempts; if (encryptMaxAttempts == null) { encryptMaxAttempts = 0; } let encryptMissingKeyCount = a0.encryptMissingKeyCount; if (encryptMissingKeyCount == null) { encryptMissingKeyCount = 0; } _this.outboundStats = { ..._this.outboundStats, packetsSent: a0.packetsSent, bytesSent: a0.bytesSent, packetsLost, passthroughCount, encryptSuccessCount, encryptFailureCount, encryptDuration, encryptAttempts, encryptMaxAttempts, encryptMissingKeyCount }; if (Boolean(a0.audioDetected) === true && a0.audioLevel != null) { _this.outboundStats.speakingAudioLevel.addSample(20 * Math.log(a0.audioLevel)); } } }); _this.decryptionFailures = a0.transport.decryptionFailures; _this.routingFailures = a0.transport.routingFailures; _this.appendTargetRates(_this.outboundStats, a0.transport.availableOutgoingBitrate, c27375_1); Module12.forEach(a0.rtp.inbound, (a0, c30586_0) => { Module12.forEach(a0, (a0) => { if (a0.type === "audio") { const inboundStats = _this.inboundStats; const r17 = inboundStats[c30586_0]; let ping = c27375_0.transport.ping; if (ping == null) { ping = 0; } const { packetsReceived, packetsLost, bytesReceived } = a0; let nackCount = a0.nackCount; let fecPacketsReceived = a0.fecPacketsReceived; if (fecPacketsReceived == null) { fecPacketsReceived = 0; } let fecPacketsDiscarded = a0.fecPacketsDiscarded; if (fecPacketsDiscarded == null) { fecPacketsDiscarded = 0; } let jitterBuffer = a0.jitterBuffer; if (jitterBuffer == null) { jitterBuffer = 0; } let audioJitterBufferHistogram2 = r17 == null ? void 0 : r17.bufferStats.audioJitterBufferHistogram; if (audioJitterBufferHistogram2 == null) { audioJitterBufferHistogram2 = new Histogram(); } let audioJitterTargetHistogram2 = r17 == null ? void 0 : r17.bufferStats.audioJitterTargetHistogram; if (audioJitterTargetHistogram2 == null) { audioJitterTargetHistogram2 = new Histogram(); } let audioJitterDelayHistogram2 = r17 == null ? void 0 : r17.bufferStats.audioJitterDelayHistogram; if (audioJitterDelayHistogram2 == null) { audioJitterDelayHistogram2 = new Histogram(); } const bufferStats = { audioJitterBuffer: a0.audioJitterBuffer, audioJitterBufferHistogram: audioJitterBufferHistogram2, audioJitterTarget: a0.audioJitterTarget, audioJitterTargetHistogram: audioJitterTargetHistogram2, audioJitterDelay: a0.audioJitterDelay, audioJitterDelayHistogram: audioJitterDelayHistogram2, relativeReceptionDelay: a0.relativeReceptionDelay, relativePlayoutDelay: a0.relativePlayoutDelay }; const audioJitterBufferHistogram = bufferStats.audioJitterBufferHistogram; let audioJitterBufferSamples = a0.audioJitterBufferSamples; if (audioJitterBufferSamples == null) { audioJitterBufferSamples = []; } audioJitterBufferHistogram.addSamples(audioJitterBufferSamples); const audioJitterDelayHistogram = bufferStats.audioJitterDelayHistogram; let audioJitterDelaySamples = a0.audioJitterDelaySamples; if (audioJitterDelaySamples == null) { audioJitterDelaySamples = []; } audioJitterDelayHistogram.addSamples(audioJitterDelaySamples); const audioJitterTargetHistogram = bufferStats.audioJitterTargetHistogram; let audioJitterTargetSamples = a0.audioJitterTargetSamples; if (audioJitterTargetSamples == null) { audioJitterTargetSamples = []; } audioJitterTargetHistogram.addSamples(audioJitterTargetSamples); const frameOpStats = { silent: a0.opSilence, normal: a0.opNormal, merged: a0.opMerge, expanded: a0.opExpand, accelerated: a0.opAccelerate, preemptiveExpanded: a0.opPreemptiveExpand, cng: a0.opCNG }; let passthroughCount = a0.passthroughCount; if (passthroughCount == null) { passthroughCount = 0; } let decryptSuccessCount = a0.decryptSuccessCount; if (decryptSuccessCount == null) { decryptSuccessCount = 0; } let decryptFailureCount = a0.decryptFailureCount; if (decryptFailureCount == null) { decryptFailureCount = 0; } let decryptDuration = a0.decryptDuration; if (decryptDuration == null) { decryptDuration = 0; } let decryptAttempts = a0.decryptAttempts; if (decryptAttempts == null) { decryptAttempts = 0; } let decryptMissingKeyCount = a0.decryptMissingKeyCount; if (decryptMissingKeyCount == null) { decryptMissingKeyCount = 0; } let decryptInvalidNonceCount = a0.decryptInvalidNonceCount; if (decryptInvalidNonceCount == null) { decryptInvalidNonceCount = 0; } const r98 = { passthroughCount, decryptSuccessCount, decryptFailureCount, decryptDuration, decryptAttempts, decryptMissingKeyCount, decryptInvalidNonceCount }; if (r17 != null) { const r120 = packetsReceived - r17.packetsReceived; const r28 = packetsLost - r17.packetsLost; const mosBuckets = r17.mosBuckets; let decryptFailureBeforeSuccessCount = r17.decryptFailureBeforeSuccessCount; if (decryptFailureBeforeSuccessCount == null) { decryptFailureBeforeSuccessCount = r98.decryptSuccessCount > 0 ? r98.decryptFailureCount : void 0; } const r128 = r120 > 0 && r28 >= 0; let mos = 0; if (r128) { const r140 = _this.calculateMos(ping + jitterBuffer, Module12.clamp(r28 / (r120 + r28), 0, 1)); const r144 = Math.floor(r140); mosBuckets[r144] = mosBuckets[r144] + 1; mos = r140; } const inboundStats2 = _this.inboundStats; if (nackCount == null) { nackCount = 0; } inboundStats2[c30586_0] = { packetsReceived, bytesReceived, packetsLost, nackCount, fecPacketsReceived, fecPacketsDiscarded, mos, mosSum: r17.mosSum + mos, mosCount: r17.mosCount + (mos > 0 ? 1 : 0), mosBuckets, bufferStats, frameOpStats, decryptFailureBeforeSuccessCount, ...r98 }; const periodicInboundStats2 = _this.periodicInboundStats; const r162 = { previousTimestampMs: _this.periodicInboundStats[c30586_0].previousTimestampMs, previous: _this.periodicInboundStats[c30586_0].previous, currentTimestampMs: performance.now(), current: frameOpStats, accelerateRateSum: null, expandRateSum: null, preemptiveExpandRateSum: null, speechExpandRateSum: null, numRateSamples: null }; const accelerateRateSum = _this.periodicInboundStats[c30586_0].accelerateRateSum; let accelerateRate2 = a0.accelerateRate; if (accelerateRate2 == null) { accelerateRate2 = 0; } r162.accelerateRateSum = accelerateRateSum + accelerateRate2; const expandRateSum = _this.periodicInboundStats[c30586_0].expandRateSum; let expandRate2 = a0.expandRate; if (expandRate2 == null) { expandRate2 = 0; } r162.expandRateSum = expandRateSum + expandRate2; const preemptiveExpandRateSum = _this.periodicInboundStats[c30586_0].preemptiveExpandRateSum; let preemptiveExpandRate2 = a0.preemptiveExpandRate; if (preemptiveExpandRate2 == null) { preemptiveExpandRate2 = 0; } r162.preemptiveExpandRateSum = preemptiveExpandRateSum + preemptiveExpandRate2; const speechExpandRateSum = _this.periodicInboundStats[c30586_0].speechExpandRateSum; let speechExpandRate2 = a0.speechExpandRate; if (speechExpandRate2 == null) { speechExpandRate2 = 0; } r162.speechExpandRateSum = speechExpandRateSum + speechExpandRate2; r162.numRateSamples = _this.periodicInboundStats[c30586_0].numRateSamples + 1; periodicInboundStats2[c30586_0] = r162; } else { _this.inboundStats[c30586_0] = { packetsReceived, bytesReceived, packetsLost, nackCount: nackCount == null ? 0 : nackCount, fecPacketsReceived, fecPacketsDiscarded, mos: 0, mosSum: 0, mosCount: 0, mosBuckets: [0, 0, 0, 0, 0], bufferStats, frameOpStats, ...r98 }; const periodicInboundStats = _this.periodicInboundStats; const r111 = { previousTimestampMs: performance.now(), previous: frameOpStats, currentTimestampMs: performance.now(), current: frameOpStats, accelerateRateSum: null, expandRateSum: null, preemptiveExpandRateSum: null, speechExpandRateSum: null, numRateSamples: 1 }; let accelerateRate = a0.accelerateRate; if (accelerateRate == null) { accelerateRate = 0; } r111.accelerateRateSum = accelerateRate; let expandRate = a0.expandRate; if (expandRate == null) { expandRate = 0; } r111.expandRateSum = expandRate; let preemptiveExpandRate = a0.preemptiveExpandRate; if (preemptiveExpandRate == null) { preemptiveExpandRate = 0; } r111.preemptiveExpandRateSum = preemptiveExpandRate; let speechExpandRate = a0.speechExpandRate; if (speechExpandRate == null) { speechExpandRate = 0; } r111.speechExpandRateSum = speechExpandRate; periodicInboundStats[c30586_0] = r111; } } }); }); if (a0.audioDevice !== void 0) { _this.sampleAudioDevice(a0.audioDevice.input, _this.inputDeviceStats); _this.sampleAudioDevice(a0.audioDevice.output, _this.outputDeviceStats); } const r4 = _this.outboundStats.packetsSent > packetsSent; let r72 = false; if (r4) { const duration2 = _this.duration; duration2.speaking = duration2.speaking + 1; r72 = true; } const r85 = Module12.reduce(_this.inboundStats, (a0, a1) => { a0.packetsReceived = a0.packetsReceived + a1.packetsReceived; return a0; }, { packetsReceived: 0 }).packetsReceived > r34.packetsReceived; let r2 = false; if (r85) { const duration3 = _this.duration; duration3.listening = duration3.listening + 1; r2 = true; } if (!r72) { r72 = r2; } if (r72) { const duration4 = _this.duration; duration4.participation = duration4.participation + 1; } } }; this.connection = a0; this.networkQuality = new NetworkQuality(); this.systemResources = new SystemResources(); this.inboundStats = {}; this.outboundStats = { packetsSent: 0, bytesSent: 0, packetsLost: 0, passthroughCount: 0, encryptSuccessCount: 0, encryptFailureCount: 0, encryptDuration: 0, encryptAttempts: 0, encryptMaxAttempts: 0, encryptMissingKeyCount: 0, bytesAvailable: 0, bytesTarget: 0, previousTimestampMs: 0, aggregationDurationMs: 0, speakingAudioLevel: new Histogram() }; this.duration = { listening: 0, speaking: 0, participation: 0, connected: 0 }; this.periodicInboundStats = {}; this.inputDeviceStats = {}; this.outputDeviceStats = {}; } start() { this.connection.on(BaseConnectionEvent.Stats, this.sampleStats); } stop() { this.connection.off(BaseConnectionEvent.Stats, this.sampleStats); } getMosStats() { const r12 = Module12.reduce(this.inboundStats, (a0, a1) => { a0.mosSum = a0.mosSum + a1.mosSum; a0.mosCount = a0.mosCount + a1.mosCount; let r0 = 0; while (true) { const mosBuckets = a0.mosBuckets; mosBuckets[r0] = mosBuckets[r0] + a1.mosBuckets[r0]; r0 = r0 + 1; if (!(r0 < 5)) { return a0; } } }, { mosSum: 0, mosCount: 0, mosBuckets: [0, 0, 0, 0, 0] }); return { mos_mean: r12.mosCount > 0 ? r12.mosSum / r12.mosCount : 0, mos_1: r12.mosBuckets[1], mos_2: r12.mosBuckets[2], mos_3: r12.mosBuckets[3], mos_4: r12.mosBuckets[4] }; } getPacketStats() { const r11 = Module12.reduce(this.inboundStats, (a0, a1) => { a0.packetsReceived = a0.packetsReceived + a1.packetsReceived; a0.packetsReceivedLost = a0.packetsReceivedLost + a1.packetsLost; a0.nackCount = a0.nackCount + a1.nackCount; a0.fecPacketsReceived = a0.fecPacketsReceived + a1.fecPacketsReceived; a0.fecPacketsDiscarded = a0.fecPacketsDiscarded + a1.fecPacketsDiscarded; return a0; }, { packetsReceived: 0, packetsReceivedLost: 0, nackCount: 0, fecPacketsReceived: 0, fecPacketsDiscarded: 0 }); return { packets_sent: this.outboundStats.packetsSent, packets_sent_lost: this.outboundStats.packetsLost, packets_received: r11.packetsReceived, packets_received_lost: r11.packetsReceivedLost, num_nacks_sent: r11.nackCount, fec_packets_received: r11.fecPacketsReceived, fec_packets_discarded: r11.fecPacketsDiscarded }; } getBytesStats() { const bytes_received = Module12.reduce(this.inboundStats, (a0, a1) => a0 + a1.bytesReceived, 0); const r17 = this.outboundStats.aggregationDurationMs / 1000; return { bytes_sent: this.outboundStats.bytesSent, bytes_received, outbound_bandwidth_estimate: 0 < r17 ? Math.round(8 * this.outboundStats.bytesAvailable / r17) : 0, audio_target_bitrate: 0 < r17 ? Math.round(8 * this.outboundStats.bytesTarget / r17) : 0 }; } getNetworkStats() { return this.networkQuality.getStats(); } getSystemResourceStats() { return this.systemResources.getStats(); } getBufferStats() { const r31 = Module12.reduce(this.inboundStats, (a0, a1) => { const r8 = a1.bufferStats.audioJitterBufferHistogram.getSamples() > 0 ? a1.bufferStats.audioJitterBufferHistogram.getPercentile(75) : a1.bufferStats.audioJitterBuffer != null ? a1.bufferStats.audioJitterBuffer.p75 : null; let r20 = a0; const r22 = a0 == null ? null : a0.audioJitterBufferHistogram.getSamples() > 0 ? a0.audioJitterBufferHistogram.getPercentile(75) : a0.audioJitterBuffer != null ? a0.audioJitterBuffer.p75 : null; if (a0 == null || r22 == null || r8 != null && r8 > r22) { r20 = a1.bufferStats; } return r20; }, null); const audio_jitter_buffer = r31 != null ? r31.audioJitterBufferHistogram.getSamples() > 0 ? r31.audioJitterBufferHistogram : r31.audioJitterBuffer != null ? r31.audioJitterBuffer : null : null; const audio_jitter_target = r31 != null ? r31.audioJitterTargetHistogram.getSamples() > 0 ? r31.audioJitterTargetHistogram : r31.audioJitterTarget != null ? r31.audioJitterTarget : null : null; const audio_jitter_delay = r31 != null ? r31.audioJitterDelayHistogram.getSamples() > 0 ? r31.audioJitterDelayHistogram : r31.audioJitterDelay != null ? r31.audioJitterDelay : null : null; let relative_reception_delay = r31?.relativeReceptionDelay; if (relative_reception_delay == null) { relative_reception_delay = null; } let relative_playout_delay = r31?.relativePlayoutDelay; if (relative_playout_delay == null) { relative_playout_delay = null; } const r16 = { audio_jitter_buffer, audio_jitter_target, audio_jitter_delay, relative_reception_delay, relative_playout_delay }; const r59 = {}; for (const key in r16) { const r21 = r16[key]; if (r21 instanceof Histogram) { const report = r21.getReport([75, 95, 99]); r59[key + "_mean"] = Math.round(report.mean); r59[key + "_p75"] = Math.round(report.percentiles[75]); r59[key + "_p95"] = Math.round(report.percentiles[95]); r59[key + "_p99"] = Math.round(report.percentiles[99]); r59[key + "_max"] = Math.round(report.max); } else { r59[key + "_mean"] = r21 != null ? r21.mean : 0; r59[key + "_p75"] = r21 != null ? r21.p75 : 0; r59[key + "_p95"] = r21 != null ? r21.p95 : 0; r59[key + "_p99"] = r21 != null ? r21.p99 : 0; r59[key + "_max"] = r21 != null ? r21.max : 0; } } return { ...r59 }; } getFrameOpStats() { const r11 = Module12.reduce(this.inboundStats, (a0, a1) => { if (a1.frameOpStats.silent != null) { a0.silent = a0.silent + a1.frameOpStats.silent; } if (a1.frameOpStats.normal != null) { a0.normal = a0.normal + a1.frameOpStats.normal; } if (a1.frameOpStats.merged != null) { a0.merged = a0.merged + a1.frameOpStats.merged; } if (a1.frameOpStats.expanded != null) { a0.expanded = a0.expanded + a1.frameOpStats.expanded; } if (a1.frameOpStats.accelerated != null) { a0.accelerated = a0.accelerated + a1.frameOpStats.accelerated; } if (a1.frameOpStats.preemptiveExpanded != null) { a0.preemptiveExpanded = a0.preemptiveExpanded + a1.frameOpStats.preemptiveExpanded; } if (a1.frameOpStats.cng != null) { a0.cng = a0.cng + a1.frameOpStats.cng; } return a0; }, { silent: 0, normal: 0, merged: 0, expanded: 0, accelerated: 0, preemptiveExpanded: 0, cng: 0 }); return { frame_op_silent: r11.silent, frame_op_normal: r11.normal, frame_op_merged: r11.merged, frame_op_expanded: r11.expanded, frame_op_accelerated: r11.accelerated, frame_op_preemptive_expanded: r11.preemptiveExpanded, frame_op_cng: r11.cng }; } getDurationStats() { return { duration_listening: this.duration.listening, duration_speaking: this.duration.speaking, duration_participation: this.duration.participation, duration_connected: this.duration.connected }; } getTransportStats() { return { decryption_failures: this.decryptionFailures, routing_failures: this.routingFailures }; } getE2EEStats() { const r11 = Module12.reduce(this.inboundStats, (a0, a1) => { const passthroughCount2 = a0.passthroughCount; let passthroughCount = a1.passthroughCount; if (passthroughCount == null) { passthroughCount = 0; } a0.passthroughCount = passthroughCount2 + passthroughCount; const decryptSuccessCount = a0.decryptSuccessCount; let decryptSuccessCount2 = a1.decryptSuccessCount; if (decryptSuccessCount2 == null) { decryptSuccessCount2 = 0; } a0.decryptSuccessCount = decryptSuccessCount + decryptSuccessCount2; const decryptFailureCount = a0.decryptFailureCount; let decryptFailureCount2 = a1.decryptFailureCount; if (decryptFailureCount2 == null) { decryptFailureCount2 = 0; } a0.decryptFailureCount = decryptFailureCount + decryptFailureCount2; const decryptDuration = a0.decryptDuration; let decryptDuration2 = a1.decryptDuration; if (decryptDuration2 == null) { decryptDuration2 = 0; } a0.decryptDuration = decryptDuration + decryptDuration2; const decryptAttempts = a0.decryptAttempts; let decryptAttempts2 = a1.decryptAttempts; if (decryptAttempts2 == null) { decryptAttempts2 = 0; } a0.decryptAttempts = decryptAttempts + decryptAttempts2; const decryptMissingKeyCount = a0.decryptMissingKeyCount; let decryptMissingKeyCount2 = a1.decryptMissingKeyCount; if (decryptMissingKeyCount2 == null) { decryptMissingKeyCount2 = 0; } a0.decryptMissingKeyCount = decryptMissingKeyCount + decryptMissingKeyCount2; const decryptInvalidNonceCount = a0.decryptInvalidNonceCount; let decryptInvalidNonceCount2 = a1.decryptInvalidNonceCount; if (decryptInvalidNonceCount2 == null) { decryptInvalidNonceCount2 = 0; } a0.decryptInvalidNonceCount = decryptInvalidNonceCount + decryptInvalidNonceCount2; const decryptFailureAfterSuccessCount = a0.decryptFailureAfterSuccessCount; let decryptFailureCount3 = a1.decryptFailureCount; if (decryptFailureCount3 == null) { decryptFailureCount3 = 0; } let decryptFailureBeforeSuccessCount = a1.decryptFailureBeforeSuccessCount; if (decryptFailureBeforeSuccessCount == null) { decryptFailureBeforeSuccessCount = 0; } a0.decryptFailureAfterSuccessCount = decryptFailureAfterSuccessCount + (decryptFailureCount3 - decryptFailureBeforeSuccessCount); return a0; }, { passthroughCount: 0, decryptSuccessCount: 0, decryptFailureCount: 0, decryptDuration: 0, decryptAttempts: 0, decryptMissingKeyCount: 0, decryptInvalidNonceCount: 0, decryptFailureAfterSuccessCount: 0 }); return { decrypt_passthrough_count: r11.passthroughCount, decrypt_success_count: r11.decryptSuccessCount, decrypt_failure_count: r11.decryptFailureCount, decrypt_duration: r11.decryptDuration, decrypt_attempts: r11.decryptAttempts, decrypt_missing_key_count: r11.decryptMissingKeyCount, decrypt_invalid_nonce_count: r11.decryptInvalidNonceCount, decrypt_failure_after_success_count: r11.decryptFailureAfterSuccessCount, encrypt_passthrough_count: this.outboundStats.passthroughCount, encrypt_success_count: this.outboundStats.encryptSuccessCount, encrypt_failure_count: this.outboundStats.encryptFailureCount, encrypt_duration: this.outboundStats.encryptDuration, encrypt_attempts: this.outboundStats.encryptAttempts, encrypt_max_attempts: this.outboundStats.encryptMaxAttempts, encrypt_missing_key_count: this.outboundStats.encryptMissingKeyCount }; } getAudioDeviceStats() { return { input_device_restart_count: this.inputDeviceStats.restartCount?.accumulated, output_device_restart_count: this.outputDeviceStats.restartCount?.accumulated, input_device_time_to_first_audio: this.inputDeviceStats.timeToFirstCallbackMs, output_device_time_to_first_audio: this.outputDeviceStats.timeToFirstCallbackMs, input_device_buffer_overfull_count: this.inputDeviceStats.bufferViolations?.accumulated, output_device_buffer_underrun_count: this.outputDeviceStats.bufferViolations?.accumulated, input_device_session_sample_rate: this.inputDeviceStats.sessionSampleRate, output_device_session_sample_rate: this.outputDeviceStats.sessionSampleRate, input_device_time_from_connect_to_first_audio_ms: this.inputDeviceStats.timeFromConnectToFirstCallbackMs, output_device_time_from_connect_to_first_audio_ms: this.outputDeviceStats.timeFromConnectToFirstCallbackMs }; } getAudioLevelStats() { const report = this.outboundStats.speakingAudioLevel.getReport([1, 5, 10, 25, 50, 75, 90, 95, 99]); return { outbound_audio_level_db_p1: report.percentiles[1], outbound_audio_level_db_p5: report.percentiles[5], outbound_audio_level_db_p10: report.percentiles[10], outbound_audio_level_db_p25: report.percentiles[25], outbound_audio_level_db_p50: report.percentiles[50], outbound_audio_level_db_p75: report.percentiles[75], outbound_audio_level_db_p90: report.percentiles[90], outbound_audio_level_db_p95: report.percentiles[95], outbound_audio_level_db_p99: report.percentiles[99], outbound_audio_level_db_max: report.max, outbound_audio_level_db_mean: report.mean }; } getPeriodicStats() { const r0 = []; for (const item of Object.entries(this.periodicInboundStats)) { const [userId, r44] = item; const { previous, current, currentTimestampMs, previousTimestampMs, numRateSamples } = r44; if (previousTimestampMs !== void 0 && currentTimestampMs > previousTimestampMs) { const durationMs = currentTimestampMs - previousTimestampMs; let silent = current.silent; if (silent == null) { let silent2 = previous.silent; if (silent2 == null) { silent2 = 0; } silent = 0 - silent2; } let normal = current.normal; if (normal == null) { let normal2 = previous.normal; if (normal2 == null) { normal2 = 0; } normal = 0 - normal2; } let merged = current.merged; if (merged == null) { let merged2 = previous.merged; if (merged2 == null) { merged2 = 0; } merged = 0 - merged2; } let expanded = current.expanded; if (expanded == null) { let expanded2 = previous.expanded; if (expanded2 == null) { expanded2 = 0; } expanded = 0 - expanded2; } let accelerated = current.accelerated; if (accelerated == null) { let accelerated2 = previous.accelerated; if (accelerated2 == null) { accelerated2 = 0; } accelerated = 0 - accelerated2; } let preemptiveExpanded = current.preemptiveExpanded; if (preemptiveExpanded == null) { let preemptiveExpanded2 = previous.preemptiveExpanded; if (preemptiveExpanded2 == null) { preemptiveExpanded2 = 0; } preemptiveExpanded = 0 - preemptiveExpanded2; } let cng = current.cng; if (cng == null) { let cng2 = previous.cng; if (cng2 == null) { cng2 = 0; } cng = 0 - cng2; } const accelerateRateSum = r44.accelerateRateSum; const r58 = { userId, silent, normal, merged, expanded, accelerated, preemptiveExpanded, cng, accelerateRate: accelerateRateSum / numRateSamples, expandRate: r44.expandRateSum / numRateSamples, preemptiveExpandRate: r44.preemptiveExpandRateSum / numRateSamples, speechExpandRate: r44.speechExpandRateSum / numRateSamples, durationMs }; if (r58.normal + r58.merged + r58.expanded + r58.accelerated + r58.preemptiveExpanded > 0) { r0.push(r58); } } const periodicInboundStats = this.periodicInboundStats; periodicInboundStats[userId].accelerateRateSum = 0; this.periodicInboundStats[userId].expandRateSum = 0; this.periodicInboundStats[userId].preemptiveExpandRateSum = 0; this.periodicInboundStats[userId].speechExpandRateSum = 0; this.periodicInboundStats[userId].numRateSamples = 0; this.periodicInboundStats[userId].previous = current; this.periodicInboundStats[userId].previousTimestampMs = currentTimestampMs; } return r0; } calculateMos(a0, a1) { const r12 = this.calculateR(a0, a1); return r12 < 0 ? 1 : r12 > 100 ? 4.5 : 1 + 0.035 * r12 + 0.0000071 * r12 * (r12 - 60) * (100 - r12); } calculateR(a0, a1) { return 93.4 - (0.024 * a0 + (a0 > 177.3 ? 0.11 * (a0 - 177.3) : 0)) - (10 + 122 * a1 / (a1 + 10)); } } export default VoiceQuality; export { c8874_4 as VoiceQualityEvent };