This repository was archived by the owner on Mar 23, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -4,21 +4,30 @@ const component = () => {
4
4
paused : undefined ,
5
5
loading : false ,
6
6
toggling : false ,
7
+ ws : undefined ,
7
8
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 => {
11
14
const data = JSON . parse ( event . data ) ;
12
15
this . jobs = data . jobs ;
13
16
this . paused = data . paused ;
14
17
} ;
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' ) ;
17
22
} ;
18
- ws . onclose = err => {
23
+ this . ws . onerror = ( ) => {
24
+ if ( secure )
25
+ return this . ws . failed = true ;
19
26
alert ( 'danger' , 'Socket connection failed' ) ;
20
27
} ;
21
-
28
+ } ,
29
+ init ( ) {
30
+ this . wsConnect ( ) ;
22
31
this . load ( ) ;
23
32
} ,
24
33
load ( ) {
You can’t perform that action at this time.
0 commit comments