From 433ad72752e26803d610c4c5eb693663cfc73d52 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sun, 9 Jun 2019 00:09:07 -0600 Subject: [PATCH] Fixes & /clear * Fix use port from config * Add /clear & menu method: clearMessages() --- core/mrc.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/core/mrc.js b/core/mrc.js index 3ab1e91b..c80adf80 100644 --- a/core/mrc.js +++ b/core/mrc.js @@ -10,6 +10,7 @@ const { } = require('./color_codes.js'); const stringFormat = require('./string_format.js'); const StringUtil = require('./string_util.js'); +const Config = require('./config.js').get; // deps const _ = require('lodash'); @@ -112,6 +113,11 @@ exports.getModule = class mrcModule extends MenuModule { quit : (formData, extraArgs, cb) => { return this.prevMenu(cb); + }, + + clearMessages : (formData, extraArgs, cb) => { + this.clearMessages(); + return cb(null); } }; } @@ -132,7 +138,7 @@ exports.getModule = class mrcModule extends MenuModule { }, (callback) => { const connectOpts = { - port : 5000, + port : _.get(Config(), 'chatServers.mrc.serverPort', 5000), host : 'localhost', }; @@ -160,6 +166,15 @@ exports.getModule = class mrcModule extends MenuModule { this.processReceivedMessage(data); }); + this.state.socket.once('error', err => { + this.log.warn( { error : err.message }, 'MRC multiplexer socket error' ); + this.state.socket.destroy(); + delete this.state.socket; + + // bail with error - fall back to prev menu + return callback(err); + }); + return(callback); } ], @@ -389,8 +404,11 @@ exports.getModule = class mrcModule extends MenuModule { this.sendServerMessage('LIST'); break; + case 'quit' : + return this.prevMenu(); + case 'clear': - chatLogView.setText(''); + this.clearMessages(); break; case '?': @@ -404,7 +422,11 @@ exports.getModule = class mrcModule extends MenuModule { // just do something to get the cursor back to the right place ¯\_(ツ)_/¯ this.sendServerMessage('STATS'); + } + clearMessages() { + const chatLogView = this.viewControllers.mrcChat.getView(MciViewIds.mrcChat.chatLog); + chatLogView.setText(''); } /**