From 23ea8fa6931d59351557eb06bdc637abcb11450d Mon Sep 17 00:00:00 2001 From: LV-426 Date: Tue, 13 Jan 2015 15:43:55 +0200 Subject: rz_mesh.js: attempt to actively disconnect on 'beforeunload' event --- src/client/rz_mesh.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/client') diff --git a/src/client/rz_mesh.js b/src/client/rz_mesh.js index 95a5f9ef..30318cf0 100644 --- a/src/client/rz_mesh.js +++ b/src/client/rz_mesh.js @@ -9,6 +9,7 @@ define([ 'rz_config', 'util', 'model/diff', 'model/util', 'socketio'], function( + rz_config.rz_server_port + '/graph'; // socketio namespace + var socket; var rz_mesh_graph_ref; /** @@ -16,7 +17,7 @@ define([ 'rz_config', 'util', 'model/diff', 'model/util', 'socketio'], function( */ function init(init_spec) { - var socket = io.connect(ws_server_url, { + socket = io.connect(ws_server_url, { 'reconnectionDelay': 3000, }); @@ -29,6 +30,13 @@ define([ 'rz_config', 'util', 'model/diff', 'model/util', 'socketio'], function( socket.on('error', on_error); socket.on('diff_commit__topo', ws_diff_merge__topo); socket.on('diff_commit__attr', ws_diff_merge__attr); + + // attempt to actively disconnect on tab/window close + // ref: https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers.onbeforeunload + window.addEventListener("beforeunload", function(e){ + socket.close(); + console.log('ws: connection closed on \'beforeunload\' event'); // no one will ever see this but still + }); } function on_connect() { @@ -36,7 +44,7 @@ define([ 'rz_config', 'util', 'model/diff', 'model/util', 'socketio'], function( } function on_disconnect() { - // TODO: call when possible + console.log('ws: connection closed on peer disconnect, endpoint: ' + ws_server_url); } function on_error(err) { -- cgit v1.3.1