Ranvier telnet is an event-based telnet server and socket package with GMCP support. Telnet commands are issued as events that you can handle as you please.
Node >= 7
const Telnet = require('ranvier-telnet');
const server = new Telnet.TelnetServer(rawSocket => {
const telnetSocket = new Telnet.TelnetSocket();
telnetSocket.attach(rawSocket);
telnetSocket.on('data', data => {
// do stuff with input
});
}).netServer;
server.listen(4000);
<event name>(arguments)
data(Buffer input)
: Stream data that is not part of an IAC sequenceWILL/WONT/DO/DONT(number commandOpt)
: IAC command event, argument is the opt byte to the command, you can useRanvierTelnet.Options
or your own map of options.SUBNEG(number opt, Buffer buffer)
: Sent at completion ofIAC SB <OPT> [data] IAC SB
sequence.buffer
argument is aBuffer
of SB dataGMCP(string package, data)
: Sent on completion of GMCP data. See: https://www.gammon.com.au/gmcpunknownAction(number command, number opt)
: Some unknown IAC command was given
As shown above you can receive GMCP data with the GMCP
event. To send GMCP data you can use the sendGMCP
method:
telnetSocket.sendGMCP('foo.bar', { some: "data" });
If you want to execute other telnet commands, perhaps in response to a DO
or DONT
you can use the telnetCommand
method:
// inside some class somewhere
this.useGMCP = false;
telnetSocket.on('DO', option => {
switch (option) {
case Telnet.Options.GMCP:
this.useGMCP = true;
break;
}
});
telnetSocket.telnetCommand(Telnet.Sequences.WILL, Telnet.Options.GMCP);