How to use the minecraft-protocol/src.Client function in minecraft-protocol

To help you get started, we’ve selected a few minecraft-protocol examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github deathcap / wsmc / minecraft-protocol-stream.js View on Github external
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;