File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change 2828< body >
2929 < script type ="text/javascript " src ="/js/libs/jquery-2.1.3.js "> </ script >
3030 < script type ="text/javascript ">
31- var $body = $ ( 'body' ) ;
31+ var $body = $ ( 'body' ) ,
32+ connected = false ,
33+ domain ,
34+ user ;
3235
3336 $ . getJSON ( 'http://localhost:7000/config' , function ( resp ) {
3437 // resp should contain the username and root_domain
35- connect_ws ( resp . root_domain , resp . username ) ;
38+ domain = resp . root_domain ;
39+ user = resp . username ;
40+ setInterval ( check_connection , 5000 ) ;
41+ check_connection ( ) ;
3642 } ) ;
3743
44+ function check_connection ( ) {
45+ if ( ! connected ) {
46+ connect_ws ( domain , user ) ;
47+ }
48+ }
49+
3850 // initializes WebSocket connection
3951 function connect_ws ( root_domain , username ) {
4052 console . log ( 'init WebSocket connection as ' + username ) ;
4153 var ws = new WebSocket ( "ws://" + root_domain + "/ws/" + username ) ;
4254 ws . onopen = function ( ) {
55+ console . log ( 'connection open' ) ;
4356 ws . send ( "connecting as " + username ) ;
57+ connected = true ;
4458 } ;
4559 ws . onmessage = function ( evt ) {
4660 var data = JSON . parse ( evt . data ) ;
5771 } , 1000 ) ;
5872 } ) ;
5973 }
60-
74+ } ;
75+ ws . onclose = function ( evt ) {
76+ console . log ( 'connection closed' ) ;
77+ connected = false ;
6178 } ;
6279 }
6380 </ script >
You can’t perform that action at this time.
0 commit comments