Skip to content

Commit

Permalink
fix: reconnect socket if get disconnected
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-ojha committed Jul 12, 2022
1 parent 6acd414 commit f9579da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 3 additions & 4 deletions client/src/pages/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ const Index = (): JSX.Element => {
setUserStories(userData.data.userStories);
setRenderMainPage(true);
}
socket.on("connect", () => {
console.log(`connected to id: ${socket.id}`);
});

socket.emit("authenticate", (res) => {
console.log(res);
});

if (!socket.connected) {
socket.connect();
}
socket.emit(
"join-room",
userData.data.userProfileDetail.id,
Expand Down
13 changes: 13 additions & 0 deletions client/src/services/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,17 @@ const socket = io(process.env.REACT_APP_API_BASE_URL as string, {
withCredentials: true,
});

// socket.on("connect_error", (err) => {
// console.log(err);
// });
// socket.on("connect_failed", (err) => {
// console.log(err);
// });
// socket.on("disconnect", (err) => {
// console.log(err);
// });
socket.on("connect", () => {
console.log(`connected to id: ${socket.id}`);
});

export default socket;

1 comment on commit f9579da

@roman-ojha
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for social ready!

✅ Preview
https://social-8id3hqjal-razzroman98-gmailcom.vercel.app
https://rsocial.vercel.app

Built with commit f9579da.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.