startStream method

Future<CommandAck> startStream(
  1. DeviceCommand command
)

Implementation

Future<CommandAck> startStream(
  DeviceCommand command,
) async {
  var result = CommandAck(
    commandId: command.id,
    message: '[${command.type}]: unknown command type',
    success: false,
  );
  await _logSubscription?.cancel();
  _logSubscription = null;

  if (command is StartLogStreamCommand) {
    result = CommandAck(
      commandId: command.id,
      message: '[${command.type}]: starting log stream',
      success: true,
    );

    Logger.root.onRecord.listen((record) {
      if (_driver.state.driverName == null) {
        cancel();
      } else {
        if (record.level.value <= command.level.value) {
          final jrecord = JsonLogRecord.fromLogRecord(record);
          final response = LogResponse(record: jrecord);
          final ack = CommandAck(
            commandId: command.id,
            response: response,
          );
          _driver.communicator!.sendCommand(ack);
        }
      }
    });
  }

  return result;
}