Skip to content

Commit

Permalink
fix: respond on setting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlaz committed Oct 26, 2023
1 parent d8bd39e commit c5c985e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 7 additions & 3 deletions packages/client/src/permissions/PermissionsContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions packages/react-bindings/src/wrappers/Restricted.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<{
/**
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c5c985e

Please sign in to comment.