Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createClient(options) {
assert.ok(options, "options is required");
var stream = options.stream;
assert.ok(stream, "stream is required");
assert.ok(options.username, "username is required");
var keepAlive = options.keepAlive == null ? true : options.keepAlive;
var optVersion = options.version || require('./mcversion.js');
var mcData = require('minecraft-data')(optVersion);
var version = mcData.version;
var client = new Client(false, version.majorVersion);
// Options to opt-out of MC protocol packet framing (useful since WS is alreay framed)
if (options.noPacketFramer) {
client.framer = EmptyTransformStream;
}
if (options.noPacketSplitter) {
client.splitter = EmptyTransformStream;
}
client.on('connect', onConnect);
client.once('success', onLogin);
client.once('compress', onCompressionRequest);
client.once('set_compression', onCompressionRequest);
if (keepAlive) client.on('keep_alive', onKeepAlive);
client.username = options.username;