l-min-components 1.0.652 → 1.0.655
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
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function getCookie(name) {
|
|
2
|
+
// Split cookie string and get all individual name=value pairs in an array
|
|
3
|
+
var cookieArr = document.cookie.split(";");
|
|
4
|
+
|
|
5
|
+
// Loop through the array elements
|
|
6
|
+
for (var i = 0; i < cookieArr.length; i++) {
|
|
7
|
+
var cookiePair = cookieArr[i].split("=");
|
|
8
|
+
|
|
9
|
+
/* Removing whitespace at the beginning of the cookie name
|
|
10
|
+
and compare it with the given string */
|
|
11
|
+
if (name == cookiePair[0].trim()) {
|
|
12
|
+
// Decode the cookie value and return
|
|
13
|
+
return decodeURIComponent(cookiePair[1]);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Return null if not found
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
@@ -24,6 +24,7 @@ import { OutletContext } from "..";
|
|
|
24
24
|
import { useLocation } from "react-router-dom";
|
|
25
25
|
import usFlag from "../../assets/images/usFlag.png";
|
|
26
26
|
import LanguageDropdown from "./languageDropdown";
|
|
27
|
+
import { getCookie } from "./getCookies";
|
|
27
28
|
/**
|
|
28
29
|
* @param {{
|
|
29
30
|
* type: string,
|
|
@@ -240,6 +241,40 @@ const HeaderComponent = (props) => {
|
|
|
240
241
|
return "Learning";
|
|
241
242
|
};
|
|
242
243
|
|
|
244
|
+
// websocket for notifications initialization
|
|
245
|
+
const [socketUrl, setSocketUrl] = useState(
|
|
246
|
+
"dev-117782726-api.learngual.com/notify/v1/ws/connect/"
|
|
247
|
+
);
|
|
248
|
+
const socket = useRef()
|
|
249
|
+
const token = getCookie("access");
|
|
250
|
+
const account_id = generalData?.defaultAccount?.id || "";
|
|
251
|
+
|
|
252
|
+
useEffect(() => {
|
|
253
|
+
if(!socket?.current){
|
|
254
|
+
socket.current = new WebSocket(
|
|
255
|
+
`wss://${socketUrl}?account=${account_id}&authorization=${token}`
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
socket.current.onopen = () => {
|
|
259
|
+
console.log("websocket connection established");
|
|
260
|
+
};
|
|
261
|
+
socket.current.onmessage = (event) => {
|
|
262
|
+
const response = JSON?.parse(event?.data);
|
|
263
|
+
console.log(response)
|
|
264
|
+
if(response?.data){
|
|
265
|
+
handleGetUnreadNotification();
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return () => {
|
|
273
|
+
console.log("websocket closed");
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
}, [socket]);
|
|
277
|
+
|
|
243
278
|
return (
|
|
244
279
|
<Navbar>
|
|
245
280
|
<img src={logo} alt="Learngual logo" />
|