diff options
| author | LV-426 <lv-426@taproot.org.il> | 2014-12-29 00:59:06 +0200 |
|---|---|---|
| committer | LV-426 <lv-426@taproot.org.il> | 2014-12-29 00:59:48 +0200 |
| commit | 6812460919e359e80bf506b6506e57f760abbbea (patch) | |
| tree | f07ca251fa3720a0ae2195a090e6be777cbae49d /src | |
| parent | 3d03bb0c2f3e2b07d8bfa4621f99e85069ac7d0c (diff) | |
rz_mesh: socket callbacks
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/rz_mesh.js | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/src/client/rz_mesh.js b/src/client/rz_mesh.js index 69806340..d7912e76 100644 --- a/src/client/rz_mesh.js +++ b/src/client/rz_mesh.js @@ -5,21 +5,48 @@ */ define([ 'rz_config', 'util', 'model/diff', 'socketio'], function(rz_config, util, model_diff, io) { - var rz_server_url = 'http://' + rz_config.rz_server_host + ':' - + rz_config.rz_server_port; + var ws_server_url = 'http://' + rz_config.rz_server_host + ':' + + rz_config.rz_server_port + + '/graph'; // socketio namespace - function init() { - var socket = io.connect(rz_server_url + '/graph', { - 'reconnection' : true, // TODO: limit reconnection attempts + var rz_mesh_graph_ref; + + /** + * @param init_spec: expected to contain a graph:graph mapping + */ + function init(init_spec) { + + var socket = io.connect(ws_server_url, { 'reconnectionDelay': 3000, }); + util.assert(undefined != init_spec.graph, 'unable to init ws connection, graph undefined'); + rz_mesh_graph_ref = init_spec.graph; + // wire up event handlers + socket.on('connect', on_connect); + socket.on('disconnect', on_disconnect); + socket.on('error', on_error); socket.on('diff_commit__topo', diff_merge__topo); } - function diff_merge__topo(topo_diff) { - console.log('ws: rx: diff_merge__topo') + function on_connect() { + console.log('ws: connection established: endpoint: ' + ws_server_url); + } + + function on_disconnect() { + // TODO: call when possible + } + + function on_error(err) { + console.log('ws: error: ' + err); + } + + function diff_merge__topo(topo_diff_raw) { + console.log('ws: rx: diff_merge__topo'); + var topo_diff_json = JSON.parse(topo_diff_raw); + var topo_diff = model_diff.new_topo_diff(topo_diff_json); + rz_mesh_graph_ref.on_backend__diff(topo_diff); } return { |
