I’m facing an issue in my android RN app where the sendbird.connect function always throws an exception:
Websocket connection failed
and when i check the native logs i found that the SDK throws the following error:
2022-05-08 19:15:05.438 7464-7495/com.zed.customerUat E/ReactNativeJS: '[ERROR ]', 'API dummy call failed:', { [SendBirdException: Request failed.]
name: 'SendBirdException',
code: 800220,
line: 2280,
column: 8430,
sourceURL: 'index.android.bundle' }
2022-05-08 19:15:05.447 7464-7496/com.zed.customerUat E/unknown:ReactNative: console.error: [ERROR ] API dummy call failed: SendBirdException: Request failed., stack:
construct@-1
o@64:330
construct@-1
<unknown>@63:437
c@63:637
f@63:1880
value@2280:14041
forEach@-1
value@2280:15212
value@2280:15934
<unknown>@2280:92630
<unknown>@2280:27983
u@76:156
<unknown>@76:865
<unknown>@84:1671
k@84:499
w@84:897
callReactNativeMicrotasks@84:3053
value@37:2867
<unknown>@37:959
value@37:2503
value@37:918
value@-1
value@-1
Here is a snippet showing how I’m trying to run the sdk:
App.tsx:
import React from 'react';
import { NavigationContainer, DarkTheme } from '@react-navigation/native';
import { ThemeProvider, USER_TYPE } from '@app/theme';
import AppNavigation from '@customer/navigation';
import { ApolloProvider } from '@apollo/client';
import { createClient } from '@zedapp/data-access';
import { useAuth } from '@customer/modules/auth/login/hooks/useAuth';
import SendBird from 'sendbird';
import Config from 'react-native-config';
import { chatVar } from '@customer/reactivities';
import ChatProvider from './context';
const sendbird = new SendBird({ appId: Config.SENDBIRD_APP_ID });
// chatVar({ sendbird });
sendbird.setErrorFirstCallback(true);
const initialState = {
sendbird,
};
const App = () => {
const { authVar } = useAuth();
const params = {
authToken: authVar.token,
};
const client = createClient(params);
return (
<ChatProvider value={initialState}>
<ApolloProvider client={client}>
<NavigationContainer theme={DarkTheme} >
<ThemeProvider value={{ userType: USER_TYPE.CUSTOMER }}>
<AppNavigation />
</ThemeProvider>
</NavigationContainer>
</ApolloProvider>
</ChatProvider>
);
};
export default App;
and my chat screen (where i’m getting the error):
import React, { useEffect } from 'react';
import { StyleSheet } from 'react-native';
import { Container, Header, hp } from '@app/components';
import { useTheme } from '@app/theme';
import { useChatContext } from '@customer/app/context';
import { useCustomer } from '@customer/modules/profile/hooks/useCustomer';
const ChatWithAgentScreen = () => {
const theme = useTheme();
const { sendbird } = useChatContext();
const { customerVar } = useCustomer();
useEffect(() => {
// console.log(sendbird);
// if (sendbird.connect) connect();
connect();
}, []);
const connect = async () => {
try {
const user = await sendbird?.connect(customerVar?.idCustomerUser);
console.log('connect_user', user);
} catch (err) {
console.log('connect_error', err);
}
};
return (
<>
<Container.Flex style={styles.container}>
<Header.AppHeader
headerText={'Chat with Cx Service agent.'}
headerTextColor={theme.main.white}
containerStyle={{ backgroundColor: theme.main.secondary }}
hideLeft={true}
/>
</Container.Flex>
</>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
marginBottom: hp(12),
backgroundColor: '#fff',
},
body: { paddingHorizontal: 24, justifyContent: 'center' },
moodSelector: {
marginVertical: 12,
},
});
export default ChatWithAgentScreen;
react native: 0.66.4
sendbird: 3.1.7