From e99675cf57d3c1a4e276f73e1915525a75d381fb Mon Sep 17 00:00:00 2001 From: Ravi theja Date: Mon, 11 Mar 2024 22:10:58 +0530 Subject: [PATCH 01/14] fix: video tile size when res changes in sidebar (#2688) --- .../src/Prebuilt/components/VideoLayouts/ProminenceLayout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/roomkit-react/src/Prebuilt/components/VideoLayouts/ProminenceLayout.tsx b/packages/roomkit-react/src/Prebuilt/components/VideoLayouts/ProminenceLayout.tsx index 9ed895d2d8..428ea1b49e 100644 --- a/packages/roomkit-react/src/Prebuilt/components/VideoLayouts/ProminenceLayout.tsx +++ b/packages/roomkit-react/src/Prebuilt/components/VideoLayouts/ProminenceLayout.tsx @@ -70,8 +70,8 @@ const SecondarySection = ({ rootCSS={{ padding: 0, maxWidth: 240, - h: hasSidebar ? undefined : '100%', aspectRatio: 16 / 9, + ...(hasSidebar ? { w: '100%' } : { h: '100%' }), '@md': { aspectRatio: 1 }, }} objectFit="contain" From a81e46c1952d5a366f738bafbcc904bfc955e5c9 Mon Sep 17 00:00:00 2001 From: Ravi theja Date: Tue, 12 Mar 2024 10:50:40 +0530 Subject: [PATCH 02/14] Merge main to dev (#2691) * fix: video tile size when res changes in sidebar * revert: type 'module' as it causing some build issues --- packages/hls-player/package.json | 1 - packages/hls-stats/package.json | 1 - packages/hms-video-store/jest.config.js | 2 +- packages/hms-video-store/package.json | 1 - packages/hms-virtual-background/package.json | 1 - packages/react-icons/package.json | 1 - packages/react-sdk/package.json | 1 - packages/roomkit-react/package.json | 1 - packages/roomkit-web/package.json | 1 - 9 files changed, 1 insertion(+), 9 deletions(-) diff --git a/packages/hls-player/package.json b/packages/hls-player/package.json index 47db5083c0..22051e3eb0 100644 --- a/packages/hls-player/package.json +++ b/packages/hls-player/package.json @@ -5,7 +5,6 @@ "main": "dist/index.cjs.js", "module": "dist/index.js", "typings": "dist/index.d.ts", - "type": "module", "repository": { "type": "git", "url": "https://github.com/100mslive/web-sdks.git", diff --git a/packages/hls-stats/package.json b/packages/hls-stats/package.json index 9607bdfa84..5da917ca71 100644 --- a/packages/hls-stats/package.json +++ b/packages/hls-stats/package.json @@ -5,7 +5,6 @@ "main": "dist/index.cjs.js", "module": "dist/index.js", "typings": "dist/index.d.ts", - "type": "module", "repository": { "type": "git", "url": "https://github.com/100mslive/web-sdks.git", diff --git a/packages/hms-video-store/jest.config.js b/packages/hms-video-store/jest.config.js index b78c73e9ad..5c19a40542 100644 --- a/packages/hms-video-store/jest.config.js +++ b/packages/hms-video-store/jest.config.js @@ -10,4 +10,4 @@ const config = { testEnvironment: 'jsdom', }; -export default config; +module.exports = config; diff --git a/packages/hms-video-store/package.json b/packages/hms-video-store/package.json index 1e71e69d55..5c07956221 100644 --- a/packages/hms-video-store/package.json +++ b/packages/hms-video-store/package.json @@ -9,7 +9,6 @@ "main": "dist/index.cjs.js", "module": "dist/index.js", "typings": "dist/index.d.ts", - "type": "module", "files": [ "dist", "src" diff --git a/packages/hms-virtual-background/package.json b/packages/hms-virtual-background/package.json index f510bdba38..4f105d174b 100755 --- a/packages/hms-virtual-background/package.json +++ b/packages/hms-virtual-background/package.json @@ -6,7 +6,6 @@ "module": "dist/index.js", "main": "dist/index.cjs.js", "typings": "dist/index.d.ts", - "type": "module", "repository": { "type": "git", "url": "https://github.com/100mslive/web-sdks.git", diff --git a/packages/react-icons/package.json b/packages/react-icons/package.json index 4ecb487707..5b3b3ed759 100644 --- a/packages/react-icons/package.json +++ b/packages/react-icons/package.json @@ -4,7 +4,6 @@ "main": "dist/index.cjs.js", "module": "dist/index.js", "typings": "dist/index.d.ts", - "type": "module", "version": "0.10.1", "author": "100ms", "license": "MIT", diff --git a/packages/react-sdk/package.json b/packages/react-sdk/package.json index f42ecf9431..2bb16efd01 100644 --- a/packages/react-sdk/package.json +++ b/packages/react-sdk/package.json @@ -4,7 +4,6 @@ "main": "dist/index.cjs.js", "module": "dist/index.js", "typings": "dist/index.d.ts", - "type": "module", "version": "0.10.1", "author": "100ms", "license": "MIT", diff --git a/packages/roomkit-react/package.json b/packages/roomkit-react/package.json index 0ede82f759..05ac1996c9 100644 --- a/packages/roomkit-react/package.json +++ b/packages/roomkit-react/package.json @@ -4,7 +4,6 @@ "main": "dist/index.cjs.js", "module": "dist/index.js", "typings": "dist/index.d.ts", - "type": "module", "keywords": [ "100mslive", "react", diff --git a/packages/roomkit-web/package.json b/packages/roomkit-web/package.json index 4f4837b032..ca0e5f035e 100644 --- a/packages/roomkit-web/package.json +++ b/packages/roomkit-web/package.json @@ -11,7 +11,6 @@ "main": "dist/index.cjs.js", "module": "dist/index.js", "typings": "dist/index.d.ts", - "type": "module", "author": "100ms", "license": "MIT", "repository": { From 7d6852ddab56b7ab045d3a50d5d9569ff12c8a99 Mon Sep 17 00:00:00 2001 From: Kaustubh Kumar Date: Tue, 12 Mar 2024 14:06:58 +0530 Subject: [PATCH 03/14] fix: rename downlink to cqs --- packages/roomkit-react/src/Stats/Stats.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/roomkit-react/src/Stats/Stats.tsx b/packages/roomkit-react/src/Stats/Stats.tsx index 5b37d1c70b..453b9275ee 100644 --- a/packages/roomkit-react/src/Stats/Stats.tsx +++ b/packages/roomkit-react/src/Stats/Stats.tsx @@ -120,7 +120,7 @@ export function VideoTileStats({ videoTrackID, audioTrackID, peerID, isLocal = f value={formatBytes(audioTrackStats?.bitrate, 'b/s')} /> - + From 99513a1371a50a309a4776f9edbfde19d12ed41e Mon Sep 17 00:00:00 2001 From: Kaustubh Kumar Date: Tue, 12 Mar 2024 16:01:00 +0530 Subject: [PATCH 04/14] fix: radio/checkbox shrink for longer options --- packages/roomkit-react/src/Prebuilt/common/utils.js | 2 +- .../components/Polls/common/MultipleChoiceOptions.jsx | 3 ++- .../components/Polls/common/OptionInputWithDelete.tsx | 1 + .../Prebuilt/components/Polls/common/SingleChoiceOptions.jsx | 4 +++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/roomkit-react/src/Prebuilt/common/utils.js b/packages/roomkit-react/src/Prebuilt/common/utils.js index f49820e37b..10f5981840 100644 --- a/packages/roomkit-react/src/Prebuilt/common/utils.js +++ b/packages/roomkit-react/src/Prebuilt/common/utils.js @@ -112,7 +112,7 @@ export const checkCorrectAnswer = (answer, localPeerResponse, type) => { } }; -export const isValidTextInput = (text, minLength = 1, maxLength = 100) => { +export const isValidTextInput = (text, minLength = 1, maxLength = 1024) => { return text && text.length >= minLength && text.length <= maxLength; }; diff --git a/packages/roomkit-react/src/Prebuilt/components/Polls/common/MultipleChoiceOptions.jsx b/packages/roomkit-react/src/Prebuilt/components/Polls/common/MultipleChoiceOptions.jsx index 4b01c78070..88eed72912 100644 --- a/packages/roomkit-react/src/Prebuilt/components/Polls/common/MultipleChoiceOptions.jsx +++ b/packages/roomkit-react/src/Prebuilt/components/Polls/common/MultipleChoiceOptions.jsx @@ -33,7 +33,7 @@ export const MultipleChoiceOptions = ({ {options.map(option => { return ( - + {!isStopped || !isQuiz ? ( handleCheckedChange(checked, option.index)} css={{ cursor: canRespond ? 'pointer' : 'not-allowed', + flexShrink: 0, }} > diff --git a/packages/roomkit-react/src/Prebuilt/components/Polls/common/OptionInputWithDelete.tsx b/packages/roomkit-react/src/Prebuilt/components/Polls/common/OptionInputWithDelete.tsx index 5f4f4b9bbf..d4b5416ae4 100644 --- a/packages/roomkit-react/src/Prebuilt/components/Polls/common/OptionInputWithDelete.tsx +++ b/packages/roomkit-react/src/Prebuilt/components/Polls/common/OptionInputWithDelete.tsx @@ -28,6 +28,7 @@ export const OptionInputWithDelete = ({ value={option?.text || ''} key={index} onChange={event => handleOptionTextChange(index, event.target.value.trimStart())} + maxLength={250} /> removeOption(index)} css={{ bg: 'transparent', border: 'none' }}> diff --git a/packages/roomkit-react/src/Prebuilt/components/Polls/common/SingleChoiceOptions.jsx b/packages/roomkit-react/src/Prebuilt/components/Polls/common/SingleChoiceOptions.jsx index f821e3a39d..172bf70aa5 100644 --- a/packages/roomkit-react/src/Prebuilt/components/Polls/common/SingleChoiceOptions.jsx +++ b/packages/roomkit-react/src/Prebuilt/components/Polls/common/SingleChoiceOptions.jsx @@ -23,7 +23,7 @@ export const SingleChoiceOptions = ({ {options.map(option => { return ( - + {!isStopped || !isQuiz ? ( Date: Tue, 12 Mar 2024 18:08:24 +0530 Subject: [PATCH 05/14] fix: calcuating difference average, av sync and remove unnecessary fields for subscriber stats sample --- .../src/analytics/stats/BaseStatsAnalytics.ts | 4 ++- .../stats/SubscribeStatsAnalytics.ts | 25 +++++++++++++------ .../src/interfaces/webrtc-stats.ts | 1 + 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/hms-video-store/src/analytics/stats/BaseStatsAnalytics.ts b/packages/hms-video-store/src/analytics/stats/BaseStatsAnalytics.ts index 179815a397..b0d16adb0c 100644 --- a/packages/hms-video-store/src/analytics/stats/BaseStatsAnalytics.ts +++ b/packages/hms-video-store/src/analytics/stats/BaseStatsAnalytics.ts @@ -85,6 +85,7 @@ export abstract class RunningTrackAnalytics { protected samples: (LocalBaseSample | LocalVideoSample | RemoteAudioSample | RemoteVideoSample)[] = []; protected tempStats: TempPublishStats[] = []; + protected prevLatestStat?: TempPublishStats; constructor({ track, @@ -118,6 +119,7 @@ export abstract class RunningTrackAnalytics { } this.samples.push(this.collateSample()); + this.prevLatestStat = this.getLatestStat(); this.tempStats.length = 0; } @@ -160,7 +162,7 @@ export abstract class RunningTrackAnalytics { } protected calculateDifferenceForSample(key: keyof TempPublishStats) { - const firstValue = Number(this.tempStats[0][key]) || 0; + const firstValue = Number(this.prevLatestStat?.[key]) || 0; const latestValue = Number(this.getLatestStat()[key]) || 0; return latestValue - firstValue; diff --git a/packages/hms-video-store/src/analytics/stats/SubscribeStatsAnalytics.ts b/packages/hms-video-store/src/analytics/stats/SubscribeStatsAnalytics.ts index 5c44720388..1ca7567d5f 100644 --- a/packages/hms-video-store/src/analytics/stats/SubscribeStatsAnalytics.ts +++ b/packages/hms-video-store/src/analytics/stats/SubscribeStatsAnalytics.ts @@ -92,12 +92,16 @@ export class SubscribeStatsAnalytics extends BaseStatsAnalytics { // eslint-disable-next-line complexity private calculateAvSyncForStat(trackStats: HMSTrackStats, hmsStats: HMSWebrtcStats) { - if (!trackStats.peerID || !(trackStats.kind === 'video')) { + if (!trackStats.peerID || !trackStats.estimatedPlayoutTimestamp || trackStats.kind !== 'video') { return; } const peer = this.store.getPeerById(trackStats.peerID); const audioTrack = peer?.audioTrack; const videoTrack = peer?.videoTrack; + /** + * 1. Send value as MAX_SAFE_INTEGER when either audio or value track is muted for the entire window + * 2. When both audio and video are unmuted for a part of window , then divide the difference by those many number of samples only + */ const areBothTracksEnabled = audioTrack && videoTrack && audioTrack.enabled && videoTrack.enabled; if (!areBothTracksEnabled) { return MAX_SAFE_INTEGER; @@ -106,7 +110,12 @@ export class SubscribeStatsAnalytics extends BaseStatsAnalytics { if (!audioStats) { return MAX_SAFE_INTEGER; } - return audioStats.timestamp - trackStats.timestamp; + if (!audioStats.estimatedPlayoutTimestamp) { + return; + } + + // https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-estimatedplayouttimestamp + return audioStats.estimatedPlayoutTimestamp - trackStats.estimatedPlayoutTimestamp; } } @@ -119,14 +128,9 @@ class RunningRemoteTrackAnalytics extends RunningTrackAnalytics { const baseSample = { timestamp: Date.now(), - fec_packets_discarded: this.calculateDifferenceForSample('fecPacketsDiscarded'), - fec_packets_received: this.calculateDifferenceForSample('fecPacketsReceived'), - total_samples_duration: this.calculateDifferenceForSample('totalSamplesDuration'), - total_packets_received: this.calculateDifferenceForSample('packetsReceived'), - total_packets_lost: this.calculateDifferenceForSample('packetsLost'), total_pli_count: this.calculateDifferenceForSample('pliCount'), total_nack_count: this.calculateDifferenceForSample('nackCount'), - avg_jitter_buffer_delay: this.calculateAverage('calculatedJitterBufferDelay'), + avg_jitter_buffer_delay: this.calculateAverage('calculatedJitterBufferDelay', false), }; if (latestStat.kind === 'video') { @@ -155,6 +159,11 @@ class RunningRemoteTrackAnalytics extends RunningTrackAnalytics { audio_concealed_samples, audio_total_samples_received: this.calculateDifferenceForSample('totalSamplesReceived'), audio_concealment_events: this.calculateDifferenceForSample('concealmentEvents'), + fec_packets_discarded: this.calculateDifferenceForSample('fecPacketsDiscarded'), + fec_packets_received: this.calculateDifferenceForSample('fecPacketsReceived'), + total_samples_duration: this.calculateDifferenceForSample('totalSamplesDuration'), + total_packets_received: this.calculateDifferenceForSample('packetsReceived'), + total_packets_lost: this.calculateDifferenceForSample('packetsLost'), }); } }; diff --git a/packages/hms-video-store/src/interfaces/webrtc-stats.ts b/packages/hms-video-store/src/interfaces/webrtc-stats.ts index edcf6452d5..05d5613e25 100644 --- a/packages/hms-video-store/src/interfaces/webrtc-stats.ts +++ b/packages/hms-video-store/src/interfaces/webrtc-stats.ts @@ -57,6 +57,7 @@ export interface MissingInboundStats extends RTCInboundRtpStreamStats, MissingCo totalFreezesDuration?: number; jitterBufferDelay?: number; jitterBufferEmittedCount?: number; + estimatedPlayoutTimestamp?: DOMHighResTimeStamp; } export type PeerConnectionType = 'publish' | 'subscribe'; From aa32029cb32b3505017622d9ddd774f6a4c026f1 Mon Sep 17 00:00:00 2001 From: Kaustubh Kumar Date: Fri, 15 Mar 2024 11:37:20 +0530 Subject: [PATCH 06/14] fix: save correct answers in draft quizzes --- .../HMSInteractivityCenter.ts | 14 +++++++++++++- .../Polls/CreateQuestions/CreateQuestions.jsx | 12 ++++++------ .../Polls/CreateQuestions/SavedQuestion.tsx | 16 ++++++++++++++-- .../Polls/common/MultipleChoiceOptions.jsx | 2 +- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/packages/hms-video-store/src/session-store/interactivity-center/HMSInteractivityCenter.ts b/packages/hms-video-store/src/session-store/interactivity-center/HMSInteractivityCenter.ts index 4e4d93a5ed..95fc81de7a 100644 --- a/packages/hms-video-store/src/session-store/interactivity-center/HMSInteractivityCenter.ts +++ b/packages/hms-video-store/src/session-store/interactivity-center/HMSInteractivityCenter.ts @@ -195,10 +195,23 @@ export class InteractivityCenter implements HMSInteractivityCenter { return polls; } + // eslint-disable-next-line complexity private createQuestionSetParams(questionParams: HMSPollQuestionCreateParams, index: number): PollQuestionParams { + // early return if the question has been saved before in a draft + if (questionParams.index) { + const optionsWithIndex = questionParams.options?.map((option, index) => { + return { ...option, index: index + 1 }; + }); + return { + question: { ...questionParams, index: index + 1 }, + options: optionsWithIndex, + answer: questionParams.answer, + }; + } const question: PollQuestionParams['question'] = { ...questionParams, index: index + 1 }; let options: HMSPollQuestionOption[] | undefined; const answer: HMSPollQuestionAnswer = questionParams.answer || { hidden: false }; + if ( Array.isArray(questionParams.options) && [HMSPollQuestionType.SINGLE_CHOICE, HMSPollQuestionType.MULTIPLE_CHOICE].includes(questionParams.type) @@ -209,7 +222,6 @@ export class InteractivityCenter implements HMSInteractivityCenter { weight: option.weight, })); - delete answer?.text; if (questionParams.type === HMSPollQuestionType.SINGLE_CHOICE) { answer.option = questionParams.options.findIndex(option => option.isCorrectAnswer) + 1 || undefined; } else { diff --git a/packages/roomkit-react/src/Prebuilt/components/Polls/CreateQuestions/CreateQuestions.jsx b/packages/roomkit-react/src/Prebuilt/components/Polls/CreateQuestions/CreateQuestions.jsx index 23d5319ee5..a97b83f2e3 100644 --- a/packages/roomkit-react/src/Prebuilt/components/Polls/CreateQuestions/CreateQuestions.jsx +++ b/packages/roomkit-react/src/Prebuilt/components/Polls/CreateQuestions/CreateQuestions.jsx @@ -75,15 +75,15 @@ export function CreateQuestions() { const updatedQuestions = [...questions.slice(0, index), questionParams, ...questions.slice(index + 1)]; setQuestions(updatedQuestions); const validQuestions = updatedQuestions.filter(question => isValidQuestion(question)); - await actions.interactivityCenter.addQuestionsToPoll(id, validQuestions); }} isQuiz={isQuiz} - removeQuestion={questionID => - setQuestions(prev => { - return prev.filter(questionFromSet => questionID !== questionFromSet?.draftID); - }) - } + removeQuestion={async questionID => { + const updatedQuestions = questions.filter(questionFromSet => questionID !== questionFromSet?.draftID); + setQuestions(updatedQuestions); + const validQuestions = updatedQuestions.filter(question => isValidQuestion(question)); + await actions.interactivityCenter.addQuestionsToPoll(id, validQuestions); + }} convertToDraft={questionID => setQuestions(prev => { const copyOfQuestions = [...prev]; diff --git a/packages/roomkit-react/src/Prebuilt/components/Polls/CreateQuestions/SavedQuestion.tsx b/packages/roomkit-react/src/Prebuilt/components/Polls/CreateQuestions/SavedQuestion.tsx index 526f003734..5878ae2ca9 100644 --- a/packages/roomkit-react/src/Prebuilt/components/Polls/CreateQuestions/SavedQuestion.tsx +++ b/packages/roomkit-react/src/Prebuilt/components/Polls/CreateQuestions/SavedQuestion.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useMemo } from 'react'; import { HMSPollQuestion } from '@100mslive/react-sdk'; import { CheckCircleIcon } from '@100mslive/react-icons'; import { Button, Flex, Text } from '../../../../'; @@ -15,6 +15,18 @@ export const SavedQuestion = ({ length: number; convertToDraft: (draftID: number) => void; }) => { + const answerArray = useMemo(() => { + const updatedAnswerArray = []; + const { option, options } = question?.answer ?? {}; + if (option) { + updatedAnswerArray.push(option); + } + if (options) { + updatedAnswerArray.push(...options); + } + return updatedAnswerArray; + }, [question?.answer]); + return ( <> @@ -30,7 +42,7 @@ export const SavedQuestion = ({ {option.text} {/* @ts-ignore */} - {option.isCorrectAnswer && ( + {(answerArray.includes(index + 1) || option.isCorrectAnswer) && ( diff --git a/packages/roomkit-react/src/Prebuilt/components/Polls/common/MultipleChoiceOptions.jsx b/packages/roomkit-react/src/Prebuilt/components/Polls/common/MultipleChoiceOptions.jsx index 88eed72912..bc779d9120 100644 --- a/packages/roomkit-react/src/Prebuilt/components/Polls/common/MultipleChoiceOptions.jsx +++ b/packages/roomkit-react/src/Prebuilt/components/Polls/common/MultipleChoiceOptions.jsx @@ -52,7 +52,7 @@ export const MultipleChoiceOptions = ({ ) : null} {isStopped && correctOptionIndexes?.includes(option.index) ? ( - + ) : null} From 764c784f0db15ed7a54650e11d7bb4045277a3fb Mon Sep 17 00:00:00 2001 From: Kaustubh Kumar Date: Fri, 15 Mar 2024 11:38:51 +0530 Subject: [PATCH 07/14] feat: calculate total usage for plugin --- .../src/analytics/AnalyticsEventFactory.ts | 18 +++++++ .../src/common/PluginUsageTracker.ts | 53 +++++++++++++++++++ packages/hms-video-store/src/common/index.ts | 1 + packages/hms-video-store/src/index.ts | 1 + .../plugins/audio/AudioPluginsAnalytics.ts | 1 + packages/hms-video-store/src/sdk/index.ts | 5 +- .../hms-video-store/src/transport/index.ts | 3 ++ 7 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 packages/hms-video-store/src/common/PluginUsageTracker.ts create mode 100644 packages/hms-video-store/src/common/index.ts diff --git a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts index 1c897ab980..8a70bf8259 100644 --- a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts +++ b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts @@ -3,6 +3,7 @@ import { AdditionalAnalyticsProperties } from './AdditionalAnalyticsProperties'; import AnalyticsEvent from './AnalyticsEvent'; import { AnalyticsEventLevel } from './AnalyticsEventLevel'; import { IAnalyticsPropertiesProvider } from './IAnalyticsPropertiesProvider'; +import { pluginUsageTracker } from '../common'; import { HMSException } from '../error/HMSException'; import { DeviceMap, SelectedDevices } from '../interfaces'; import { HMSTrackSettings } from '../media/settings/HMSTrackSettings'; @@ -235,6 +236,23 @@ export default class AnalyticsEventFactory { }); } + static getKrispUsage(sessionID: string) { + const duration = pluginUsageTracker.getPluginUsage('HMSKrispPlugin', sessionID); + return new AnalyticsEvent({ + name: 'krisp.usage', + level: AnalyticsEventLevel.INFO, + properties: { duration }, + }); + } + + static transportLeave() { + return new AnalyticsEvent({ + name: 'transport.leave', + level: AnalyticsEventLevel.INFO, + properties: {}, + }); + } + private static eventNameFor(name: string, ok: boolean) { const suffix = ok ? 'success' : 'failed'; return `${name}.${suffix}`; diff --git a/packages/hms-video-store/src/common/PluginUsageTracker.ts b/packages/hms-video-store/src/common/PluginUsageTracker.ts new file mode 100644 index 0000000000..248550ff41 --- /dev/null +++ b/packages/hms-video-store/src/common/PluginUsageTracker.ts @@ -0,0 +1,53 @@ +import AnalyticsEvent from '../analytics/AnalyticsEvent'; + +class PluginUsageTracker { + private pluginUsage: Map = new Map(); + private pluginLastAddedAt: Map = new Map(); + + 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(); diff --git a/packages/hms-video-store/src/common/index.ts b/packages/hms-video-store/src/common/index.ts new file mode 100644 index 0000000000..44f3432f1e --- /dev/null +++ b/packages/hms-video-store/src/common/index.ts @@ -0,0 +1 @@ +export { pluginUsageTracker } from './PluginUsageTracker'; diff --git a/packages/hms-video-store/src/index.ts b/packages/hms-video-store/src/index.ts index dfc3890b9f..2cce36b2dd 100644 --- a/packages/hms-video-store/src/index.ts +++ b/packages/hms-video-store/src/index.ts @@ -53,6 +53,7 @@ export type { HMSQuizLeaderboardSummary, } from './internal'; +export { pluginUsageTracker } from './common'; export { HMSReactiveStore } from './reactive-store/HMSReactiveStore'; export { HMSPluginUnsupportedTypes, HMSRecordingState, HLSPlaylistType } from './internal'; export type { diff --git a/packages/hms-video-store/src/plugins/audio/AudioPluginsAnalytics.ts b/packages/hms-video-store/src/plugins/audio/AudioPluginsAnalytics.ts index 08801d07eb..30629c4bdf 100644 --- a/packages/hms-video-store/src/plugins/audio/AudioPluginsAnalytics.ts +++ b/packages/hms-video-store/src/plugins/audio/AudioPluginsAnalytics.ts @@ -24,6 +24,7 @@ export class AudioPluginsAnalytics { this.addedTimestamps[name] = Date.now(); this.initTime[name] = 0; this.pluginSampleRate[name] = sampleRate; + this.eventBus.analytics.publish(MediaPluginsAnalyticsFactory.added(name, this.addedTimestamps[name])); } removed(name: string) { diff --git a/packages/hms-video-store/src/sdk/index.ts b/packages/hms-video-store/src/sdk/index.ts index f5c263a5d4..5d8de0e8ea 100644 --- a/packages/hms-video-store/src/sdk/index.ts +++ b/packages/hms-video-store/src/sdk/index.ts @@ -12,6 +12,7 @@ import { HMSAnalyticsLevel } from '../analytics/AnalyticsEventLevel'; import { AnalyticsEventsService } from '../analytics/AnalyticsEventsService'; import { AnalyticsTimer, TimedEvent } from '../analytics/AnalyticsTimer'; import { AudioSinkManager } from '../audio-sink-manager'; +import { pluginUsageTracker } from '../common/PluginUsageTracker'; import { DeviceManager } from '../device-manager'; import { AudioOutputManager } from '../device-manager/AudioOutputManager'; import { DeviceStorageManager } from '../device-manager/DeviceStorage'; @@ -181,7 +182,6 @@ export class HMSSdk implements HMSInterface { ); this.sessionStore = new SessionStore(this.transport); this.interactivityCenter = new InteractivityCenter(this.transport, this.store, this.listener); - /** * Note: Subscribe to events here right after creating stores and managers * to not miss events that are published before the handlers are subscribed. @@ -498,6 +498,7 @@ export class HMSSdk implements HMSInterface { this.errorListener?.onError(error); }; + // eslint-disable-next-line complexity async join(config: HMSConfig, listener: HMSUpdateListener) { validateMediaDevicesExistence(); validateRTCPeerConnection(); @@ -571,6 +572,8 @@ export class HMSSdk implements HMSInterface { throw error; } HMSLogger.timeEnd(`join-room-${roomId}`); + const sessionID = this.store.getRoom()?.sessionId || ''; + this.eventBus.analytics.subscribe(e => pluginUsageTracker.updatePluginUsageData(e, sessionID)); } private stringifyMetadata(config: HMSConfig) { diff --git a/packages/hms-video-store/src/transport/index.ts b/packages/hms-video-store/src/transport/index.ts index fc6a168e99..a4f45f8a5d 100644 --- a/packages/hms-video-store/src/transport/index.ts +++ b/packages/hms-video-store/src/transport/index.ts @@ -495,6 +495,9 @@ export default class HMSTransport { this.joinParameters = undefined; HMSLogger.d(TAG, 'leaving in transport'); try { + const sessionID = this.store.getRoom()?.sessionId || ''; + this.eventBus.analytics.publish(AnalyticsEventFactory.getKrispUsage(sessionID)); + this.eventBus.analytics.publish(AnalyticsEventFactory.transportLeave()); this.state = TransportState.Leaving; this.publishStatsAnalytics?.stop(); this.subscribeStatsAnalytics?.stop(); From 83c45afe20dd322fb745fff93da841697fd87a64 Mon Sep 17 00:00:00 2001 From: Ravi theja Date: Fri, 15 Mar 2024 11:48:41 +0530 Subject: [PATCH 08/14] Revert "feat: calculate total usage for plugin" --- .../src/analytics/AnalyticsEventFactory.ts | 18 ------- .../src/common/PluginUsageTracker.ts | 53 ------------------- packages/hms-video-store/src/common/index.ts | 1 - packages/hms-video-store/src/index.ts | 1 - .../plugins/audio/AudioPluginsAnalytics.ts | 1 - packages/hms-video-store/src/sdk/index.ts | 5 +- .../hms-video-store/src/transport/index.ts | 3 -- 7 files changed, 1 insertion(+), 81 deletions(-) delete mode 100644 packages/hms-video-store/src/common/PluginUsageTracker.ts delete mode 100644 packages/hms-video-store/src/common/index.ts diff --git a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts index 8a70bf8259..1c897ab980 100644 --- a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts +++ b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts @@ -3,7 +3,6 @@ import { AdditionalAnalyticsProperties } from './AdditionalAnalyticsProperties'; import AnalyticsEvent from './AnalyticsEvent'; import { AnalyticsEventLevel } from './AnalyticsEventLevel'; import { IAnalyticsPropertiesProvider } from './IAnalyticsPropertiesProvider'; -import { pluginUsageTracker } from '../common'; import { HMSException } from '../error/HMSException'; import { DeviceMap, SelectedDevices } from '../interfaces'; import { HMSTrackSettings } from '../media/settings/HMSTrackSettings'; @@ -236,23 +235,6 @@ export default class AnalyticsEventFactory { }); } - static getKrispUsage(sessionID: string) { - const duration = pluginUsageTracker.getPluginUsage('HMSKrispPlugin', sessionID); - return new AnalyticsEvent({ - name: 'krisp.usage', - level: AnalyticsEventLevel.INFO, - properties: { duration }, - }); - } - - static transportLeave() { - return new AnalyticsEvent({ - name: 'transport.leave', - level: AnalyticsEventLevel.INFO, - properties: {}, - }); - } - private static eventNameFor(name: string, ok: boolean) { const suffix = ok ? 'success' : 'failed'; return `${name}.${suffix}`; diff --git a/packages/hms-video-store/src/common/PluginUsageTracker.ts b/packages/hms-video-store/src/common/PluginUsageTracker.ts deleted file mode 100644 index 248550ff41..0000000000 --- a/packages/hms-video-store/src/common/PluginUsageTracker.ts +++ /dev/null @@ -1,53 +0,0 @@ -import AnalyticsEvent from '../analytics/AnalyticsEvent'; - -class PluginUsageTracker { - private pluginUsage: Map = new Map(); - private pluginLastAddedAt: Map = new Map(); - - 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(); diff --git a/packages/hms-video-store/src/common/index.ts b/packages/hms-video-store/src/common/index.ts deleted file mode 100644 index 44f3432f1e..0000000000 --- a/packages/hms-video-store/src/common/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { pluginUsageTracker } from './PluginUsageTracker'; diff --git a/packages/hms-video-store/src/index.ts b/packages/hms-video-store/src/index.ts index 2cce36b2dd..dfc3890b9f 100644 --- a/packages/hms-video-store/src/index.ts +++ b/packages/hms-video-store/src/index.ts @@ -53,7 +53,6 @@ export type { HMSQuizLeaderboardSummary, } from './internal'; -export { pluginUsageTracker } from './common'; export { HMSReactiveStore } from './reactive-store/HMSReactiveStore'; export { HMSPluginUnsupportedTypes, HMSRecordingState, HLSPlaylistType } from './internal'; export type { diff --git a/packages/hms-video-store/src/plugins/audio/AudioPluginsAnalytics.ts b/packages/hms-video-store/src/plugins/audio/AudioPluginsAnalytics.ts index 30629c4bdf..08801d07eb 100644 --- a/packages/hms-video-store/src/plugins/audio/AudioPluginsAnalytics.ts +++ b/packages/hms-video-store/src/plugins/audio/AudioPluginsAnalytics.ts @@ -24,7 +24,6 @@ export class AudioPluginsAnalytics { this.addedTimestamps[name] = Date.now(); this.initTime[name] = 0; this.pluginSampleRate[name] = sampleRate; - this.eventBus.analytics.publish(MediaPluginsAnalyticsFactory.added(name, this.addedTimestamps[name])); } removed(name: string) { diff --git a/packages/hms-video-store/src/sdk/index.ts b/packages/hms-video-store/src/sdk/index.ts index 5d8de0e8ea..f5c263a5d4 100644 --- a/packages/hms-video-store/src/sdk/index.ts +++ b/packages/hms-video-store/src/sdk/index.ts @@ -12,7 +12,6 @@ import { HMSAnalyticsLevel } from '../analytics/AnalyticsEventLevel'; import { AnalyticsEventsService } from '../analytics/AnalyticsEventsService'; import { AnalyticsTimer, TimedEvent } from '../analytics/AnalyticsTimer'; import { AudioSinkManager } from '../audio-sink-manager'; -import { pluginUsageTracker } from '../common/PluginUsageTracker'; import { DeviceManager } from '../device-manager'; import { AudioOutputManager } from '../device-manager/AudioOutputManager'; import { DeviceStorageManager } from '../device-manager/DeviceStorage'; @@ -182,6 +181,7 @@ export class HMSSdk implements HMSInterface { ); this.sessionStore = new SessionStore(this.transport); this.interactivityCenter = new InteractivityCenter(this.transport, this.store, this.listener); + /** * Note: Subscribe to events here right after creating stores and managers * to not miss events that are published before the handlers are subscribed. @@ -498,7 +498,6 @@ export class HMSSdk implements HMSInterface { this.errorListener?.onError(error); }; - // eslint-disable-next-line complexity async join(config: HMSConfig, listener: HMSUpdateListener) { validateMediaDevicesExistence(); validateRTCPeerConnection(); @@ -572,8 +571,6 @@ export class HMSSdk implements HMSInterface { throw error; } HMSLogger.timeEnd(`join-room-${roomId}`); - const sessionID = this.store.getRoom()?.sessionId || ''; - this.eventBus.analytics.subscribe(e => pluginUsageTracker.updatePluginUsageData(e, sessionID)); } private stringifyMetadata(config: HMSConfig) { diff --git a/packages/hms-video-store/src/transport/index.ts b/packages/hms-video-store/src/transport/index.ts index a4f45f8a5d..fc6a168e99 100644 --- a/packages/hms-video-store/src/transport/index.ts +++ b/packages/hms-video-store/src/transport/index.ts @@ -495,9 +495,6 @@ export default class HMSTransport { this.joinParameters = undefined; HMSLogger.d(TAG, 'leaving in transport'); try { - const sessionID = this.store.getRoom()?.sessionId || ''; - this.eventBus.analytics.publish(AnalyticsEventFactory.getKrispUsage(sessionID)); - this.eventBus.analytics.publish(AnalyticsEventFactory.transportLeave()); this.state = TransportState.Leaving; this.publishStatsAnalytics?.stop(); this.subscribeStatsAnalytics?.stop(); From 8aafe5f7eea1ac66fb48451a5948cdfd4cf2cc1a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 15 Mar 2024 11:53:05 +0530 Subject: [PATCH 09/14] build: update versions for release --- .../prebuilt-react-integration/package.json | 2 +- packages/hls-player/package.json | 4 +-- packages/hls-stats/package.json | 2 +- packages/hms-video-store/package.json | 2 +- packages/hms-virtual-background/package.json | 6 ++-- packages/react-icons/package.json | 2 +- packages/react-sdk/package.json | 4 +-- packages/roomkit-react/package.json | 10 +++--- packages/roomkit-web/package.json | 4 +-- yarn.lock | 31 +++++++++++++++++-- 10 files changed, 46 insertions(+), 21 deletions(-) diff --git a/examples/prebuilt-react-integration/package.json b/examples/prebuilt-react-integration/package.json index 0ab13ba996..f0e8dad4ee 100644 --- a/examples/prebuilt-react-integration/package.json +++ b/examples/prebuilt-react-integration/package.json @@ -10,7 +10,7 @@ "preview": "vite preview" }, "dependencies": { - "@100mslive/roomkit-react": "0.3.1", + "@100mslive/roomkit-react": "0.3.2", "react": "^18.2.0", "react-dom": "^18.2.0" }, diff --git a/packages/hls-player/package.json b/packages/hls-player/package.json index 22051e3eb0..ae95358b8d 100644 --- a/packages/hls-player/package.json +++ b/packages/hls-player/package.json @@ -1,6 +1,6 @@ { "name": "@100mslive/hls-player", - "version": "0.3.1", + "version": "0.3.2", "description": "HLS client library which uses HTML5 Video element and Media Source Extension for playback", "main": "dist/index.cjs.js", "module": "dist/index.js", @@ -36,7 +36,7 @@ "author": "100ms", "license": "MIT", "dependencies": { - "@100mslive/hls-stats": "0.4.1", + "@100mslive/hls-stats": "0.4.2", "eventemitter2": "^6.4.9", "hls.js": "1.4.12" } diff --git a/packages/hls-stats/package.json b/packages/hls-stats/package.json index 5da917ca71..3903f200ea 100644 --- a/packages/hls-stats/package.json +++ b/packages/hls-stats/package.json @@ -1,6 +1,6 @@ { "name": "@100mslive/hls-stats", - "version": "0.4.1", + "version": "0.4.2", "description": "A simple library that provides stats for your hls stream", "main": "dist/index.cjs.js", "module": "dist/index.js", diff --git a/packages/hms-video-store/package.json b/packages/hms-video-store/package.json index 5c07956221..af7d4803aa 100644 --- a/packages/hms-video-store/package.json +++ b/packages/hms-video-store/package.json @@ -1,5 +1,5 @@ { - "version": "0.12.1", + "version": "0.12.2", "license": "MIT", "repository": { "type": "git", diff --git a/packages/hms-virtual-background/package.json b/packages/hms-virtual-background/package.json index 4f105d174b..7a52ff653a 100755 --- a/packages/hms-virtual-background/package.json +++ b/packages/hms-virtual-background/package.json @@ -1,5 +1,5 @@ { - "version": "1.13.1", + "version": "1.13.2", "license": "MIT", "name": "@100mslive/hms-virtual-background", "author": "100ms", @@ -32,10 +32,10 @@ "format": "prettier --write src/**/*.ts" }, "peerDependencies": { - "@100mslive/hms-video-store": "0.12.1" + "@100mslive/hms-video-store": "0.12.2" }, "devDependencies": { - "@100mslive/hms-video-store": "0.12.1" + "@100mslive/hms-video-store": "0.12.2" }, "dependencies": { "@mediapipe/selfie_segmentation": "^0.1.1632777926", diff --git a/packages/react-icons/package.json b/packages/react-icons/package.json index 5b3b3ed759..67803a405f 100644 --- a/packages/react-icons/package.json +++ b/packages/react-icons/package.json @@ -4,7 +4,7 @@ "main": "dist/index.cjs.js", "module": "dist/index.js", "typings": "dist/index.d.ts", - "version": "0.10.1", + "version": "0.10.2", "author": "100ms", "license": "MIT", "repository": { diff --git a/packages/react-sdk/package.json b/packages/react-sdk/package.json index 2bb16efd01..b8272cd6e7 100644 --- a/packages/react-sdk/package.json +++ b/packages/react-sdk/package.json @@ -4,7 +4,7 @@ "main": "dist/index.cjs.js", "module": "dist/index.js", "typings": "dist/index.d.ts", - "version": "0.10.1", + "version": "0.10.2", "author": "100ms", "license": "MIT", "repository": { @@ -48,7 +48,7 @@ "react": ">=16.8 <19.0.0" }, "dependencies": { - "@100mslive/hms-video-store": "0.12.1", + "@100mslive/hms-video-store": "0.12.2", "react-resize-detector": "^7.0.0", "zustand": "^3.6.2" } diff --git a/packages/roomkit-react/package.json b/packages/roomkit-react/package.json index 05ac1996c9..5c85124d1a 100644 --- a/packages/roomkit-react/package.json +++ b/packages/roomkit-react/package.json @@ -10,7 +10,7 @@ "prebuilt", "roomkit" ], - "version": "0.3.1", + "version": "0.3.2", "author": "100ms", "license": "MIT", "repository": { @@ -82,11 +82,11 @@ "react": ">=17.0.2 <19.0.0" }, "dependencies": { - "@100mslive/hls-player": "0.3.1", + "@100mslive/hls-player": "0.3.2", "@100mslive/hms-noise-cancellation": "0.0.0-alpha.1", - "@100mslive/hms-virtual-background": "1.13.1", - "@100mslive/react-icons": "0.10.1", - "@100mslive/react-sdk": "0.10.1", + "@100mslive/hms-virtual-background": "1.13.2", + "@100mslive/react-icons": "0.10.2", + "@100mslive/react-sdk": "0.10.2", "@100mslive/types-prebuilt": "0.12.7", "@emoji-mart/data": "^1.0.6", "@emoji-mart/react": "^1.0.1", diff --git a/packages/roomkit-web/package.json b/packages/roomkit-web/package.json index ca0e5f035e..2fc5bc1573 100644 --- a/packages/roomkit-web/package.json +++ b/packages/roomkit-web/package.json @@ -1,6 +1,6 @@ { "name": "@100mslive/roomkit-web", - "version": "0.2.1", + "version": "0.2.2", "description": "A web component implementation of 100ms Prebuilt component", "keywords": [ "web-components", @@ -33,7 +33,7 @@ "build": "rm -rf dist && node ../../scripts/build-webapp" }, "dependencies": { - "@100mslive/roomkit-react": "0.3.1", + "@100mslive/roomkit-react": "0.3.2", "@r2wc/react-to-web-component": "2.0.2" } } diff --git a/yarn.lock b/yarn.lock index df9c962f3c..6b77c85e5c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15781,7 +15781,16 @@ string-natural-compare@^3.0.1: resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4" integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw== -"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0": + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -15881,7 +15890,14 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -17178,7 +17194,7 @@ worker-timers@^7.0.40: worker-timers-broker "^6.0.95" worker-timers-worker "^7.0.59" -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -17196,6 +17212,15 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" +wrap-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" From ea856832343f6038828290fc82a6b40f00c46804 Mon Sep 17 00:00:00 2001 From: Kaustubh Kumar Date: Fri, 15 Mar 2024 11:54:41 +0530 Subject: [PATCH 10/14] feat: calculate total usage for plugin --- .../src/analytics/AnalyticsEventFactory.ts | 18 +++++++ .../src/common/PluginUsageTracker.ts | 53 +++++++++++++++++++ packages/hms-video-store/src/common/index.ts | 1 + packages/hms-video-store/src/index.ts | 1 + .../plugins/audio/AudioPluginsAnalytics.ts | 1 + packages/hms-video-store/src/sdk/index.ts | 5 +- .../hms-video-store/src/transport/index.ts | 3 ++ 7 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 packages/hms-video-store/src/common/PluginUsageTracker.ts create mode 100644 packages/hms-video-store/src/common/index.ts diff --git a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts index 1c897ab980..8a70bf8259 100644 --- a/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts +++ b/packages/hms-video-store/src/analytics/AnalyticsEventFactory.ts @@ -3,6 +3,7 @@ import { AdditionalAnalyticsProperties } from './AdditionalAnalyticsProperties'; import AnalyticsEvent from './AnalyticsEvent'; import { AnalyticsEventLevel } from './AnalyticsEventLevel'; import { IAnalyticsPropertiesProvider } from './IAnalyticsPropertiesProvider'; +import { pluginUsageTracker } from '../common'; import { HMSException } from '../error/HMSException'; import { DeviceMap, SelectedDevices } from '../interfaces'; import { HMSTrackSettings } from '../media/settings/HMSTrackSettings'; @@ -235,6 +236,23 @@ export default class AnalyticsEventFactory { }); } + static getKrispUsage(sessionID: string) { + const duration = pluginUsageTracker.getPluginUsage('HMSKrispPlugin', sessionID); + return new AnalyticsEvent({ + name: 'krisp.usage', + level: AnalyticsEventLevel.INFO, + properties: { duration }, + }); + } + + static transportLeave() { + return new AnalyticsEvent({ + name: 'transport.leave', + level: AnalyticsEventLevel.INFO, + properties: {}, + }); + } + private static eventNameFor(name: string, ok: boolean) { const suffix = ok ? 'success' : 'failed'; return `${name}.${suffix}`; diff --git a/packages/hms-video-store/src/common/PluginUsageTracker.ts b/packages/hms-video-store/src/common/PluginUsageTracker.ts new file mode 100644 index 0000000000..248550ff41 --- /dev/null +++ b/packages/hms-video-store/src/common/PluginUsageTracker.ts @@ -0,0 +1,53 @@ +import AnalyticsEvent from '../analytics/AnalyticsEvent'; + +class PluginUsageTracker { + private pluginUsage: Map = new Map(); + private pluginLastAddedAt: Map = new Map(); + + 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(); diff --git a/packages/hms-video-store/src/common/index.ts b/packages/hms-video-store/src/common/index.ts new file mode 100644 index 0000000000..44f3432f1e --- /dev/null +++ b/packages/hms-video-store/src/common/index.ts @@ -0,0 +1 @@ +export { pluginUsageTracker } from './PluginUsageTracker'; diff --git a/packages/hms-video-store/src/index.ts b/packages/hms-video-store/src/index.ts index dfc3890b9f..2cce36b2dd 100644 --- a/packages/hms-video-store/src/index.ts +++ b/packages/hms-video-store/src/index.ts @@ -53,6 +53,7 @@ export type { HMSQuizLeaderboardSummary, } from './internal'; +export { pluginUsageTracker } from './common'; export { HMSReactiveStore } from './reactive-store/HMSReactiveStore'; export { HMSPluginUnsupportedTypes, HMSRecordingState, HLSPlaylistType } from './internal'; export type { diff --git a/packages/hms-video-store/src/plugins/audio/AudioPluginsAnalytics.ts b/packages/hms-video-store/src/plugins/audio/AudioPluginsAnalytics.ts index 08801d07eb..30629c4bdf 100644 --- a/packages/hms-video-store/src/plugins/audio/AudioPluginsAnalytics.ts +++ b/packages/hms-video-store/src/plugins/audio/AudioPluginsAnalytics.ts @@ -24,6 +24,7 @@ export class AudioPluginsAnalytics { this.addedTimestamps[name] = Date.now(); this.initTime[name] = 0; this.pluginSampleRate[name] = sampleRate; + this.eventBus.analytics.publish(MediaPluginsAnalyticsFactory.added(name, this.addedTimestamps[name])); } removed(name: string) { diff --git a/packages/hms-video-store/src/sdk/index.ts b/packages/hms-video-store/src/sdk/index.ts index f5c263a5d4..5d8de0e8ea 100644 --- a/packages/hms-video-store/src/sdk/index.ts +++ b/packages/hms-video-store/src/sdk/index.ts @@ -12,6 +12,7 @@ import { HMSAnalyticsLevel } from '../analytics/AnalyticsEventLevel'; import { AnalyticsEventsService } from '../analytics/AnalyticsEventsService'; import { AnalyticsTimer, TimedEvent } from '../analytics/AnalyticsTimer'; import { AudioSinkManager } from '../audio-sink-manager'; +import { pluginUsageTracker } from '../common/PluginUsageTracker'; import { DeviceManager } from '../device-manager'; import { AudioOutputManager } from '../device-manager/AudioOutputManager'; import { DeviceStorageManager } from '../device-manager/DeviceStorage'; @@ -181,7 +182,6 @@ export class HMSSdk implements HMSInterface { ); this.sessionStore = new SessionStore(this.transport); this.interactivityCenter = new InteractivityCenter(this.transport, this.store, this.listener); - /** * Note: Subscribe to events here right after creating stores and managers * to not miss events that are published before the handlers are subscribed. @@ -498,6 +498,7 @@ export class HMSSdk implements HMSInterface { this.errorListener?.onError(error); }; + // eslint-disable-next-line complexity async join(config: HMSConfig, listener: HMSUpdateListener) { validateMediaDevicesExistence(); validateRTCPeerConnection(); @@ -571,6 +572,8 @@ export class HMSSdk implements HMSInterface { throw error; } HMSLogger.timeEnd(`join-room-${roomId}`); + const sessionID = this.store.getRoom()?.sessionId || ''; + this.eventBus.analytics.subscribe(e => pluginUsageTracker.updatePluginUsageData(e, sessionID)); } private stringifyMetadata(config: HMSConfig) { diff --git a/packages/hms-video-store/src/transport/index.ts b/packages/hms-video-store/src/transport/index.ts index fc6a168e99..a4f45f8a5d 100644 --- a/packages/hms-video-store/src/transport/index.ts +++ b/packages/hms-video-store/src/transport/index.ts @@ -495,6 +495,9 @@ export default class HMSTransport { this.joinParameters = undefined; HMSLogger.d(TAG, 'leaving in transport'); try { + const sessionID = this.store.getRoom()?.sessionId || ''; + this.eventBus.analytics.publish(AnalyticsEventFactory.getKrispUsage(sessionID)); + this.eventBus.analytics.publish(AnalyticsEventFactory.transportLeave()); this.state = TransportState.Leaving; this.publishStatsAnalytics?.stop(); this.subscribeStatsAnalytics?.stop(); From aeadfc9452709564f74f0a87ee51421a3b79ae6f Mon Sep 17 00:00:00 2001 From: Kaustubh Kumar Date: Fri, 15 Mar 2024 14:46:17 +0530 Subject: [PATCH 11/14] fix: use more efficient preset for effects vb (#2706) --- packages/hms-virtual-background/src/HMSEffectsPlugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hms-virtual-background/src/HMSEffectsPlugin.ts b/packages/hms-virtual-background/src/HMSEffectsPlugin.ts index b8a3ed5f5b..372d167ff3 100644 --- a/packages/hms-virtual-background/src/HMSEffectsPlugin.ts +++ b/packages/hms-virtual-background/src/HMSEffectsPlugin.ts @@ -11,7 +11,7 @@ export class HMSEffectsPlugin implements HMSMediaStreamPlugin { private blurAmount = 0; private background: HMSEffectsBackground = HMSVirtualBackgroundTypes.NONE; private backgroundType = HMSVirtualBackgroundTypes.NONE; - private preset = 'balanced'; + private preset = 'lightning'; constructor(effectsSDKKey: string) { this.effects = new tsvb(effectsSDKKey); From 0ba911f260153022ba63be1330af058167a2cfab Mon Sep 17 00:00:00 2001 From: Kaustubh Kumar Date: Fri, 15 Mar 2024 14:46:51 +0530 Subject: [PATCH 12/14] fix: casing for lower all hands --- .../src/Prebuilt/components/Footer/RoleAccordion.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/roomkit-react/src/Prebuilt/components/Footer/RoleAccordion.tsx b/packages/roomkit-react/src/Prebuilt/components/Footer/RoleAccordion.tsx index 0eec2bef23..ce931ae60c 100644 --- a/packages/roomkit-react/src/Prebuilt/components/Footer/RoleAccordion.tsx +++ b/packages/roomkit-react/src/Prebuilt/components/Footer/RoleAccordion.tsx @@ -153,7 +153,7 @@ export const RoleAccordion = ({ {canBringToStage && (