diff options
Diffstat (limited to 'telnet-server.js')
-rw-r--r-- | telnet-server.js | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/telnet-server.js b/telnet-server.js index 6111d9d..d8d8e07 100644 --- a/telnet-server.js +++ b/telnet-server.js @@ -1,5 +1,6 @@ 'use strict' +const EventEmitter = require('events') const net = require('net') const setupClient = require('./client') @@ -9,8 +10,10 @@ const { } } = require('./tui-lib') -class TelnetServer { +class TelnetServer extends EventEmitter { constructor(backend) { + super() + this.backend = backend this.server = new net.Server(socket => this.handleConnection(socket)) this.sockets = [] @@ -28,7 +31,7 @@ class TelnetServer { interfacer, appConfig: { canControlPlayback: false, - canControlQueue: false, + canControlQueue: true, canProcessMetadata: false, canSuspend: false, showLeftPane: true, @@ -37,6 +40,8 @@ class TelnetServer { } }) + appElement.attachAsServerClient(this) + let closed = false const quit = (msg = 'See you!') => { @@ -52,16 +57,18 @@ class TelnetServer { appElement.on('quitRequested', quit) socket.on('close', () => { + clearInterval(renderInterval) if (!closed) { - clearInterval(renderInterval) flushable.end() closed = true this.sockets.splice(this.sockets.indexOf(socket), 1) } + this.emit('left', socket) }) socket.quit = quit this.sockets.push(socket) + this.emit('joined', socket) } disconnectAllSockets(msg) { |