Skip to content
This repository was archived by the owner on Mar 23, 2025. It is now read-only.

Commit a4c6e66

Browse files
committed
Try WSS first, and fallback to WS (#144)
1 parent 0b457a2 commit a4c6e66

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

public/js/download-manager.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,30 @@ const component = () => {
44
paused: undefined,
55
loading: false,
66
toggling: false,
7+
ws: undefined,
78

8-
init() {
9-
const ws = new WebSocket(`ws://${location.host}${base_url}api/admin/mangadex/queue`);
10-
ws.onmessage = event => {
9+
wsConnect(secure = true) {
10+
const url = `${secure ? 'wss' : 'ws'}://${location.host}${base_url}api/admin/mangadex/queue`;
11+
console.log(`Connecting to ${url}`);
12+
this.ws = new WebSocket(url);
13+
this.ws.onmessage = event => {
1114
const data = JSON.parse(event.data);
1215
this.jobs = data.jobs;
1316
this.paused = data.paused;
1417
};
15-
ws.onerror = err => {
16-
alert('danger', `Socket connection failed. Error: ${err}`);
18+
this.ws.onclose = () => {
19+
if (this.ws.failed)
20+
return this.wsConnect(false);
21+
alert('danger', 'Socket connection closed');
1722
};
18-
ws.onclose = err => {
23+
this.ws.onerror = () => {
24+
if (secure)
25+
return this.ws.failed = true;
1926
alert('danger', 'Socket connection failed');
2027
};
21-
28+
},
29+
init() {
30+
this.wsConnect();
2231
this.load();
2332
},
2433
load() {

0 commit comments

Comments
 (0)