Skip to content

Commit

Permalink
feat: internal method to check if recording should continue
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 committed Nov 14, 2024
1 parent 314666c commit 05d6ecb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/hms-video-store/src/IHMSActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -587,4 +588,10 @@ export interface IHMSActions<T extends HMSGenericTypes = { sessionStore: Record<
* Method to get enabled flags and endpoints. Should only be called after joining.
*/
getDebugInfo(): DebugInfo | undefined;

/**
* @internal
* Method to check if received bitrate is 0 for all remote peers or whether the room has whiteboard/quiz running. To be used by beam.
*/
hasActiveElements(hmsStats: HMSStats): boolean;
}
21 changes: 21 additions & 0 deletions packages/hms-video-store/src/reactive-store/HMSSDKActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import {
selectVideoTrackByID,
} from '../selectors';
import { FindPeerByNameRequestParams } from '../signal/interfaces';
import { HMSStats } from '../webrtc-stats';

/**
* This class implements the IHMSActions interface for 100ms SDK. It connects with SDK
Expand Down Expand Up @@ -1671,4 +1672,24 @@ export class HMSSDKActions<T extends HMSGenericTypes = { sessionStore: Record<st
private setState: NamedSetState<HMSStore<T>> = (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))
);
}
}

0 comments on commit 05d6ecb

Please sign in to comment.