From 23511a9b6b91cb7b4146ab0164e3cb326650e185 Mon Sep 17 00:00:00 2001 From: aoife cassidy Date: Wed, 18 Sep 2024 23:57:19 -0700 Subject: [PATCH] use process.hrtime.bigint --- packages/livekit-rtc/src/audio_source.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/livekit-rtc/src/audio_source.ts b/packages/livekit-rtc/src/audio_source.ts index 761c32c4..c298ce10 100644 --- a/packages/livekit-rtc/src/audio_source.ts +++ b/packages/livekit-rtc/src/audio_source.ts @@ -64,7 +64,10 @@ export class AudioSource { } get queuedDuration(): number { - return Math.max(this.currentQueueSize - Date.now() + this.lastCapture, 0); + return Math.max( + this.currentQueueSize - Number(process.hrtime.bigint() / 1000000n) + this.lastCapture, + 0, + ); } clearQueue() { @@ -90,7 +93,7 @@ export class AudioSource { } async captureFrame(frame: AudioFrame) { - const now = Date.now(); + const now = Number(process.hrtime.bigint() / 1000000n); const elapsed = this.lastCapture === 0 ? 0 : now - this.lastCapture; this.currentQueueSize += (frame.samplesPerChannel / frame.sampleRate - elapsed) * 1000;