Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update pluginUsageTracker implementation #2713

Merged
merged 24 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b257e6f
feat: accept sessionID while initing plugins
KaustubhKumar05 Mar 18, 2024
e1f5ebe
fix: make session id optional for backward compatibility
KaustubhKumar05 Mar 18, 2024
cdb80e6
fix: add duration only if added timestamp exists
KaustubhKumar05 Mar 18, 2024
6762d12
fix: handle toggle scenarios
KaustubhKumar05 Mar 18, 2024
3063cfa
fix: simplify expression
KaustubhKumar05 Mar 18, 2024
98babbc
fix: review comments
KaustubhKumar05 Mar 19, 2024
6b5ff8f
refactor: use instance specific class
raviteja83 Mar 19, 2024
920c3c2
build: update versions
raviteja83 Mar 19, 2024
17c991b
fix: remove export
raviteja83 Mar 19, 2024
f402d41
feat: use plugin track usage in transport
raviteja83 Mar 19, 2024
8f8e130
feat: update noise cancellation
raviteja83 Mar 19, 2024
2a5d3c2
fix: conflict
KaustubhKumar05 Mar 20, 2024
9b3da25
fix: remove session id arg
KaustubhKumar05 Mar 20, 2024
a58f264
fix: use dummy event for cleanup
KaustubhKumar05 Mar 20, 2024
4511bd2
fix: replace crypto usage
KaustubhKumar05 Mar 20, 2024
b045672
fix: revert version bump
KaustubhKumar05 Mar 20, 2024
37aa45c
fix: revert version bump
KaustubhKumar05 Mar 20, 2024
8d1830c
fix: failing tests
raviteja83 Mar 20, 2024
ca423c8
fix: conflict
KaustubhKumar05 Mar 20, 2024
d9eccb6
fix: versions
KaustubhKumar05 Mar 20, 2024
10b1821
fix: remove logs
KaustubhKumar05 Mar 20, 2024
fbcddc2
fix: clean up
KaustubhKumar05 Mar 20, 2024
db87188
fix: combine get and cleanup
KaustubhKumar05 Mar 20, 2024
31dfa54
fix: remove extra cleanup
KaustubhKumar05 Mar 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions packages/hms-video-store/src/common/PluginUsageTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,33 @@ 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 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) {
this.pluginUsage.set(pluginKey, (this.pluginUsage.get(pluginKey) || 0) + duration * 1000);
this.pluginLastAddedAt.delete(pluginKey);
switch (event.name) {
// Sent on leave, after krisp usage is sent
case 'transport.leave': {
this.cleanup(sessionID);
return;
}
case 'mediaPlugin.toggled.on':
case 'mediaPlugin.added': {
const addedAt = event.properties.added_at || Date.now();
this.pluginLastAddedAt.set(pluginKey, addedAt);
break;
}
case 'mediaPlugin.toggled.off':
case 'mediaPlugin.stats': {
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
if (this.pluginLastAddedAt.has(pluginKey)) {
const duration =
event.properties.duration || (Date.now() - (this.pluginLastAddedAt.get(pluginKey) || 0)) / 1000;
this.pluginUsage.set(pluginKey, (this.pluginUsage.get(pluginKey) || 0) + Math.max(duration, 0) * 1000);
this.pluginLastAddedAt.delete(pluginKey);
}
}
}
return;
KaustubhKumar05 marked this conversation as resolved.
Show resolved Hide resolved
};

private cleanup = (sessionID: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface HMSAudioPlugin {
* variables, loading ML models etc. This can be used by a plugin to ensure it's prepared at the time
* processAudio is called.
*/
init(): Promise<void> | void;
init(sessionID?: string): Promise<void> | void;

/**
* The name is meant to uniquely specify a plugin instance. This will be used to track number of plugins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface HMSMediaStreamPlugin {
*/
getName(): string;

apply(stream: MediaStream): MediaStream;
apply(stream: MediaStream, sessionID?: string): MediaStream;

stop(): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface HMSVideoPlugin {
* variables, loading ML models etc. This can be used by a plugin to ensure it's prepared at the time
* processVideoFrame is called.
*/
init(): Promise<void>;
init(sessionID?: string): Promise<void>;
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved

/**
* @see HMSVideoPluginType
Expand Down
Loading