- fixed parsing websocket message;
This commit is contained in:
@@ -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');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user