-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into publish-alpha
- Loading branch information
Showing
34 changed files
with
230 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import AnalyticsEvent from '../analytics/AnalyticsEvent'; | ||
|
||
class PluginUsageTracker { | ||
private pluginUsage: Map<string, number> = new Map<string, number>(); | ||
private pluginLastAddedAt: Map<string, number> = new Map<string, number>(); | ||
|
||
getPluginUsage = (name: string, sessionID: string) => { | ||
const pluginKey = `${sessionID}-${name}`; | ||
|
||
if (!this.pluginUsage.has(pluginKey)) { | ||
this.pluginUsage.set(pluginKey, 0); | ||
} | ||
if (this.pluginLastAddedAt.has(pluginKey)) { | ||
const lastAddedAt = this.pluginLastAddedAt.get(pluginKey) || 0; | ||
const extraDuration = lastAddedAt ? Date.now() - lastAddedAt : 0; | ||
this.pluginUsage.set(pluginKey, (this.pluginUsage.get(pluginKey) || 0) + extraDuration); | ||
this.pluginLastAddedAt.delete(pluginKey); | ||
} | ||
return this.pluginUsage.get(pluginKey); | ||
}; | ||
|
||
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) { | ||
this.pluginUsage.set(pluginKey, (this.pluginUsage.get(pluginKey) || 0) + duration * 1000); | ||
this.pluginLastAddedAt.delete(pluginKey); | ||
} | ||
} | ||
}; | ||
|
||
private cleanup = (sessionID: string) => { | ||
for (const key of this.pluginUsage.keys()) { | ||
if (sessionID.length && key.includes(sessionID)) { | ||
this.pluginUsage.delete(key); | ||
this.pluginLastAddedAt.delete(key); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
export const pluginUsageTracker = new PluginUsageTracker(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { pluginUsageTracker } from './PluginUsageTracker'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.