{"version":3,"sources":["EncompassWebServices/includes/Notification.js"],"names":["connectionID","num","window","EWS","connection","returnConnection","getGlobalConnection","Promise","resolve","push","async","browserNotify","userName","message","callback","Notification","permission","requestPermission","catch","err","document","hidden","notify","body","onclick","e","preventDefault","focus","Ready","getConnection","options","skipNegotiation","transport","signalR","HttpTransportType","WebSockets","HubConnectionBuilder","withUrl","location","origin","configureLogging","LogLevel","Information","withAutomaticReconnect","build","jsPromises","EC_Fmt","LoadScript","all","on","connID","forEach","a","msg","NotificationNumEle","getElementById","style","display","notificationNum","Number","localStorage","getItem","innerText","setItem","state","HubConnectionState","Connected","start","onclose","invoke","Distributor","NotifyButton","removeItem","href","EduGoHome"],"mappings":"AAAA,aAEA,IAAIA,aACJ,IAAIC,KACH,SAAUC,EAAQC,GACf,IAAIC,EACJ,IAAIC,KACJH,EAAOI,oBAAsB,WACzB,GAAIF,EAAY,CACZ,OAAOG,QAAQC,QAAQJ,GAE3B,OAAO,IAAIG,QAASC,IAChBH,EAAiBI,KAAKD,MAG9BE,eAAeC,EAAcC,EAAUC,EAASC,GAC5C,KAAM,iBAAkBZ,GAAS,CAC7B,OAEJ,GAAIa,aAAaC,aAAe,SAAU,CACtC,OAEJ,GAAID,aAAaC,aAAe,UAAW,OACjCD,aAAaE,oBAAoBC,MAAMC,GAAO,UAExD,GAAIJ,aAAaC,aAAe,UAAW,CACvC,OAEJ,IAAKH,EAAS,CACV,OAEJ,IAAKO,SAASC,OAAQ,CAClB,OAGJ,MAAMC,EAAS,IAAIP,kBAAkBH,QACjCW,KAAMV,IAEVS,EAAOE,QAAU,SAAUC,GACvBA,EAAEC,iBACFxB,EAAOyB,QACP,UAAWb,IAAa,WAAY,CAChCA,IAEJ,OAAO,OAGfH,EAAc,OAAQ,MACtBT,EAAOS,cAAgBA,EACvBR,EAAIyB,MAAMlB,UACN,SAASmB,IACL,MAAMC,GAAYC,gBAAiB,KAAMC,UAAWC,QAAQC,kBAAkBC,YAE9E,OAAO,IAAIF,QAAQG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,eAAe,aAC1C,GAAImB,EAAW,CACXA,EAAUlD,QAAU,MAChBtB,EAAOoC,SAASmC,QAAUvE,EAAOoC,SAASC,uCA1H1D,CA8HErC,OAAQC","file":"Notification.min.js","sourcesContent":["\"use strict\";\n\nlet connectionID;\nlet num;\n(function (window, EWS) {\n let connection;\n let returnConnection = [];\n window.getGlobalConnection = function () {\n if (connection) {\n return Promise.resolve(connection);\n }\n return new Promise((resolve) => {\n returnConnection.push(resolve);\n });\n };\n async function browserNotify(userName, message, callback) {\n if (!(\"Notification\" in window)) {\n return;\n }\n if (Notification.permission === \"denied\") {\n return;\n }\n if (Notification.permission === \"default\") {\n await Notification.requestPermission().catch(err => \"denied\");\n }\n if (Notification.permission !== \"granted\") {\n return;\n }\n if (!message) {\n return;\n }\n if (!document.hidden) {\n return;\n }\n // eslint-disable-next-line no-new\n const notify = new Notification(`来自${userName}的消息`, {\n body: message\n });\n notify.onclick = function (e) {\n e.preventDefault();\n window.focus();\n if (typeof callback === \"function\") {\n callback();\n }\n return false;\n };\n }\n browserNotify(\"系统消息\", null);\n window.browserNotify = browserNotify;\n EWS.Ready(async () => {\n function getConnection() {\n const options = { skipNegotiation: true, transport: signalR.HttpTransportType.WebSockets };\n\n return new signalR.HubConnectionBuilder()\n .withUrl(`${window.location.origin}/hubs/chathub`, options)\n .configureLogging(signalR.LogLevel.Information)\n .withAutomaticReconnect()\n .build();\n }\n\n const jsPromises = [\n EC_Fmt.LoadScript(\"https://cdnjs.cloudflare.com/ajax/libs/microsoft-signalr/6.0.1/signalr.js\")\n ];\n if (jsPromises) {\n await Promise.all(jsPromises);\n }\n\n connection = getConnection();\n\n connection.on(\"ReceiveConnectionId\", (connID) => {\n connectionID = connID;\n if (returnConnection) {\n returnConnection.forEach(a => a(connection));\n returnConnection = [];\n }\n });\n\n connection.on(\"ReceiveGroupMessage\", (msg) => {\n const NotificationNumEle = document.getElementById(\"NotificationNum\");\n if (NotificationNumEle) {\n NotificationNumEle.style.display = \"block\";\n let notificationNum = Number(localStorage.getItem(\"notificationNum\"));\n if (notificationNum === 0) {\n notificationNum = 1;\n } else {\n notificationNum++;\n }\n NotificationNumEle.innerText = notificationNum;\n localStorage.setItem(\"notificationNum\", Number(notificationNum));\n }\n });\n connection.on(\"connectionStateChanged\", async (state) => {\n if (state !== signalR.HubConnectionState.Connected) {\n await connection.start();\n }\n });\n\n connection.onclose(async () => {\n await connection.start();\n });\n\n await connection.start();\n connection.invoke(\"JoinGroup\", Distributor);\n const NotifyButton = document.getElementById(\"NotifyButton\");\n\n if (NotifyButton) {\n NotifyButton.onclick = () => {\n const NotificationNumEle = document.getElementById(\"NotificationNum\");\n if (NotificationNumEle) {\n NotificationNumEle.style.display = \"none\";\n NotificationNumEle.innerText = 0;\n localStorage.removeItem(\"notificationNum\");\n }\n window.location.href = `${window.location.origin}/Home?DashboardID=195849`;\n };\n\n const NotificationNumEle = document.getElementById(\"NotificationNum\");\n const notificationNum = Number(localStorage.getItem(\"notificationNum\"));\n if (notificationNum !== 0) {\n NotificationNumEle.innerText = notificationNum;\n NotificationNumEle.style.display = \"block\";\n }\n }\n const EduGoHome = document.getElementById(\"EduGoHome\");\n if (EduGoHome) {\n EduGoHome.onclick = () => {\n window.location.href = `${window.location.origin}/Home?DashboardID=195762`;\n };\n }\n });\n}(window, EWS));\n"]}