From 545f995a3e71904faefc8afb01f4a5f1a5ab5c98 Mon Sep 17 00:00:00 2001 From: d3x0r Date: Mon, 27 Mar 2017 16:55:29 -0700 Subject: [PATCH] Handle batched messages. Failure to handle batch messages causes half communcaitions failures... (the clients were using a batching protocol, while all servers were based on this example... --- examples/http-external-ws.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/http-external-ws.js b/examples/http-external-ws.js index 0099ca79..f59819e3 100644 --- a/examples/http-external-ws.js +++ b/examples/http-external-ws.js @@ -46,7 +46,12 @@ function acceptConnection( connection ) { gunPeers.push( connection ); connection.on( 'error',function(error){console.log( "WebSocket Error:", error) } ); - connection.on( 'message',function(msg){gun.on('in',JSON.parse( msg))}) + connection.on('message', function (msg) { + msg = JSON.parse(msg) + if ("forEach" in msg) msg.forEach(m => gun.on('in', JSON.parse(m))); + else gun.on('in', msg) + }) + connection.on( 'close', function(reason,desc){ // gunpeers gone. var i = gunPeers.findIndex( function(p){return p===connection} );