Hi Team,
I am using “@zoom/react-native-videosdk”: “^1.12.5”, I have valid ZOOM_APP_KEY = ‘qZHv4EVsRKGwUiRiNGc6kg’ & ZOOM_APP_SECRET = ‘’,
When i tried to implement in my code i am getting error LOG Join Session Response: null.
import React, {useState, useEffect} from ‘react’
import {Alert, Button, View, StyleSheet} from ‘react-native’
import {useZoom} from ‘@zoom/react-native-videosdk’ // Zoom Video SDK
import {sign} from ‘react-native-pure-jwt’ // JWT library for signing tokens
// Zoom Video SDK Credentials (Replace with your own)
const ZOOM_APP_KEY = ‘EcTju1ovR2uXqoPL-P7suA’ // Replace with your Zoom SDK app key
const ZOOM_APP_SECRET = ‘’ // Replace with your Zoom SDK app secret
// Define the session configuration
const sessionConfig = {
sessionName: ‘DemoSession’, // The session name (same as tpc in JWT token)
userName: ‘User123’, // The name of the user who will join the session
roleType: 1, // 1 for host, 0 for attendee
sessionIdleTimeoutMins: 10, // Timeout setting
}
const ZoomVideoSDKPage: React.FC = () => {
const [isZoomReady, setIsZoomReady] = useState(false) // Track SDK readiness
const [token, setToken] = useState(‘’) // Store the JWT token
const zoom = useZoom() // Initialize Zoom Video SDK
useEffect(() => {
if (zoom) {
console.log(‘Zoom Video SDK initialized’)
setIsZoomReady(true)
generateToken() // Generate token once the SDK is ready
} else {
console.log(‘Zoom SDK not initialized’)
}
}, [zoom])
// Function to generate the Zoom Video SDK JWT token
const generateToken = async () => {
try {
const currentTime = Math.floor(Date.now() / 1000) // Current time in seconds
const expirationTime = currentTime + 3600 // Token valid for 1 hour
// Generate the JWT token for the Zoom Video SDK
const generatedToken = await sign(
{
app_key: ZOOM_APP_KEY, // Video SDK app key
version: 1,
user_identity: sessionConfig.userName, // User identity
iat: currentTime, // Issued at time
exp: expirationTime, // Expiration time (1 hour from now)
tpc: sessionConfig.sessionName, // Topic of the session (same as sessionName)
role_type: sessionConfig.roleType, // 1 for host, 0 for attendee
},
ZOOM_APP_SECRET, // Video SDK app secret
{alg: 'HS256'}, // Algorithm
)
console.log('Generated Token for Video SDK:', generatedToken)
setToken(generatedToken) // Save the token to state
return generatedToken
} catch (error) {
console.error('Error generating Video SDK token:', error)
Alert.alert('Error', 'Failed to generate token')
}
}
// Function to join the Zoom Video SDK session
const joinSession = async () => {
if (!isZoomReady) {
Alert.alert(‘Zoom SDK is not ready.’)
return
}
if (!token) {
Alert.alert('Token is not generated yet.')
return
}
try {
// Try to join the session using the SDK
const response = await zoom.joinSession({
sessionName: 'Test',
sessionPassword: 'Test',
token: token,
userName: 'Test',
audioOptions: {
connect: true,
mute: true,
autoAdjustSpeakerVolume: false,
},
videoOptions: {
localVideoOn: true,
},
sessionIdleTimeoutMins: parseInt('10', 10),
})
// Check if response is successful
console.log('Join Session Response:', response)
if (response && response.status === 'success') {
Alert.alert('Successfully joined the session')
} else {
Alert.alert(
'Failed to join the session',
response?.error || 'Unknown error',
)
}
} catch (error: any) {
// Log the full error to understand the issue
console.error('Error joining session:', error)
// Alert with the error message
Alert.alert(
'Error joining session',
error.message || 'Unknown error occurred',
)
}
}
return (
)
}
// Styles for the page
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: ‘center’,
alignItems: ‘center’,
padding: 20,
},
})
export default ZoomVideoSDKPage