IOServer constructor

IOServer({
  1. bool debug = false,
  2. bool https = false,
  3. String? pathToPem,
  4. String? pathToRsa,
  5. int port = defaultGamePort,
})

Implementation

IOServer({
  this.debug = false,
  this.https = false,
  String? pathToPem,
  String? pathToRsa,
  int port = defaultGamePort,
}) {
  final server = StreamServer();
  if (https) {
    assert(pathToPem != null, 'Https requires pathToPem');
    assert(pathToRsa != null, 'Https requires pathToRsa');

    final security = SecurityContext()
      ..useCertificateChain(pathToPem!)
      ..usePrivateKey(pathToRsa!);
    server.startSecure(security,
        address: InternetAddress.anyIPv4, port: port);
  } else {
    server.start(address: InternetAddress.loopbackIPv4, port: port);
  }
  io.listen(server, _serverSocketOpts);
  io.on(
    IOChannel.connection.string,
    (c) => _handleClientConnection(c as IO.Socket),
  );
  Logger.root.clearListeners();
  Logger.root.level = Level.FINE; // defaults to Level.INFO
  Logger.root.onRecord.listen((record) {
    if (record.loggerName.startsWith('socket_io')) {
      return;
    }
    // ignore: avoid_print
    print('[${record.level.name}]: ${record.loggerName} ${record.message}');
  });
}