Hey @hazzal
Thanks for sharing the code snippet with us.
After analyzing the code, we found some issues when using the Video SDK that might cause the ‘IMPROPER_MEETING_STATE’ error. Here are some recommendations we provide:
const initialiseCall = useCallback(async () => { /** * Skip unrelated code. **/ await client.init("en-US", "Global", { patchJsMedia: true, leaveOnPageUnload: true, }); await client.join(zoomJwtResponse.session, zoomJwtResponse.jwt, username); console.log("session", client.getSessionInfo()); /** * Skip unrelated code. **/ // The next line mighe return rejected promise with "IMPROPER_MEETING_STATE" await zoomStream.startAudio(); }, [ client, consultationId, consultationService, isPatient, renderVideo, username, ]); // Automatically execute once the `initialiseCall` method changes useEffect(() => { void initialiseCall(); }, [initialiseCall]); // Another place that calls the init and join methods. const joinClient = useCallback(async () => { try { const remoteViewElement = canvasElementRef.current; const zoomJwtResponse = await consultationService.getZoomJwt( consultationId ); console.log("joining zoom session with", zoomJwtResponse); await client.init("en-US", "Global", { patchJsMedia: true, leaveOnPageUnload: true, }); await client.join(zoomJwtResponse.session, zoomJwtResponse.jwt, username); console.log("session", client.getSessionInfo()); // The next line mighe return rejected promise with "IMPROPER_MEETING_STATE" await streamRef.current.startVideo(); } catch (error) { console.error("Error joining Zoom session:", error); } });
There are two rejoin logics in the code. According to my analysis and understanding, when you call the createNewSession and joinClient methods, the initialiseCall method within the useEffect will also execute automatically. The issue arises here. Since these two executions are independent, they are not blocked by await, leading to the following situation:
// execute sequence
-> await client.join // joinClient method
-> await client.init // initialiseCall method
When the client.join statement is executed in the joinClient method, the initialiseCall method might simultaneously execute the client.init statement. Since the client.init method resets the entire session state, the subsequent code in the joinClient method will not run as expected, which may result in the IMPROPER_MEETING_STATE error.
Either of the following solutions are viable:
-
Refine the
initialiseCallmethod so that it is only called when the component mounts. -
Remove the
joinClientmethod and let React automatically trigger theinitialiseCallmethod to join a new session when theconsultationIdchanges. However, ensure that you refine theinitialiseCallmethod by adding a cleanup function, as repeatedly binding event handlers to theclient.onmethod might also cause issues.
Please let me know if you need any assistance with the issue.
Thanks
Vic