mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: only show hint if disconnected for a long time
This commit is contained in:
1 parent
3808d9dda8
commit
eef64ff2e0
2 files changed
+6
-3
No files matched your search
@@ -23,12 +23,14 @@ export default class Sock {
|
||||
constructor(url, showNotification = true) {
|
||||
this.url = url;
|
||||
this.isreconnect = false;
|
||||
this.retryCount = 0;
|
||||
this.init();
|
||||
this.showNotification = showNotification;
|
||||
}
|
||||
|
||||
onauth() {
|
||||
remove();
|
||||
this.retryCount = 0;
|
||||
if (this.onopen) this.onopen(this.sock);
|
||||
}
|
||||
|
||||
@@ -37,12 +39,13 @@ export default class Sock {
|
||||
// SockJS wouldn't send cookie. hack.
|
||||
this.sock.onopen = () => this.send(document.cookie);
|
||||
this.sock.onclose = ({ code, reason }) => {
|
||||
this.retryCount++;
|
||||
console.warn('Connection closed, ', code, reason);
|
||||
if (code >= 4000) this.closed = true;
|
||||
if (!this.closed) {
|
||||
if (this.showNotification) create();
|
||||
this.isreconnect = setTimeout(this.init.bind(this), 3000);
|
||||
} else if (this.showNotification) create();
|
||||
}
|
||||
if (this.showNotification && this.retryCount > 3) create();
|
||||
if (this.onclose) this.onclose(code, reason);
|
||||
};
|
||||
this.sock.onmessage = (message) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/ui-default",
|
||||
"version": "4.20.6",
|
||||
"version": "4.20.7",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"license": "AGPL-3.0",
|
||||
"main": "hydro.js",
|
||||
|
||||
Reference in new issue
Block a user