Cannot read property shouldAutoEstablishSocketConnection of undefined, js engine: hermes
It's ok when I just run the application, but when I build it to apk file for android and then try to open the app it does not work.
import React, { useCallback, useEffect } from 'react';
import { getTrackingStatus, requestTrackingPermission } from 'react-native-tracking-transparency';
import i18next from '@/services/i18next';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { I18nextProvider } from 'react-i18next';
import { Provider } from 'react-redux';
import { persistor, store } from '@/redux';
import { PersistGate } from 'redux-persist/integration/react';
import { AppNavigation } from '@/navigation';
import { GoogleSignin } from '@react-native-google-signin/google-signin';
import { BottomSheetModalProvider } from '@gorhom/bottom-sheet';
// eslint-disable-next-line no-duplicate-imports
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { NotificationToast } from '@/components/NotificationToast/NotificationToast';
import { Alert, Linking, StatusBar, useColorScheme } from 'react-native';
import { save, get } from './src/utils/asyncStorage/asyncStorage';
import appleAuth from '@invertase/react-native-apple-authentication';
import { isAndroid } from '@/utils/platform/isAndroid';
import { CometChat } from '@cometchat/chat-sdk-react-native';
function App(): JSX.Element {
const appearance = useColorScheme();
const initCometChat = () => {
const appID = process.env.COMET_CHAT_APP_ID;
const region = process.env.COMET_CHAT_REGION;
const appSetting = new CometChat.AppSettingsBuilder()
.subscribePresenceForAllUsers()
.setRegion(region)
.autoEstablishSocketConnection(true)
.overrideAdminHost(`${appID}.api-${region}.cc-cluster-2.io/v3`)
.overrideClientHost(`${appID}.apiclient-${region}.cc-cluster-2.io/v3`)
.build();
CometChat.init(appID, appSetting).then(
() => {
console.log('Comet Chat initialization completed successfully');
},
error => {
console.log('Comet Chat initialization failed with error:', error);
},
);
};
const setAppTheme = useCallback(async () => {
const IS_FIRST = await get('IS_FIRST');
if (IS_FIRST === null) {
save('THEME', appearance);
save('IS_FIRST', true);
}
}, []);
useEffect(() => {
setAppTheme();
}, [setAppTheme]);
const tracking = async () => {
const permissionStatus = await getTrackingStatus()
if (permissionStatus === "not-determined") {
const trackingStatus = await requestTrackingPermission();
console.log("trackingStatus", trackingStatus);
return
}
if (permissionStatus === "denied") {
Alert.alert('Allow to track you activity across others companies app and websites?', ' Settings > Privacy & Security > Tracking.', [
{
text: 'Go to settings',
onPress: () => Linking.openSettings(),
style: 'cancel',
},
{
text: 'Cancel',
onPress: () => console.log('Cancel Pressed'),
},
]);
}
};
useEffect(() => {
GoogleSignin.configure({
iosClientId: process.env.GOOGLE_OAUTH_CLIENT_ID_IOS,
webClientId: process.env.GOOGLE_OAUTH_CLIENT_ID_WEB,
});
tracking();
initCometChat();
}, []);
useEffect(() => {
if (!isAndroid()) {
return appleAuth.onCredentialRevoked(async () => {
console.warn(
'If this function executes, User Credentials have been Revoked',
);
});
}
}, []);
return (
<Provider store={store}>
<PersistGate persistor={persistor} loading={null}>
<I18nextProvider i18n={i18next}>
<GestureHandlerRootView style={{ flex: 1 }}>
<BottomSheetModalProvider>
<SafeAreaProvider>
<StatusBar
barStyle={
appearance === 'light' ? 'light-content' : 'dark-content'
}
/>
<NotificationToast />
<AppNavigation />
</SafeAreaProvider>
</BottomSheetModalProvider>
</GestureHandlerRootView>
</I18nextProvider>
</PersistGate>
</Provider>
);
}
export default App;