diff --git a/src/App.js b/src/App.js index e07b6a3ef..a4e7af08f 100644 --- a/src/App.js +++ b/src/App.js @@ -25,6 +25,8 @@ import Routes, { useOptionalAuth } from 'navigation/components/Routes'; import 'index.css'; +import WebSocket from 'webSockets/WebSocket'; + import BreadcrumbsShareContainer from 'layout/BreadcrumbsShareContainer'; import OptionalAuthBottomMessage from 'account/components/OptionalAuthBottomMessage'; import OptionalAuthTopMessage from 'account/components/OptionalAuthTopMessage'; @@ -40,6 +42,7 @@ const App = () => { return ( <> + { + const [message, setMessage] = useState(''); + + useEffect(() => { + const socket = new WebSocket('ws://127.0.0.1:8000/ws/notifications/'); + + socket.onopen = () => { + console.log('WebSocket connection opened'); + }; + + socket.onmessage = event => { + const data = JSON.parse(event.data); + setMessage(data.message); + }; + + socket.onclose = () => { + console.log('WebSocket connection closed'); + }; + + return () => { + socket.close(); + }; + }, []); + + return ( + + Message from WebSocket: {message} + + ); +}; + +export default WebSocketComponent;
Message from WebSocket: {message}