2020-08-04 11:21:16 +09:00
|
|
|
@inject LinkGenerator linkGenerator
|
|
|
|
|
|
|
|
<div></div>
|
2020-06-24 10:23:16 +02:00
|
|
|
@await Component.InvokeAsync("NotificationsDropdown")
|
2020-08-04 11:21:16 +09:00
|
|
|
<script type="text/javascript">
|
2020-06-11 17:36:48 -05:00
|
|
|
|
2020-06-24 10:23:16 +02:00
|
|
|
var supportsWebSockets = 'WebSocket' in window && window.WebSocket.CLOSING === 2;
|
2020-06-11 17:36:48 -05:00
|
|
|
|
2020-08-04 11:21:16 +09:00
|
|
|
if (supportsWebSockets) {
|
|
|
|
|
|
|
|
var loc = window.location, ws_uri;
|
|
|
|
if (loc.protocol === "https:") {
|
|
|
|
ws_uri = "wss:";
|
|
|
|
} else {
|
|
|
|
ws_uri = "ws:";
|
|
|
|
}
|
|
|
|
ws_uri += "//" + loc.host;
|
|
|
|
ws_uri += "@linkGenerator.GetPathByAction("SubscribeUpdates", "Notifications")";
|
|
|
|
var newDataEndpoint = "@linkGenerator.GetPathByAction("GetNotificationDropdownUI", "Notifications")";
|
2020-06-24 10:23:16 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
socket = new WebSocket(ws_uri);
|
|
|
|
socket.onmessage = function (e) {
|
|
|
|
$.get(newDataEndpoint, function(data){
|
|
|
|
$("#notifications-nav-item").replaceWith($(data));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
socket.onerror = function (e) {
|
|
|
|
console.error("Error while connecting to websocket for notifications (callback)", e);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
console.error("Error while connecting to websocket for notifications", e);
|
|
|
|
}
|
2020-06-11 17:36:48 -05:00
|
|
|
}
|
2020-06-24 10:23:16 +02:00
|
|
|
|
|
|
|
</script>
|