Skip to content

Commit 5e39fee

Browse files
authored
Add env var for payload verification (#485)
## Description Add environment variable to make sure that we only check events payload in development. ## Motivation and Context We want to make sure that the payload verification for events happens only in development. ## Types of changes - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) ## Checklist: - [ ] My code follows the code style of this project. - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly.
1 parent 8e1ead7 commit 5e39fee

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

internal/fishjam-chat/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ EXPO_PUBLIC_VIDEOROOM_PRODUCTION_ROOM_MANAGER=
1717

1818
# Fishjam id from cloud dashboard
1919
EXPO_PUBLIC_FISHJAM_ID=
20+
21+
# set to true during development to validate payload for events
22+
EXPO_PUBLIC_CHECK_EVENT_PAYLOAD=

internal/fishjam-chat/App.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import Toast from 'react-native-toast-message';
44

55
import AppNavigator from './navigators/AppNavigator';
66
import { useReconnectionToasts } from './hooks/useReconnectionToasts';
7+
import { setOverwriteDebugConfig } from '@fishjam-cloud/react-native-client';
8+
9+
setOverwriteDebugConfig({ validateEventPayloads: true });
710

811
function App(): React.JSX.Element {
912
useReconnectionToasts();

packages/react-native-client/src/hooks/internal/useFishjamEvent.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import nativeModule, {
55
ReceivableEventPayloads,
66
} from '../../RNFishjamClientModule';
77
import { validateNativeEventPayload } from '../../utils/eventPayloadValidator';
8+
import { getDebugConfig } from '../../utils/config';
89

910
export function useFishjamEvent<T extends keyof typeof ReceivableEvents>(
1011
eventName: T,
@@ -30,6 +31,8 @@ export function validateAndLogEventPayload<
3031
// Double check just to make sure
3132
if (!__DEV__) return;
3233

34+
if (!getDebugConfig().validateEventPayloads) return;
35+
3336
try {
3437
validateNativeEventPayload(eventName, payload);
3538
} catch (error) {

packages/react-native-client/src/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,6 @@ export type { FishjamRoomProps } from './components/FishjamRoom';
113113
export { FishjamRoom } from './components/FishjamRoom';
114114

115115
initializeWarningListener();
116+
117+
// Debug/config API
118+
export { setOverwriteDebugConfig, DebugConfig } from './utils/config';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export type DebugConfig = {
2+
validateEventPayloads: boolean;
3+
};
4+
5+
const debugConfig: DebugConfig = {
6+
validateEventPayloads: process.env.EXPO_PUBLIC_CHECK_EVENT_PAYLOAD ?? false,
7+
};
8+
9+
export function setOverwriteDebugConfig(partial: Partial<DebugConfig>): void {
10+
Object.assign(debugConfig, partial);
11+
}
12+
13+
export function getDebugConfig(): DebugConfig {
14+
return debugConfig;
15+
}

0 commit comments

Comments
 (0)