socket bugfix

This commit is contained in:
cv
2021-04-23 15:02:28 +02:00
parent 683efe56bc
commit f3ce5681c1
+3 -5
View File
@@ -1,9 +1,7 @@
import { createContext, useContext, useEffect, useState } from 'react'; import { createContext, useContext, useEffect, useState } from 'react';
import io from 'socket.io-client'; import io from 'socket.io-client';
import { serverURL } from '../api/apiConstants';
import { NODE_PORT } from '../api/apiConstants'; import { NODE_PORT } from '../api/apiConstants';
export const SocketContext = createContext([[], () => {}]);
// get origin from URL // get origin from URL
const serverURL = window.location.origin.replace( const serverURL = window.location.origin.replace(
window.location.port, window.location.port,
@@ -20,9 +18,9 @@ function SocketProvider(props) {
const [socket, setSocket] = useState(); const [socket, setSocket] = useState();
useEffect(() => { useEffect(() => {
const socket = io(serverURL, { transports: ['websocket'] }); const s = io(serverURL, { transports: ['websocket'] });
setSocket(socket); setSocket(s);
return () => socket.disconnect(); return () => s.disconnect();
}, []); }, []);
return ( return (