Commits

Marcin Lulek committed 6a1ddd8

updates to client

Comments (0)

Files changed (1)

gevent_cometd/static/client.js

     };
 
     var get_conn_id = function(create_new_socket) {
+        if (state.socket) {
+            console.log('socket present, delete old one');
+            state.socket.close();
+            state.socket = null;
+        }
+
         Request.post(state.webapp_url + "/connect", {
             handleAs : 'json',
             data : JSON.stringify(state.connection_request),
     }
 
     var close_event = function(event) {
-        if (state.reconnect_timout) {
-            clearTimeout(state.reconnect_timout);
-        }
-        state.reconnect_timout = setTimeout(function() {
-            /* reconnect requires fetching new id and updating socket */
-            get_conn_id(true);
-            console.log('Got new connection id');
-        }, 500); // try to collapse multiple reconnects into 1
+        console.log('detected socket closed');
+        state.socket.close();
     }
     var error_event = function(event) {
         console.log('Error event', event);
+        state.socket.close();
     }
 
     var create_socket = function() {
-        if (state.socket) {
-            console.log('socket present, delete old one');
-            state.socket.close();
-        }
         state.last_message = Date.now();
         console.log('attempting to create socket');
         if (state.check_connection) {
         }
         state.check_connection = setInterval(function() {
             var last_update = (Date.now() - state.last_message) / 1000.0;
-            if (last_update > 20) {
-                close_event();
+            if (last_update > 20 || state.socket.readyState == 3
+            || state.socket.readyState == 2) {
+                console.log('reconnect');
+                get_conn_id(true);
             }
-        }, 5000);
+        }, 3000);
     }
 
     var connect = function(webapp_url, server_url, connection_request,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.