refactored socket connection events
This commit is contained in:
parent
c4a32df45c
commit
2e93fd9fc5
49
lib/node.js
49
lib/node.js
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ var types = [
|
||||
},
|
||||
{
|
||||
name: "warn",
|
||||
sign: '=❗=',
|
||||
sign: '=!=',
|
||||
signColor: chalk.yellow,
|
||||
messageColor: chalk.bold.yellow,
|
||||
formatter: function (sign, message)
|
||||
|
Loading…
Reference in New Issue
Block a user