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

@ekaansh.zoom sure , i will share code snippet . when we click on leave session app is crashing!

import {useRef, useState} from ‘react’
import {
Alert,
Button,
EmitterSubscription,
SafeAreaView,
StyleSheet,
Text,
View,
} from ‘react-native’
import {
EventType,
VideoAspect,
ZoomVideoSdkProvider,
ZoomVideoSdkUser,
ZoomView,
useZoom,
} from ‘@zoom/react-native-videosdk’
import React from ‘react’
import {config} from ‘…/…/app-base/zoomConfig’
import generateJwt from ‘…/…/helper/zoomToken’

const ZoomCall = () => {
const zoom = useZoom()
const listeners = useRef<EmitterSubscription>()
const [users, setUsersInSession] = useState<ZoomVideoSdkUser>()
const [isInSession, setIsInSession] = useState(false)
const [isAudioMuted, setIsAudioMuted] = useState(true)
const [isVideoMuted, setIsVideoMuted] = useState(true)

const join = async () => {
/* Disclaimer: JWT should be generated from your server */
const token = await generateJwt(config.sessionName, config.roleType)
console.log(‘token’, token)

const sessionJoin = zoom.addListener(EventType.onSessionJoin, async () => {
  const mySelf = new ZoomVideoSdkUser(await zoom.session.getMySelf())
  const remoteUsers = await zoom.session.getRemoteUsers()
  setUsersInSession([mySelf, ...remoteUsers])
  setIsInSession(true)
})
listeners.current.push(sessionJoin)

const userJoin = zoom.addListener(EventType.onUserJoin, async (event) => {
  const {remoteUsers} = event
  const mySelf = await zoom.session.getMySelf()
  const remote = remoteUsers.map((user) => new ZoomVideoSdkUser(user))
  setUsersInSession([mySelf, ...remote])
})
listeners.current.push(userJoin)

const userLeave = zoom.addListener(EventType.onUserLeave, async (event) => {
  const {remoteUsers} = event
  const mySelf = await zoom.session.getMySelf()
  const remote = remoteUsers.map((user) => new ZoomVideoSdkUser(user))
  setUsersInSession([mySelf, ...remote])
})
listeners.current.push(userLeave)

const userVideo = zoom.addListener(
  EventType.onUserVideoStatusChanged,
  async (event) => {
    const {changedUsers} = event
    const mySelf = new ZoomVideoSdkUser(await zoom.session.getMySelf())
    changedUsers.find((user) => user.userId === mySelf.userId) &&
      mySelf.videoStatus.isOn().then((on) => setIsVideoMuted(!on))
  },
)
listeners.current.push(userVideo)

const userAudio = zoom.addListener(
  EventType.onUserAudioStatusChanged,
  async (event) => {
    const {changedUsers} = event
    const mySelf = new ZoomVideoSdkUser(await zoom.session.getMySelf())
    changedUsers.find((user) => user.userId === mySelf.userId) &&
      mySelf.audioStatus.isMuted().then((muted) => setIsAudioMuted(muted))
  },
)
listeners.current.push(userAudio)

const sessionLeave = zoom.addListener(EventType.onSessionLeave, () => {
  setIsInSession(false)
  setUsersInSession([])
  sessionLeave.remove()
})

await zoom
  .joinSession({
    sessionName: config.sessionName,
    sessionPassword: config.sessionPassword,
    token: token,
    userName: config.displayName,
    audioOptions: {
      connect: true,
      mute: true,
      autoAdjustSpeakerVolume: false,
    },
    videoOptions: {localVideoOn: true},
    sessionIdleTimeoutMins: config.sessionIdleTimeoutMins,
  })
  .then((res: any) => {
    console.log('res', res)
  })
  .catch((e) => {
    console.log(e)
  })

}

const leaveSession = async () => {
if (!isInSession) {
console.log(‘Session already left.’)
return
}

try {
  zoom.leaveSession(false)

  if (listeners.current.length > 0) {
    listeners.current.forEach((listener) => {
      if (listener) {
        listener.remove()
      }
    })
  }

  listeners.current = []
  setIsInSession(false)
  setUsersInSession([])

  console.log('Left the session successfully and cleaned up listeners.')
} catch (e) {
  console.error('Error leaving session:', e.message || e)
  Alert.alert('Failed to leave the session')
}

}

return isInSession ? (

{users.map((user) => (



))}

<Button title=“Leave Session” color={‘#f01040’} onPress={leaveSession} />

) : (

Zoom Video SDK
React Native Quickstart



)
}

const MuteButtons = ({
isAudioMuted,
isVideoMuted,
}: {
isAudioMuted: boolean
isVideoMuted: boolean
}) => {
const zoom = useZoom()
const onPressAudio = async () => {
const mySelf = await zoom.session.getMySelf()
const muted = await mySelf.audioStatus.isMuted()
muted
? await zoom.audioHelper.unmuteAudio(mySelf.userId)
: await zoom.audioHelper.muteAudio(mySelf.userId)
}

const onPressVideo = async () => {
const mySelf = await zoom.session.getMySelf()
const videoOn = await mySelf.videoStatus.isOn()
videoOn
? await zoom.videoHelper.stopVideo()
: await zoom.videoHelper.startVideo()
}
return (

<Button
title={isAudioMuted ? ‘Unmute Audio’ : ‘Mute Audio’}
onPress={onPressAudio}
/>

<Button
title={isVideoMuted ? ‘Unmute Video’ : ‘Mute Video’}
onPress={onPressVideo}
/>

)
}

export default ZoomCall

export const styles = StyleSheet.create({
safe: {
width: ‘90%’,
alignSelf: ‘center’,
margin: 16,
flex: 1,
justifyContent: ‘center’,
},
container: {
width: ‘100%’,
alignSelf: ‘center’,
height: ‘100%’,
flex: 1,
justifyContent: ‘center’,
},
spacer: {
height: 16,
width: 8,
},
heading: {
fontSize: 24,
fontWeight: ‘bold’,
textAlign: ‘center’,
},
button: {
alignItems: ‘center’,
justifyContent: ‘center’,
paddingVertical: 12,
paddingHorizontal: 32,
borderRadius: 4,
elevation: 3,
},
buttonHolder: {
flexDirection: ‘row’,
justifyContent: ‘center’,
margin: 8,
},
text: {
fontSize: 16,
lineHeight: 21,
fontWeight: ‘bold’,
letterSpacing: 0.25,
color: ‘white’,
},
})

What’s the version of the SDK you’re using? Can you try updating to v1.12.10? I’m not able to reproduce the error with the quickstart I shared with you, it’s using the same code for leaveSession.

1 Like

ok i will update and let you know!