diff --git a/packages/client/src/permissions/PermissionsContext.ts b/packages/client/src/permissions/PermissionsContext.ts index c4b7d8c11d..95070f1a08 100644 --- a/packages/client/src/permissions/PermissionsContext.ts +++ b/packages/client/src/permissions/PermissionsContext.ts @@ -44,11 +44,15 @@ export class PermissionsContext { * within the call. * * @param permission the permission to check for. + * @param settings the call settings to check against (optional). */ - canRequest = (permission: OwnCapability) => { - if (!this.settings) return false; + canRequest = ( + permission: OwnCapability, + settings: CallSettingsResponse | undefined = this.settings, + ) => { + if (!settings) return false; - const { audio, video, screensharing } = this.settings; + const { audio, video, screensharing } = settings; switch (permission) { case OwnCapability.SEND_AUDIO: return audio.access_request_enabled; diff --git a/packages/react-bindings/src/wrappers/Restricted.tsx b/packages/react-bindings/src/wrappers/Restricted.tsx index 917e70ada7..a0ff5b5b08 100644 --- a/packages/react-bindings/src/wrappers/Restricted.tsx +++ b/packages/react-bindings/src/wrappers/Restricted.tsx @@ -2,7 +2,7 @@ import { OwnCapability } from '@stream-io/video-client'; import { PropsWithChildren } from 'react'; import { useCall } from '../contexts'; -import { useOwnCapabilities } from '../hooks'; +import { useCallStateHooks, useOwnCapabilities } from '../hooks'; type RestrictedProps = PropsWithChildren<{ /** @@ -33,14 +33,16 @@ export const Restricted = ({ }: RestrictedProps) => { const call = useCall(); const ownCapabilities = useOwnCapabilities(); + const { useCallSettings } = useCallStateHooks(); + const settings = useCallSettings(); const hasPermissions = requiredGrants[requireAll ? 'every' : 'some']( (capability) => ownCapabilities?.includes(capability), ); if (hasPermissionsOnly) return hasPermissions ? <>{children} : null; - const canRequest = requiredGrants.some( - (capability) => !!call && call.permissionsContext.canRequest(capability), + const canRequest = requiredGrants.some((capability) => + call?.permissionsContext.canRequest(capability, settings), ); if (canRequestOnly) return canRequest ? <>{children} : null;