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