1- var instance_skel = require ( '../../instance_skel' )
1+ const instance_skel = require ( '../../instance_skel' )
22const actions = require ( './actions' )
33
44const WebSocket = require ( 'ws' )
@@ -35,6 +35,9 @@ class instance extends instance_skel {
3535 this . ws . close ( 1000 )
3636 delete this . ws
3737 }
38+ if ( this . reconnect ) {
39+ clearInterval ( this . reconnect )
40+ }
3841 }
3942
4043 updateConfig ( config ) {
@@ -43,7 +46,9 @@ class instance extends instance_skel {
4346 }
4447
4548 initWebSocket ( ) {
46- clearInterval ( this . reconnect )
49+ if ( this . reconnect ) {
50+ clearInterval ( this . reconnect )
51+ }
4752
4853 if ( this . ws !== undefined ) {
4954 this . ws . close ( 1000 )
@@ -68,23 +73,29 @@ class instance extends instance_skel {
6873 this . ws . on ( 'close' , ( code ) => {
6974 if ( code !== 1000 ) {
7075 this . debug ( 'error' , `Websocket closed: ${ code } ` )
71- this . reconnect = setInterval ( ( ) => {
72- this . initWebSocket ( )
73- } , 500 )
7476 }
77+ this . reconnect = setInterval ( ( ) => {
78+ this . initWebSocket ( )
79+ } , 1000 )
7580 } )
7681
7782 this . ws . on ( 'message' , this . messageReceivedFromWebSocket . bind ( this ) )
7883
7984 this . ws . on ( 'error' , ( data ) => {
80- this . status ( this . STATUS_ERROR )
81- this . log ( 'error' , `WebSocket ${ data } ` )
85+ if ( this . currentStatus != 2 ) {
86+ this . status ( this . STATUS_ERROR )
87+ if ( data ?. code == 'ENOTFOUND' ) {
88+ this . log ( 'error' , `Unable to reach api.vdo.ninja` )
89+ } else {
90+ this . log ( 'error' , `WebSocket ${ data } ` )
91+ }
92+ }
8293 this . ws . close ( )
8394 } )
8495 }
8596
8697 messageReceivedFromWebSocket ( data ) {
87- this . log ( ' debug' , `Message received: ${ data } ` )
98+ this . debug ( `Message received: ${ data } ` )
8899 }
89100
90101 config_fields ( ) {
0 commit comments