import React, { useEffect, useCallback } from 'react';
import { Alert } from 'react-native';
import { CometChatCalls } from '@cometchat/calls-sdk-react-native';
interface CallScreenProps {
sessionId: string;
onCallEnd: () => void;
}
function CallScreen({ sessionId, onCallEnd }: CallScreenProps) {
const handleSessionTimeout = useCallback(() => {
Alert.alert(
'Session Ended',
'The call has ended due to inactivity.',
[
{
text: 'OK',
onPress: onCallEnd,
},
]
);
}, [onCallEnd]);
useEffect(() => {
const unsubscribe = CometChatCalls.addEventListener(
'onSessionTimedOut',
handleSessionTimeout
);
return () => unsubscribe();
}, [handleSessionTimeout]);
useEffect(() => {
async function initializeCall() {
try {
const { token } = await CometChatCalls.generateToken(sessionId);
const sessionSettings = {
idleTimeoutPeriodBeforePrompt: 180000, // 3 minutes
idleTimeoutPeriodAfterPrompt: 120000, // 2 minutes
};
// Render call component with token and sessionSettings
} catch (error) {
console.error('Failed to initialize call:', error);
}
}
initializeCall();
}, [sessionId, handleSessionTimeout, onCallEnd]);
// ... render call UI
return null;
}
export default CallScreen;