Skip to content

Commit

Permalink
fix: make cleanup private
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 committed Mar 13, 2024
1 parent 95e6d0c commit 03bc7df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
17 changes: 12 additions & 5 deletions packages/hms-video-store/src/common/PluginUsageTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,28 @@ class PluginUsageTracker {
return this.pluginUsage.get(pluginKey);
};

updatePluginUsage = (event: AnalyticsEvent, sessionID: string) => {
updatePluginUsageData = (event: AnalyticsEvent, sessionID: string) => {
// Sent on leave, after krisp usage is sent
if (event.name === 'subscriber.stats') {
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;
this.pluginUsage.set(pluginKey, (this.pluginUsage.get(pluginKey) || 0) + duration * 1000);
this.pluginLastAddedAt.delete(pluginKey);
if (duration) {
this.pluginUsage.set(pluginKey, (this.pluginUsage.get(pluginKey) || 0) + duration * 1000);
this.pluginLastAddedAt.delete(pluginKey);
}
}
};

cleanup = (sessionID: string) => {
private cleanup = (sessionID: string) => {
for (const key of this.pluginUsage.keys()) {
if (sessionID.length && key.includes(sessionID)) {
this.pluginUsage.delete(key);
Expand Down
4 changes: 1 addition & 3 deletions packages/hms-video-store/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ export class HMSSdk implements HMSInterface {
}
HMSLogger.timeEnd(`join-room-${roomId}`);
const sessionID = this.store.getRoom()?.sessionId || '';
this.eventBus.analytics.subscribe(e => pluginUsageTracker.updatePluginUsage(e, sessionID));
this.eventBus.analytics.subscribe(e => pluginUsageTracker.updatePluginUsageData(e, sessionID));
}

private stringifyMetadata(config: HMSConfig) {
Expand All @@ -585,8 +585,6 @@ export class HMSSdk implements HMSInterface {
}

private cleanup() {
const sessionID = this.store.getRoom()?.sessionId || '';
pluginUsageTracker.cleanup(sessionID);
this.cleanDeviceManagers();
this.eventBus.analytics.unsubscribe(this.sendAnalyticsEvent);
this.analyticsTimer.cleanup();
Expand Down

0 comments on commit 03bc7df

Please sign in to comment.