From 05d6ecb97ce5d31e087bff67e11ab8c02014bfcb Mon Sep 17 00:00:00 2001 From: KaustubhKumar05 Date: Thu, 14 Nov 2024 12:16:51 +0530 Subject: [PATCH] feat: internal method to check if recording should continue --- packages/hms-video-store/src/IHMSActions.ts | 7 +++++++ .../src/reactive-store/HMSSDKActions.ts | 21 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/packages/hms-video-store/src/IHMSActions.ts b/packages/hms-video-store/src/IHMSActions.ts index 01cc905201..bcfe6dbdbc 100644 --- a/packages/hms-video-store/src/IHMSActions.ts +++ b/packages/hms-video-store/src/IHMSActions.ts @@ -40,6 +40,7 @@ import { IHMSSessionStoreActions, } from './schema'; import { HMSRoleChangeRequest } from './selectors'; +import { HMSStats } from './webrtc-stats'; /** * The below interface defines our SDK API Surface for taking room related actions. @@ -587,4 +588,10 @@ export interface IHMSActions> = (fn, name) => { return this.store.namedSetState(fn, name); }; + + /** + * @internal + * This will be used by beam to check if the recording should continue, it will pass __hms.stats + * It will poll at a fixed interval and start an exit timer if the method fails twice consecutively + * The exit timer is stopped if the method returns true before that + * @param hmsStats + */ + hasActiveElements(hmsStats: HMSStats): boolean { + const isWhiteboardPresent = Object.keys(this.store.getState().whiteboards).length > 0; + const isQuizOrPollPresent = Object.keys(this.store.getState().polls).length > 0; + const peerCount = Object.keys(this.store.getState().peers).length > 0; + const remoteTracks = hmsStats.getState().remoteTrackStats; + return ( + peerCount && + (isWhiteboardPresent || + isQuizOrPollPresent || + Object.values(remoteTracks).some(track => track && typeof track.bitrate === 'number' && track.bitrate > 0)) + ); + } }