l-min-components 1.0.660 → 1.0.664
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/header/index.jsx +27 -44
package/package.json
CHANGED
|
@@ -267,60 +267,43 @@ const HeaderComponent = (props) => {
|
|
|
267
267
|
const generalSocket = useRef()
|
|
268
268
|
const token = getCookie("access");
|
|
269
269
|
const account_id = generalData?.defaultAccount?.id || "";
|
|
270
|
-
|
|
271
|
-
useEffect(() => {
|
|
272
|
-
if(!socket?.current){
|
|
273
|
-
socket.current = new WebSocket(
|
|
274
|
-
`wss://${socketUrl}?account=${account_id}&authorization=${token}`
|
|
275
|
-
)
|
|
276
|
-
|
|
277
|
-
socket.current.onopen = () => {
|
|
278
|
-
console.log("websocket connection established");
|
|
279
|
-
};
|
|
280
|
-
socket.current.onmessage = (event) => {
|
|
281
|
-
const response = JSON?.parse(event?.data);
|
|
282
|
-
console.log(response)
|
|
283
|
-
if(response?.data){
|
|
284
|
-
handleGetUnreadNotification();
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
};
|
|
288
270
|
|
|
289
|
-
|
|
271
|
+
// websocket for all notification account
|
|
272
|
+
const websocket = new WebSocket(
|
|
273
|
+
`wss://${socketUrl}?account=${account_id}&authorization=${token}`
|
|
274
|
+
);
|
|
290
275
|
|
|
291
|
-
|
|
292
|
-
|
|
276
|
+
useEffect(() => {
|
|
277
|
+
websocket.onopen = () => {
|
|
278
|
+
//check if socket is connected
|
|
279
|
+
console.log("websocket connection established");
|
|
293
280
|
};
|
|
294
|
-
|
|
295
|
-
}, [socket]);
|
|
296
281
|
|
|
282
|
+
websocket.onmessage = (event) => {
|
|
283
|
+
const data = JSON.parse(event.data);
|
|
284
|
+
console.log("websocket data", data);
|
|
285
|
+
};
|
|
297
286
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
};
|
|
308
|
-
generalSocket.current.onmessage = (event) => {
|
|
309
|
-
const response = JSON?.parse(event?.data);
|
|
310
|
-
console.log(response)
|
|
311
|
-
if(response?.data){
|
|
312
|
-
handleGeneralNotificationCount();
|
|
287
|
+
const handler = (event) => {
|
|
288
|
+
if (event?.data) {
|
|
289
|
+
const data = JSON.parse(event?.data); //check for incoming message from socket
|
|
290
|
+
if (data.event === "new.notification.result") {
|
|
291
|
+
if (data.data) {
|
|
292
|
+
console.log(data)
|
|
293
|
+
handleGetUnreadNotification();
|
|
294
|
+
handleGeneralNotificationCount();
|
|
295
|
+
}
|
|
313
296
|
}
|
|
314
|
-
|
|
315
|
-
};
|
|
316
297
|
|
|
317
|
-
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
websocket.addEventListener("message", handler, { passive: true });
|
|
318
301
|
|
|
319
302
|
return () => {
|
|
320
|
-
|
|
303
|
+
websocket.removeEventListener("message", handler);
|
|
304
|
+
console.log("websocket closed");
|
|
321
305
|
};
|
|
322
|
-
|
|
323
|
-
}, [generalSocket]);
|
|
306
|
+
}, [websocket]);
|
|
324
307
|
|
|
325
308
|
|
|
326
309
|
return (
|