Merge pull request #117 from cubedro/develop

Socket events refactor
This commit is contained in:
Marian OANCΞA 2015-05-11 21:00:06 +03:00
commit 8e1fc2d7d1
3 changed files with 44 additions and 9 deletions

View File

@ -5,5 +5,5 @@ if [[ -f /usr/bin/geth ]];
then
geth -rpc -maxpeers "50" -verbosity "3" -bootnodes "enode://09fbeec0d047e9a37e63f60f8618aa9df0e49271f3fadb2c070dc09e2099b95827b63a8b837c6fd01d0802d457dd83e3bd48bd3e6509f8209ed90dabbc30e3d3@52.16.188.185:30303" -nat "extip:$IP"
else
eth --bootstrap --peers 50 --remote 52.16.188.185:30303 --mining off --json-rpc --public-ip $IP -v 4
eth --bootstrap --peers 50 --remote 52.16.188.185:30303 --mining off --json-rpc --public-ip $IP -v 3
fi

View File

@ -39,7 +39,7 @@ Socket = Primus.createSocket({
transformer: 'websockets',
pathname: '/api',
timeout: 120000,
strategy: 'disconnect,online',
strategy: 'disconnect,online,timeout',
plugin: {emitter: Emitter, sparkLatency: Latency}
});
@ -173,7 +173,7 @@ Node.prototype.setupSockets = function()
// Setup events
socket.on('open', function open()
{
console.info('wsc', 'The connection has been opened.');
console.info('wsc', 'The socket connection has been opened.');
console.log(' ', 'Trying to login');
socket.emit('hello', {
@ -185,14 +185,14 @@ Node.prototype.setupSockets = function()
.on('ready', function()
{
self._socket = true;
console.success('wsc', 'The connection has been established.');
console.success('wsc', 'The socket connection has been established.');
self.updateBlock();
self.update(true);
})
.on('data', function incoming(data)
{
console.info('Received some data', data);
console.info('Socket received some data', data);
})
.on('history', function (data)
{
@ -212,15 +212,50 @@ Node.prototype.setupSockets = function()
.on('end', function end()
{
self._socket = false;
console.error('wsc', 'Socket connection closed');
console.error('wsc', 'Socket connection end received');
})
.on('error', function error(err)
{
console.error('wsc', 'Socket error:', err);
})
.on('reconnecting', function reconnecting(opts)
.on('timeout', function ()
{
console.warn('wsc', 'We are scheduling a reconnect operation', opts);
console.error('wsc', 'Socket connection timeout');
})
.on('close', function ()
{
self._socket = false;
console.error('wsc', 'Socket connection has been closed');
})
.on('offline', function ()
{
self._socket = false;
console.error('wsc', 'Network connection is offline');
})
.on('online', function ()
{
console.info('wsc', 'Network connection is online');
})
.on('reconnect', function ()
{
console.info('wsc', 'Socket reconnect attempt started');
})
.on('reconnect scheduled', function (opts)
{
console.warn('wsc', 'Reconnecting in', opts.scheduled, 'ms');
console.warn('wsc', 'This is attempt', opts.attempt, 'out of', opts.retries);
})
.on('reconnected', function (opts)
{
console.success('wsc', 'Socket reconnected successfully after', opts.duration, 'ms');
})
.on('reconnect timeout', function (err, opts)
{
console.error('wsc', 'Socket reconnect atempt took too long:', err.message);
})
.on('reconnect failed', function (err, opts)
{
console.error('wsc', 'Socket reconnect failed:', err.message);
});
}

View File

@ -44,7 +44,7 @@ var types = [
},
{
name: "warn",
sign: '==',
sign: '=!=',
signColor: chalk.yellow,
messageColor: chalk.bold.yellow,
formatter: function (sign, message)