- fixed parsing websocket message;

This commit is contained in:
Vitalii Kiiko
2025-01-02 10:33:54 +01:00
parent fd2be71821
commit 4f5bb94246

View File

@@ -163,12 +163,11 @@ const NotificationsSidebar = () => {
stomp.current.connect(
{},
() => {
// connected
console.log('Websocket connected');
//console.log('Websocket connected');
setIsConnected(true);
},
(error) => {
console.error('WebSocket Connection Error:', error);
//console.error('WebSocket Connection Error:', error);
setIsConnected(false);
setTimeout(connectWebSocket, 5000);
}
@@ -176,14 +175,12 @@ const NotificationsSidebar = () => {
};
const subscribeTo = (topic) => {
console.log('subscribeTo', topic)
const subscription = stomp.current.subscribe(
topic,
(message) => {
try {
const notification = JSON.parse(message.body);
console.log('notification', notification)
//setNotifications(prev => [notification, ...prev]);
setNotifications(prev => [notification, ...prev]);
} catch (error) {
console.error('Error parsing notification:', error);
}
@@ -208,7 +205,7 @@ const NotificationsSidebar = () => {
if (stomp.current) {
stomp.current.disconnect(() => {
console.log('WebSocket Disconnected');
//console.log('WebSocket Disconnected');
});
}
};