fix: websocket handlers

This commit is contained in:
canove
2020-08-10 19:24:15 -03:00
parent 1c0e251b24
commit c7c451d227
4 changed files with 16 additions and 9 deletions

View File

@@ -28,7 +28,7 @@ import ContactsSekeleton from "../../components/ContactsSekeleton";
import ContactModal from "../../components/ContactModal";
import ConfirmationModal from "../../components/ConfirmationModal/";
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
let socket;
const useStyles = makeStyles(theme => ({
mainContainer: {
@@ -105,6 +105,7 @@ const Contacts = () => {
}, [searchParam, page, rowsPerPage]);
useEffect(() => {
socket = openSocket(process.env.REACT_APP_BACKEND_URL);
return () => {
socket.disconnect();
};

View File

@@ -10,7 +10,7 @@ import Paper from "@material-ui/core/Paper";
import SessionInfo from "../../components/SessionInfo";
import Qrcode from "../../components/Qrcode";
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
let socket;
const useStyles = makeStyles(theme => ({
root: {
@@ -54,6 +54,14 @@ const WhatsAuth = () => {
fetchSession();
}, []);
useEffect(() => {
socket = openSocket(process.env.REACT_APP_BACKEND_URL);
return () => {
socket.disconnect();
};
}, []);
useEffect(() => {
socket.on("qrcode", data => {
if (data.action === "update") {
@@ -68,10 +76,6 @@ const WhatsAuth = () => {
history.push("/chat");
}
});
return () => {
socket.disconnect();
};
}, [history]);
return (