You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I creating an video chat application with peerjs, socket (Nodejs) and front end is reactjs application.On join room it works fine but for reconnect it is not working fine. I test it with turning internet off for one device but sometime one of the remote device cannot see reconnected user
Below is my front end reactjs code to reconnect peer connection for video chat application.
In which i check if internet is restore check via socket.
Below is my back end nodejs code for ping pong technique and after every 5 seconds i check if pong difference is between 6 to 40 seconds then emit 'connection-lose' to remote screens.
socket.on("pong", (roomId, uuId) => {
const user = rooms[roomId]?.find((item) => item.uuId === uuId);
if (user) {
user["pingAt"] = new Date();
}
});
const pingInterval = setInterval(() => {
io.to(payload.roomId).emit("ping", payload.roomId);
setTimeout(() => {
connectionInterval();
}, 2000);
}, 5000); // Send "ping" event every 5 seconds
// Have to re-write this code
const connectionInterval = () => {
const currentTime = new Date().getTime();
const roomId = payload.roomId;
rooms[roomId]?.forEach((user) => {
const timeDifference = currentTime - user.pingAt.getTime();
if (timeDifference <= 6000) {
if (user) {
if (!user["connection"]) {
user["connection"] = true;
io.to(roomId).emit(
"reconnected-from-server-lack",
user.peerId,
timeDifference
);
}
}
} else if (timeDifference > 6000 && timeDifference < 40000) {
if (user) {
if (user["connection"]) {
user["connection"] = false;
io.to(roomId).emit("connectionLose", user.peerId, timeDifference);
}
}
} else if (timeDifference >= 40000) {
removeParticipant(socket, roomId, user.peerId, 2);
}
});
};
May be my way is not right please suggest better one also if anybody knows.
The text was updated successfully, but these errors were encountered:
I creating an video chat application with peerjs, socket (Nodejs) and front end is reactjs application.On join room it works fine but for reconnect it is not working fine. I test it with turning internet off for one device but sometime one of the remote device cannot see reconnected user
Below is my front end reactjs code to reconnect peer connection for video chat application.
In which i check if internet is restore check via socket.
useEffect(() => {
const recPeerAndJoinRoom = async () => {
try {
setRemoteStreams([])
setPrevPeerId(peer._lastServerId)
setIsReconnected(true)
initPeerJsConnection()
} catch (error) {
console.log(error)
}
}
socket.on("pong", (roomId, uuId) => {
const user = rooms[roomId]?.find((item) => item.uuId === uuId);
if (user) {
user["pingAt"] = new Date();
}
});
The text was updated successfully, but these errors were encountered: