BBSLink + WebSockets does not update key press monitor

This commit is contained in:
Bryan Ashby 2019-07-11 22:49:15 -06:00
parent 289b32c169
commit 3eed388e33
No known key found for this signature in database
GPG Key ID: B49EB437951D2542
2 changed files with 17 additions and 10 deletions

View File

@ -135,16 +135,21 @@ exports.getModule = class BBSLinkModule extends MenuModule {
}; };
let clientTerminated; let clientTerminated;
let dataOut;
self.client.term.write(resetScreen()); self.client.term.write(resetScreen());
self.client.term.write(' Connecting to BBSLink.net, please wait...\n'); self.client.term.write(` Connecting to ${self.config.host}, please wait...\n`);
const doorTracking = trackDoorRunBegin(self.client, `bbslink_${self.config.door}`); const doorTracking = trackDoorRunBegin(self.client, `bbslink_${self.config.door}`);
const bridgeConnection = net.createConnection(connectOpts, function connected() { const bridgeConnection = net.createConnection(connectOpts, function connected() {
self.client.log.info(connectOpts, 'BBSLink bridge connection established'); self.client.log.info(connectOpts, 'BBSLink bridge connection established');
self.client.term.output.pipe(bridgeConnection); dataOut = (data) => {
return bridgeConnection.write(data);
};
self.client.term.output.on('data', dataOut);
self.client.once('end', function clientEnd() { self.client.once('end', function clientEnd() {
self.client.log.info('Connection ended. Terminating BBSLink connection'); self.client.log.info('Connection ended. Terminating BBSLink connection');
@ -153,9 +158,11 @@ exports.getModule = class BBSLinkModule extends MenuModule {
}); });
}); });
const restorePipe = function() { const restore = () => {
self.client.term.output.unpipe(bridgeConnection); if(dataOut && self.client.term.output) {
self.client.term.output.resume(); self.client.term.output.removeListener('data', dataOut);
dataOut = null;
}
trackDoorRunEnd(doorTracking); trackDoorRunEnd(doorTracking);
}; };
@ -167,14 +174,14 @@ exports.getModule = class BBSLinkModule extends MenuModule {
}); });
bridgeConnection.on('end', function connectionEnd() { bridgeConnection.on('end', function connectionEnd() {
restorePipe(); restore();
return callback(clientTerminated ? Errors.General('Client connection terminated') : null); return callback(clientTerminated ? Errors.General('Client connection terminated') : null);
}); });
bridgeConnection.on('error', function error(err) { bridgeConnection.on('error', function error(err) {
self.client.log.info('BBSLink bridge connection error: ' + err.message); self.client.log.info('BBSLink bridge connection error: ' + err.message);
restorePipe(); restore();
callback(err); return callback(err);
}); });
} }
], ],

View File

@ -88,7 +88,7 @@ function WebSocketClient(ws, req, serverType) {
}); });
// //
// Montior connection status with ping/pong // Monitor connection status with ping/pong
// //
ws.on('pong', () => { ws.on('pong', () => {
Log.trace(`Pong from ${this.socketBridge.remoteAddress}`); Log.trace(`Pong from ${this.socketBridge.remoteAddress}`);