Skip to content

Commit

Permalink
fix: add duration only if added timestamp exists
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 committed Mar 18, 2024
1 parent e1f5ebe commit cdb80e6
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/hms-video-store/src/common/PluginUsageTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ 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') {
const addedAt = event.properties.added_at;
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);
}
Expand Down

0 comments on commit cdb80e6

Please sign in to comment.