run method

  1. @override
void run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
void run() async {
  Loggy.initLoggy(
    logPrinter: const PrettyPrinter(showColors: false),
    logOptions: OnvifUtil.convertToLogOptions(globalResults!['log-level']),
  );

  final server = await serve(
    DevicesController().handler,
    argResults!['bind-ip'],
    int.parse(argResults!['port']),
  );

  // TODO: send `hello` to all devices
  // loggy.info('Sending WS-Discovery HELLO message...');
  // await multicastProbe.sendHello();

  ProcessSignal.sigint.watch().listen((_) async {
    print('Shutting down...');

    // TODO: send `bye` to all devices

    await server.close();

    exit(0);
  });

  if (argResults!['bind-ip'] == _defaultIp) {
    final interfaces = await NetworkInterface.list();

    for (var interface in interfaces) {
      for (var addr in interface.addresses) {
        loggy.info('Serving at http://${addr.address}:${server.port}');
      }
    }
  } else {
    loggy.info('Serving at http://${server.address.host}:${server.port}');
  }
}