Getting Error while using React Native Video SDK "@zoom/react-native-videosdk": "^1.12.5",

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

@chunsiong.zoom Hey can you please help me for this?

I am using React Native Video SDK , with ZOOM_APP_KEY = ‘qZHv4EVsRKGwUiRiNGc6kg’ & ZOOM_APP_SECRET = ‘’

I have referred react-native-zoom-video-sdk-example with version 1.12.10.

import React, {useEffect, useState} from ‘react’
import {
Alert,
Button,
Modal,
SafeAreaView,
StatusBar,
Text,
View,
TouchableOpacity,
} from ‘react-native’
import {ZoomView, useZoom} from ‘@zoom/react-native-videosdk’
import {styles} from ‘./styles’
import {useNavigation, useRoute} from ‘@react-navigation/native’
import generateJwt from ‘…/…/helper/zoomToken’

const ZoomCall: React.FC = () => {
const zoom = useZoom()
const navigation = useNavigation() // For navigating back on error
const route = useRoute() // For accessing params
const [isInSession, setIsInSession] = useState(false)

// useEffect to join the session on component mount
useEffect(() => {
;(async () => {
const token = await generateJwt(‘DemoSession’, ‘1’)
console.log(‘token’, token)

  try {
    // Ensure token, sessionName, and displayName are valid and passed
    const response = await zoom.joinSession({
      sessionName: 'DemoSession', // Correct session name
      sessionPassword: '', // Optional password
      token: token, // Pass generated JWT token
      userName: 'shree', // User display name
      audioOptions: {
        connect: true,
        mute: true,
        autoAdjustSpeakerVolume: false,
      },
      videoOptions: {
        localVideoOn: true,
      },
      sessionIdleTimeoutMins: 10,
    })
    console.log('Join Session Response:', response)
  } catch (e) {
    console.error('Error joining session:', e)
    Alert.alert('Failed to join the session')
    setTimeout(() => navigation.goBack(), 1000)
  }
})()

// Adjust keyboard settings based on platform

}, [route, zoom])

// Function to leave the session
const leaveSession = () => {
try {
zoom.leaveSession(false) // Leave the session
setIsInSession(false)
console.log(‘Left the session successfully.’)
navigation.goBack() // Navigate back after leaving the session
} catch (e) {
console.error(‘Error leaving session:’, e.message || e)
Alert.alert(‘Failed to leave the session’)
}
}

return (


{isInSession ? (

<ZoomView
style={styles.videoContainer}
userId={‘local’} // Local user view
fullScreen
/>

Leave Session


) : (

Joining Zoom Session…

)}

)
}

export default ZoomCall
for call i used above code and for token generation using below code

// This util is to generate JWTs.
// THIS IS NOT A SAFE OPERATION TO DO IN YOUR APP IN PRODUCTION.
// JWTs should be provided by a backend server as they require a secret
// WHICH IS NOT SAFE TO STORE ON DEVICE!
// @ts-ignore
import {sign} from ‘react-native-pure-jwt’
import {ZOOM_APP_KEY, ZOOM_APP_SECRET} from ‘…/app-base/zoomConfig’

function makeId(length: number) {
var result = ‘’
var characters =
‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789’
var charactersLength = characters.length
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength))
}
return result
}

export default async function generateJwt(
sessionName: string,
roleType: string,
) {
// Ignoring because it hates on this for some reason.
// @ts-ignore
try {
const token = await sign(
{
app_key: ZOOM_APP_KEY,
version: 1,
user_identity: makeId(10),
iat: new Date().getTime(),
exp: new Date(Date.now() + 23 * 3600 * 1000).getTime(),
tpc: sessionName,
role_type: parseInt(roleType, 10),
cloud_recording_option: 1,
},
ZOOM_APP_SECRET,
{
alg: ‘HS256’,
},
)

return token

} catch (e) {
console.log(e)
return ‘’
}
}
but while joining zoom session getting response ‘null’ @chunsiong.zoom can you please help me for same!

@shreenivas.kokil ,

please do not post your secret key here.

Are you using the SDK Key and SDK Secret from a Video SDK account ?

@chunsiong.zoom sorry ! will take care next time! yes I am using from Video SDK account!
Video SDK | Pay As You Go

Renews on September 28, 2024

117 of 10,000 minutes (1.17% used)

@chunsiong.zoom any update on this ? can you please help me this ? This is blocker for us!

@shreenivas.kokil could you share yourJWT token here?

You have used the sample app as is right?

Do note that the developer forum has no SLA and is a best effort basis. If this is urgent or is a blocker, I would strongly recommend you to sign up for a premium developer support

@chunsiong.zoom ok I will check with Developer Premium account ! and Below is JWT token with my eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOm51bGwsImlzcyI6IkhiaDYtVkwyUkhPOXNWZFpBQjZYR3ciLCJleHAiOjE3MjY3NTU2NzYsImlhdCI6MTcyNjY2OTI3Nn0.XA86pZR6kz2JEfhbUYt6o9cGUwbGnQQtgL0K6DluP70

@shreenivas.kokil how did you generate the token?

The token used to access the api is different from the token used to authenticate video sdk

You can use the generator here to create a valid token

@chunsiong.zoom Please check below one !

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBfa2V5IjoicVpIdjRFVnNSS0d3VWlSaU5HYzZrZyIsInJvbGVfdHlwZSI6MSwidHBjIjoiVGVzdGluZyIsInZlcnNpb24iOjEsImlhdCI6MTcyNjY3MTkxOCwiZXhwIjoxNzI2Njc1NTE4fQ.ZTVm2LMaHfMLA5hQ_9XEwhX1niQhk6fG-BUNeTm0NV8

@chunsiong.zoom please find the attached screenshot for your reference !


LOG token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBfa2V5IjoicVpIdjRFVnNSS0d3VWlSaU5HYzZrZyIsInJvbGVfdHlwZSI6MS4wLCJ0cGMiOiJEZW1vU2Vzc2lvbiIsImNsb3VkX3JlY29yZGluZ19vcHRpb24iOjEuMCwidXNlcl9pZGVudGl0eSI6InpGMGZlM2dzbnoiLCJleHAiOjE3MjY3NTgxNDcsInZlcnNpb24iOjEuMCwiaWF0IjoxNzI2Njc1MzQ3fQ.Wxh8CyJZkBYlrPRVr8ycAxuJG8IZ335mqE9KCxKbsak
LOG Join Session Response: null

@shreenivas.kokil this token works fine.

Do note that when you are joining / starting the session, you need to input the same exact topic / sessionName “DemoSession” in your join parameter

import React, {useEffect, useState} from ‘react’
import {
Alert,
Button,
Modal,
SafeAreaView,
StatusBar,
Text,
View,
TouchableOpacity,
} from ‘react-native’
import {ZoomView, useZoom} from ‘@zoom/react-native-videosdk’
import {styles} from ‘./styles’
import {useNavigation, useRoute} from ‘@react-navigation/native’
import generateJwt from ‘…/…/helper/zoomToken’

const ZoomCall: React.FC = () => {
const zoom = useZoom()
const navigation = useNavigation() // For navigating back on error
const route = useRoute() // For accessing params
const [isInSession, setIsInSession] = useState(false)

const button = async () => {
await zoom
.joinSession({
sessionName: ‘DemoSession’, // Correct session name
sessionPassword: ‘’, // Optional password
token:
‘eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBfa2V5IjoicVpIdjRFVnNSS0d3VWlSaU5HYzZrZyIsInJvbGVfdHlwZSI6MCwidHBjIjoiRGVtb1Nlc3Npb24iLCJ2ZXJzaW9uIjoxLCJpYXQiOjE3MjY3MzU5OTQsImV4cCI6MTcyNjczOTU5NH0.2XJzojZeIxzqpHSTe-xNkUTTwLbtvzBetvn_b009H6U’, // Pass generated JWT token
userName: ‘shree’, // User display name
audioOptions: {
connect: true,
mute: true,
autoAdjustSpeakerVolume: false,
},
videoOptions: {
localVideoOn: true,
},
sessionIdleTimeoutMins: 10,
})
.then((res: any) => {
console.log(‘res’, res)
})
}

// Function to leave the session
const leaveSession = () => {
try {
zoom.leaveSession(false) // Leave the session
setIsInSession(false)
console.log(‘Left the session successfully.’)
navigation.goBack() // Navigate back after leaving the session
} catch (e) {
console.error(‘Error leaving session:’, e.message || e)
Alert.alert(‘Failed to leave the session’)
}
}

return (



<ZoomView
style={styles.videoContainer}
userId={‘local’} // Local user view
fullScreen
/>

Leave Session




)
}

export default ZoomCall
PLEASE CAN YOU TRY THIS AND LET ME KNOW IF IS WORKING !

Are you using the correct credentials?
I see your initial post has two different App Keys:

ZOOM_APP_KEY = ‘qZHv4EVsRKGwUiRiNGc6kg’ 
...
const ZOOM_APP_KEY = ‘EcTju1ovR2uXqoPL-P7suA’

After the joinSession completes succefully it triggers the EventType.onSessionJoin event:

    const sessionJoin = zoom.addListener(EventType.onSessionJoin, async () => {
      ...
      setIsInSession(true);
    });

I’d suggest taking a look at this react-native quickstart sample to understand how the SDK works by reading through a simpler example. Here’s a step-by-step blog for you: Build a React Native video conferencing app with the Zoom Video SDK & Expo

1 Like

Thank you for quick response ! just wanna ask you 2 things !
we have to used SDK credentials(which is SDK Key & SDK Secret ) not API keys (which is API Key & API Secret)
2. we need to add listener also ? directly we cant use joinsession ?

  1. Yes, you need to use SDK Key/Secret
  2. Yes

Thank you! i will try and update you still i am facing issue or not ! thank you!

1 Like

Thank you @ekaansh.zoom @chunsiong.zoom now i am able to used zoom video sdk. But there is crashing when i click on leave session! Session is ended but App is crashing !

Hi @chunsiong.zoom @ekaansh.zoom now i am able to used zoom video sdk. But there is crashing when i click on leave session! Session is ended but App is crashing !

Can you share the snippet causing the crash?