feat: discovery automático + QR como fallback en PantallaUnirse
All checks were successful
Build & Deploy Farolero / Análisis de código (push) Successful in 9s
Build & Deploy Farolero / Build APK + AAB release (push) Successful in 1m7s

- Discovery: busca hosts cercanos automáticamente y los muestra en lista
- Cada host aparece como tile tocable con nombre de la sala
- QR fallback: botón 'Escanear QR' debajo de la lista
- ServicioNearby: hostsEncontrados map, pararBusqueda(), no auto-connect
- Flujo: nombre → buscar → lista de salas (o QR) → conectar → espera
- l10n: searchGames, searchingGames, noGamesFound, orScanQR (es/en)
This commit is contained in:
ShanaiaBot
2026-04-04 03:20:32 +02:00
parent 6428667e11
commit 757344ca48
22 changed files with 732 additions and 133 deletions

View File

@@ -71,6 +71,9 @@ class ServicioNearby extends ChangeNotifier {
final Map<String, JugadorConectado> _jugadores = {};
final List<OnMensajeCallback> _listeners = [];
// Hosts descubiertos (para discovery automático)
final Map<String, String> _hostsEncontrados = {}; // endpointId -> nombre
// Estado para clientes
String? _palabraRecibida;
bool? _soyImpostor;
@@ -92,6 +95,7 @@ class ServicioNearby extends ChangeNotifier {
List<JugadorConectado> get jugadores => _jugadores.values.toList();
int get numJugadoresConectados => _jugadores.length;
Map<String, String> get hostsEncontrados => Map.unmodifiable(_hostsEncontrados);
/// Registra un listener de mensajes
void onMensaje(OnMensajeCallback callback) {
@@ -239,12 +243,26 @@ class ServicioNearby extends ChangeNotifier {
void _onEndpointEncontrado(String endpointId, String endpointName, String serviceId) {
debugPrint('Host encontrado: $endpointName ($endpointId)');
// Auto-conectar al primer host encontrado
conectarAHost(endpointId, _miNombre ?? 'Jugador');
_hostsEncontrados[endpointId] = endpointName;
notifyListeners();
}
void _onEndpointPerdido(String? endpointId) {
debugPrint('Endpoint perdido: $endpointId');
if (endpointId != null) {
_hostsEncontrados.remove(endpointId);
notifyListeners();
}
}
/// Para el discovery sin desconectar
Future<void> pararBusqueda() async {
try {
await Nearby().stopDiscovery();
} catch (_) {}
_buscando = false;
_hostsEncontrados.clear();
notifyListeners();
}
void _onPayloadRecibido(String endpointId, Payload payload) {
@@ -443,6 +461,7 @@ class ServicioNearby extends ChangeNotifier {
_faseActual = null;
_datosPartida = null;
_jugadores.clear();
_hostsEncontrados.clear();
notifyListeners();
}