Skip to content

Commit

Permalink
test: logs for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 committed Mar 8, 2024
1 parent 8d1ec6d commit aef9581
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/hms-video-store/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class HMSSdk implements HMSInterface {
* to not miss events that are published before the handlers are subscribed.
*/
this.eventBus.analytics.subscribe(this.sendAnalyticsEvent);
this.eventBus.analytics.subscribe(this.store.subscribeToPluginStateEvents);
this.eventBus.analytics.subscribe(this.store.updatePluginUsage);
this.eventBus.deviceChange.subscribe(this.handleDeviceChange);
this.eventBus.audioPluginFailed.subscribe(this.handleAudioPluginError);
}
Expand Down
32 changes: 15 additions & 17 deletions packages/hms-video-store/src/sdk/store/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,13 @@ class Store {
private userAgent: string = createUserAgent(this.env);
private polls = new Map<string, HMSPoll>();
private whiteboards = new Map<string, HMSWhiteboard>();
private pluginUsage: Record<string, number> = {};
private pluginLastAddedAt: Record<string, number> = {};
private pluginUsage: Record<string, number> = { HMSKrispPlugin: 0 };
private pluginLastAddedAt: Record<string, number> = { HMSKrispPlugin: 0 };

getConfig() {
return this.config;
}

subscribeToPluginStateEvents(event: AnalyticsEvent) {
if (event.name === 'plugin.state.changed') {
const name = event.properties.pluginName;
this.updatePluginUsage(name, event.timestamp);
}
}
getPluginUsage(name: string) {
if (!this.pluginUsage[name]) {
this.pluginUsage[name] = 0;
Expand All @@ -74,16 +68,20 @@ class Store {
}
return this.pluginUsage[name];
}
updatePluginUsage(name: string, timeStamp: number) {
if (!this.pluginUsage[name]) {
this.pluginUsage[name] = 0;
}
updatePluginUsage(event: AnalyticsEvent) {
if (event.name === 'plugin.state.changed') {
const name = event.properties.pluginName;
if (!this.pluginUsage[name]) {
this.pluginUsage[name] = 0;
}

if (!this.pluginLastAddedAt[name]) {
this.pluginLastAddedAt[name] = timeStamp;
} else {
this.pluginUsage[name] = (this.pluginUsage?.[name] || 0) + timeStamp - this.pluginLastAddedAt[name];
this.pluginLastAddedAt[name] = 0;
if (!this.pluginLastAddedAt[name]) {
this.pluginLastAddedAt[name] = event.timestamp;
} else {
this.pluginUsage[name] = (this.pluginUsage?.[name] || 0) + event.timestamp - this.pluginLastAddedAt[name];
this.pluginLastAddedAt[name] = 0;
}
console.log('krisp usage value:', this.pluginUsage[name]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/hms-video-store/src/transport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export default class HMSTransport {
HMSLogger.d(TAG, 'leaving in transport');
try {
const krispUsage = this.store.getPluginUsage('HMSKrispPlugin');
console.log('final value', krispUsage);
console.log('krisp final value', krispUsage);
this.state = TransportState.Leaving;
this.publishStatsAnalytics?.stop();
this.subscribeStatsAnalytics?.stop();
Expand Down

0 comments on commit aef9581

Please sign in to comment.