Discussions

Ask a Question
Back to All

I tried to integrate the stream code with my react code but facing some issues

I tried to integrate the stream code with my react code but facing some issues.

I execute the connect function as soon as the page loads
useEffect(() => {
// // Connect when the page loads
connect();
}, []);

this is working fine.

I also execute the talk function once a connection is made like this

useEffect(() => {
// Check if the last message is from the assistant and trigger the talk button
if (
messages.length &&
messages[messages.length - 1].role === "assistant" &&
peerStatus === "connected" &&
iceGatheringStatus === "complete" &&
peerConnectionConnected
) {

    talkButton();

}

}, [messages, peerStatus, iceGatheringStatus, peerConnectionConnected]);

but talk is not working when i am using button to execute then it working. Please let me know where i am doing wrong