Skip to content

Commit

Permalink
cli: enable reconnection reporting
Browse files Browse the repository at this point in the history
PR-URL: #391
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
  • Loading branch information
belochub committed Dec 11, 2018
1 parent da5bc6a commit 56a2e34
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/cli/command-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ module.exports = class CommandProcessor extends EventEmitter {
event: new EventCompleter(cli),
connect: new ConnectCompleter(cli),
};

this._connectionCloseListener = () => {
this.cli.log('Connection lost');
};
}

getNextCompleter(name) {
Expand Down Expand Up @@ -144,6 +148,20 @@ module.exports = class CommandProcessor extends EventEmitter {
return;
}
this.cli.api = filterApiCompletions(api, ['_', 'domain']);

connection.once('close', this._connectionCloseListener);
connection.on('reconnectAttempt', () => {
this.cli.log('Attempting to reconnect...');
});
connection.on('reconnect', err => {
if (err) {
this.cli.log('Reconnection failed');
this.cli._logErr(err);
} else {
this.cli.log('Successfully reconnected');
connection.once('close', this._connectionCloseListener);
}
});
// TODO: make event registering generic
connection.on('event', (interfaceName, eventName, args) => {
this.cli.log(`Received remote event '${eventName}'` +
Expand Down Expand Up @@ -171,6 +189,7 @@ module.exports = class CommandProcessor extends EventEmitter {
}

_disconnect() {
this.cli.connection.removeListener('close', this._connectionCloseListener);
this.cli.connection.close();
this.cli.connection = null;
}
Expand Down

0 comments on commit 56a2e34

Please sign in to comment.