diff --git a/packages/mobile-client/src/constraints.ts b/packages/mobile-client/src/constraints.ts new file mode 100644 index 00000000..9e9826e5 --- /dev/null +++ b/packages/mobile-client/src/constraints.ts @@ -0,0 +1,52 @@ +/** + * Google-specific audio processing constraints (legacy Chrome constraints). + * These are not part of the standard MediaTrackConstraints type but are supported by WebRTC implementations. + */ +interface GoogleAudioConstraints { + googEchoCancellation?: string | boolean; + googAutoGainControl?: string | boolean; + googNoiseSuppression?: string | boolean; + googTypingNoiseDetection?: string | boolean; + googHighpassFilter?: string | boolean; +} + +/** + * Extended MediaTrackConstraints that includes Google-specific audio processing properties. + */ +export type ExtendedMediaTrackConstraints = MediaTrackConstraints & GoogleAudioConstraints; + +/** + * Default audio constraints for mobile-client with Google audio processing features enabled. + * These constraints can be overridden by passing custom audio constraints to FishjamProvider. + */ +export const DEFAULT_MOBILE_AUDIO_CONSTRAINTS: ExtendedMediaTrackConstraints = { + googEchoCancellation: true, + googAutoGainControl: true, + googNoiseSuppression: true, + googTypingNoiseDetection: true, + googHighpassFilter: true, +}; + +/** + * Merges default mobile audio constraints with user-provided constraints. + * User-provided constraints take precedence over defaults. + * + * @param userConstraints - User-provided audio constraints (can be boolean or MediaTrackConstraints) + * @returns Merged audio constraints + */ +export function mergeMobileAudioConstraints( + userConstraints?: ExtendedMediaTrackConstraints | boolean, +): ExtendedMediaTrackConstraints | boolean { + if (userConstraints === false) { + return false; + } + + if (userConstraints === true || userConstraints === undefined) { + return DEFAULT_MOBILE_AUDIO_CONSTRAINTS; + } + + return { + ...DEFAULT_MOBILE_AUDIO_CONSTRAINTS, + ...userConstraints, + }; +} diff --git a/packages/mobile-client/src/index.ts b/packages/mobile-client/src/index.ts index 2a801ddc..c527469b 100644 --- a/packages/mobile-client/src/index.ts +++ b/packages/mobile-client/src/index.ts @@ -12,7 +12,10 @@ import { } from '@fishjam-cloud/react-client'; import { FishjamClient } from '@fishjam-cloud/ts-client'; +import { mergeMobileAudioConstraints } from './constraints'; + export { RTCView, RTCPIPView, type RTCVideoViewProps, type RTCPIPViewProps } from './overrides/RTCView'; + export { ScreenCapturePickerView, startPIP, @@ -90,8 +93,17 @@ export type { export type FishjamProviderProps = Omit; export function FishjamProvider(props: FishjamProviderProps) { const fishjamClient = new FishjamClient({ reconnect: props.reconnect, debug: props.debug, clientType: 'mobile' }); + + const mergedConstraints = React.useMemo(() => { + return { + ...props.constraints, + audio: mergeMobileAudioConstraints(props.constraints?.audio), + }; + }, [props.constraints]); + return React.createElement(ReactClientFishjamProvider, { ...props, + constraints: mergedConstraints, persistLastDevice: false, fishjamClient, });