Skip to content

Commit

Permalink
feat: add audio level threshold to global state
Browse files Browse the repository at this point in the history
  • Loading branch information
martinstark authored and malmen237 committed Apr 25, 2024
1 parent 3e04dfe commit 12d7673
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/global-state/global-state-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type TGlobalStateAction =
| TUpdateDevicesAction
| TUpdateJoinProductionOptions
| TDominantSpeaker
| TAudioLevel
| TMediaStream;

export type TPublishError = {
Expand Down Expand Up @@ -41,3 +42,8 @@ export type TMediaStream = {
type: "CONNECTED_MEDIASTREAM";
payload: MediaStream | null;
};

export type TAudioLevel = {
type: "AUDIO_LEVEL_ABOVE_THRESHOLD";
payload: boolean;
};
9 changes: 9 additions & 0 deletions src/global-state/global-state-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const initialGlobalState: TGlobalState = {
joinProductionOptions: null,
mediaStreamInput: null,
dominantSpeaker: null,
audioLevelAboveThreshold: false,
};

const globalReducer: Reducer<TGlobalState, TGlobalStateAction> = (
Expand Down Expand Up @@ -54,6 +55,14 @@ const globalReducer: Reducer<TGlobalState, TGlobalStateAction> = (
...state,
dominantSpeaker: action.payload,
};
case "AUDIO_LEVEL_ABOVE_THRESHOLD":
// Don't update state if receiving the same value
if (state.audioLevelAboveThreshold === action.payload) return state;

return {
...state,
audioLevelAboveThreshold: action.payload,
};
default:
return state;
}
Expand Down
1 change: 1 addition & 0 deletions src/global-state/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export type TGlobalState = {
joinProductionOptions: TJoinProductionOptions | null;
mediaStreamInput: MediaStream | null;
dominantSpeaker: string | null;
audioLevelAboveThreshold: boolean;
};

0 comments on commit 12d7673

Please sign in to comment.