@@ -26,10 +26,24 @@ the deck container.
26
26
myWebSocket : null ,
27
27
ip : '127.0.0.1' ,
28
28
port : '8080' ,
29
+ reconnectAttempt : null ,
30
+ reconnect : function ( ) {
31
+ if ( this . myWebSocket != null && this . myWebSocket . readyState <= WebSocket . OPEN ) return ;
32
+ if ( this . reconnectAttempt ) return ;
33
+ var $this = this ;
34
+ this . reconnectAttempt = setTimeout ( function ( ) { $this . init ( ) } , 1000 ) ;
35
+ } ,
29
36
init : function ( ) {
37
+ this . reconnectAttempt = null ;
38
+
30
39
if ( 'WebSocket' in window == false && 'MozWebSocket' in window ) window . WebSocket = window . MozWebSocket ;
31
40
32
- this . myWebSocket = new WebSocket ( "ws://" + this . ip + ":" + this . port ) ;
41
+ try {
42
+ this . myWebSocket = new WebSocket ( "ws://" + this . ip + ":" + this . port ) ;
43
+ } catch ( e ) {
44
+ this . reconnect ( ) ;
45
+ return ;
46
+ }
33
47
34
48
if ( location . href . indexOf ( '#mirror' ) != - 1 ) {
35
49
this . initMirror ( parseInt ( location . href . substr ( 7 + location . href . indexOf ( '#mirror' ) ) ) ) ;
@@ -38,6 +52,7 @@ the deck container.
38
52
$this = this ;
39
53
this . myWebSocket . onopen = function ( evt ) {
40
54
$this . myWebSocket . send ( '{"type":"identify", "data":"server", "url":"' + location . href + '"}' ) ;
55
+ $this . sendStatus ( ) ;
41
56
} ;
42
57
this . myWebSocket . onmessage = function ( evt ) {
43
58
try {
@@ -49,7 +64,9 @@ the deck container.
49
64
} catch ( e ) {
50
65
}
51
66
} ;
52
- this . myWebSocket . onclose = function ( evt ) { } ;
67
+ this . myWebSocket . onclose = function ( evt ) {
68
+ $this . reconnect ( ) ;
69
+ } ;
53
70
} ,
54
71
initMirror : function ( offset ) {
55
72
$this = this ;
@@ -65,7 +82,9 @@ the deck container.
65
82
} catch ( e ) {
66
83
}
67
84
} ;
68
- this . myWebSocket . onclose = function ( evt ) { } ;
85
+ this . myWebSocket . onclose = function ( evt ) {
86
+ $this . reconnect ( ) ;
87
+ } ;
69
88
this . sendStatus = function ( ) { } ;
70
89
} ,
71
90
sendStatus : function ( ) {
0 commit comments