Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"eslint": "^9.26.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-react": "^7.37.5",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-react-hooks": "^6.1.0",
"globals": "^16.1.0",
"husky": "^9.1.7",
"lint-staged": "^15.5.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-bindings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"devDependencies": {
"@rollup/plugin-typescript": "^12.1.2",
"@stream-io/video-client": "workspace:^",
"@types/react": "^19.1.3",
"@types/react": "^19.2.0",
"react": "19.0.0",
"rimraf": "^6.0.1",
"rollup": "^4.40.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-bindings/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as CallStateHooks from './callStateHooks';

export * from './useEffectEvent';
export * from './useObservableValue';

export * from './store';
Expand Down
23 changes: 23 additions & 0 deletions packages/react-bindings/src/hooks/useEffectEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {
useCallback,
useLayoutEffect,
useRef,
useEffectEvent as BuiltInHook,
} from 'react';

function useEffectEventShim<T extends (...args: any[]) => any>(
cb: T,
): (...funcArgs: Parameters<T>) => ReturnType<T> {
const cbRef = useRef(cb);

useLayoutEffect(() => {
cbRef.current = cb;
}, [cb]);

return useCallback((...args: Parameters<T>) => {
const callback = cbRef.current;
return callback(...args);
}, []);
}

export const useEffectEvent = BuiltInHook ?? useEffectEventShim;
19 changes: 7 additions & 12 deletions packages/react-native-sdk/src/hooks/usePermissionNotification.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { CallingState, OwnCapability } from '@stream-io/video-client';
import { useCallStateHooks } from '@stream-io/video-react-bindings';
import { useCallback, useEffect } from 'react';
import { useEffect } from 'react';
import { Alert } from 'react-native';
import { usePrevious } from '../utils/hooks/usePrevious';
import { useEffectEvent } from '@stream-io/video-react-bindings';

export type PermissionNotificationProps = {
/**
Expand Down Expand Up @@ -32,13 +33,13 @@ export const usePermissionNotification = (
const previousHasPermission = usePrevious(hasPermission);
const callingState = useCallCallingState();

const showGrantedNotification = useCallback(() => {
const showGrantedNotification = useEffectEvent(() => {
Alert.alert(messageApproved);
}, [messageApproved]);
});

const showRevokedNotification = useCallback(() => {
const showRevokedNotification = useEffectEvent(() => {
Alert.alert(messageRevoked);
}, [messageRevoked]);
});

useEffect(() => {
// Permission state is not reliable before the call is joined,
Expand All @@ -51,11 +52,5 @@ export const usePermissionNotification = (
} else if (!hasPermission && previousHasPermission) {
showRevokedNotification();
}
}, [
callingState,
hasPermission,
previousHasPermission,
showGrantedNotification,
showRevokedNotification,
]);
}, [callingState, hasPermission, previousHasPermission]);
};
16 changes: 0 additions & 16 deletions packages/react-sdk/src/hooks/useEffectEvent.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
LivestreamLayoutProps,
StreamCall,
} from '../../core';
import { useEffectEvent } from '../../hooks/useEffectEvent';
import { useEffectEvent } from '@stream-io/video-react-bindings';

export type LivestreamPlayerProps = {
/**
Expand Down Expand Up @@ -53,7 +53,7 @@ export const LivestreamPlayer = (props: LivestreamPlayerProps) => {
const { callType, callId, ...restProps } = props;
const client = useStreamVideoClient();
const [call, setCall] = useState<Call>();
const onError = useEffectEvent(props.onError);
const onError = useEffectEvent(props.onError ?? (() => {}));

useEffect(() => {
if (!client) return;
Expand All @@ -69,7 +69,7 @@ export const LivestreamPlayer = (props: LivestreamPlayerProps) => {
});
setCall(undefined);
};
}, [callId, callType, client, onError]);
}, [callId, callType, client]);

if (!call) {
return null;
Expand Down Expand Up @@ -116,7 +116,7 @@ const useLivestreamCall = (props: {
const canJoin =
(joinBehavior === 'asap' && canJoinAsap) ||
(joinBehavior === 'live' && canJoinLive);
const onError = useEffectEvent(props.onError);
const onError = useEffectEvent(props.onError ?? (() => {}));

useEffect(() => {
if (call && call.state.callingState === CallingState.IDLE && canJoin) {
Expand All @@ -125,7 +125,7 @@ const useLivestreamCall = (props: {
onError(e);
});
}
}, [call, canJoin, onError]);
}, [call, canJoin]);

return call;
};
Expand Down
Loading
Loading