From 276c42505ec10062dbfc3cbf92296a1661743696 Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Mon, 16 Sep 2024 15:44:56 -0500 Subject: [PATCH 1/2] feat: (WIP) Websockets configuration --- src/App.js | 3 +++ src/webSockets/WebSocket.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/webSockets/WebSocket.js 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/shared-data/'); + + 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; From b3acec5611300807dfa06f4522e4b7773e335ecd Mon Sep 17 00:00:00 2001 From: Jose Buitron Date: Wed, 18 Sep 2024 10:13:20 -0500 Subject: [PATCH 2/2] fix: Fixed ws name --- src/webSockets/WebSocket.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webSockets/WebSocket.js b/src/webSockets/WebSocket.js index be6789716..11483d009 100644 --- a/src/webSockets/WebSocket.js +++ b/src/webSockets/WebSocket.js @@ -4,7 +4,7 @@ const WebSocketComponent = props => { const [message, setMessage] = useState(''); useEffect(() => { - const socket = new WebSocket('ws://127.0.0.1:8000/ws/shared-data/'); + const socket = new WebSocket('ws://127.0.0.1:8000/ws/notifications/'); socket.onopen = () => { console.log('WebSocket connection opened');