ui: fix connection close

This commit is contained in:
undefined committed 2022-05-12 22:59:47 +08:00
1 parent fdcf06c373
commit 60aa0e1611
2 files changed
+2 -4

No files matched your search

@@ -5,7 +5,6 @@ export default class Sock {
const i = new URL(url, window.location.href);
i.protocol = i.protocol.replace('http', 'ws');
this.url = i.toString();
this.closed = false;
this.sock = new ReconnectingWebSocket(this.url);
this.sock.onopen = () => {
console.log('Connected');
@@ -13,7 +12,7 @@ export default class Sock {
};
this.sock.onclose = ({ code, reason }) => {
console.warn('Connection closed, ', code, reason);
if (code >= 4000) this.closed = true;
if (code >= 4000) this.close();
this.onclose?.(code, reason);
};
this.sock.onmessage = (message) => {
@@ -29,7 +28,6 @@ export default class Sock {
}
close() {
this.closed = true;
this.sock?.close?.();
}
}