"use strict"; var numnoti = 0; const retryTimes = [0, 3000, 10000, 60000]; var notiaudio = document.getElementById("noti-audio"); var connection = new signalR.HubConnectionBuilder() .configureLogging("none") .withUrl("https://bongdaplus.vn:9501/Notification-Hub", { accessTokenFactory: () => this.loginToken, skipNegotiation: true, transport: signalR.HttpTransportType.WebSockets }) .withAutomaticReconnect({ nextRetryDelayInMilliseconds: context => { const index = context.previousRetryCount < retryTimes.length ? context.previousRetryCount : retryTimes.length - 1; return retryTimes[index]; } }) .build(); connection.on("ReceiveNotification", function (message) { var oldmess = $("#lstnoti").html(); $("#lstnoti").html(buildhtml_notifi(message) + oldmess); numnoti = numnoti + 1; //$("#noti-cnt").removeClass("noti-cnt-fill"); //$("#noti-cnt").html("" + numnoti + ""); $("#noti-cnt").html(numnoti.toString()); notiaudio.play(); }); connection.start().then(function () { }).catch(function (err) { return console.error(err.toString()); }); //----------------------------------------------------------------------- function loadNotification() { $.getJSON("/GetNotification", function (data) { var mes = ""; var oldmess = $("#lstnoti").html(); $.each(data, function (key, value) { mes = mes + buildhtml_notifi(value.contents); if (value.isRead == '0') { numnoti = numnoti + 1; } }); $("#lstnoti").html(oldmess + mes); if (numnoti > 0) { //$("#noti-cnt").removeClass("noti-cnt-fill"); //$("#noti-cnt").html("" + numnoti + ""); $("#noti-cnt").html(numnoti.toString()); } else { //$("#noti-cnt").addClass("noti-cnt-fill"); $("#noti-cnt").html(""); } }); } function readNotification() { $.get("/SetFuncs/readmess", function (data) { }); //$("#noti-cnt").addClass("noti-cnt-fill"); $("#noti-cnt").html(""); numnoti = 0; } function buildhtml_notifi(mes) { return "