From cdb80e665135a1d4a1fd0f6763ce25bade9dfe41 Mon Sep 17 00:00:00 2001 From: KaustubhKumar05 Date: Mon, 18 Mar 2024 11:06:59 +0530 Subject: [PATCH] fix: add duration only if added timestamp exists --- packages/hms-video-store/src/common/PluginUsageTracker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/hms-video-store/src/common/PluginUsageTracker.ts b/packages/hms-video-store/src/common/PluginUsageTracker.ts index 248550ff41..5e3e97d5e3 100644 --- a/packages/hms-video-store/src/common/PluginUsageTracker.ts +++ b/packages/hms-video-store/src/common/PluginUsageTracker.ts @@ -19,13 +19,13 @@ class PluginUsageTracker { return this.pluginUsage.get(pluginKey); }; + // eslint-disable-next-line complexity updatePluginUsageData = (event: AnalyticsEvent, sessionID: string) => { // Sent on leave, after krisp usage is sent if (event.name === 'transport.leave') { this.cleanup(sessionID); return; } - const name = event.properties.plugin_name; const pluginKey = `${sessionID}-${name}`; if (event.name === 'mediaPlugin.added') { @@ -33,7 +33,7 @@ class PluginUsageTracker { this.pluginLastAddedAt.set(pluginKey, addedAt); } else if (event.name === 'mediaPlugin.stats') { const duration = event.properties.duration; - if (duration > 0) { + if (duration > 0 && this.pluginLastAddedAt.has(pluginKey)) { this.pluginUsage.set(pluginKey, (this.pluginUsage.get(pluginKey) || 0) + duration * 1000); this.pluginLastAddedAt.delete(pluginKey); }