import 'dart:async'; import 'dart:convert'; import 'dart:io'; Future main(List args) async { final host = args.isNotEmpty ? args[0] : '192.168.1.75'; final secs = args.length > 1 ? int.parse(args[1]) : 90; final ws = await WebSocket.connect('ws://$host:4444'); var id = 0; final pending = >>{}; final counts = {}; final samples = {}; ws.listen((raw) { final m = jsonDecode(raw as String) as Map; final rid = m['id']; if (rid is int && pending.containsKey(rid)) { pending.remove(rid)!.complete(m); return; } final n = m['notification'] as String?; if (n != null) { counts[n] = (counts[n] ?? 0) + 1; samples.putIfAbsent(n, () => jsonEncode(m['params'])); } }); Future> call(String meth, [Map p = const {}]) { final i = ++id; final c = Completer>(); pending[i] = c; ws.add(jsonEncode({'id': i, 'method': meth, 'params': p})); return c.future.timeout(const Duration(seconds: 15)); } await call('JSONRPC.Hello'); final r = await call('JSONRPC.SetNotificationStatus', {'enabled': true}); print('Namespaces abonnés: ${r['params']['namespaces']}'); print('Écoute ${secs}s…\n'); await Future.delayed(Duration(seconds: secs)); print('--- notifications reçues en ${secs}s ---'); final keys = counts.keys.toList()..sort(); for (final k in keys) { print('${counts[k]!.toString().padLeft(4)} $k'); } print('\n--- premier échantillon par type ---'); for (final k in keys) { var s = samples[k]!; if (s.length > 260) s = '${s.substring(0, 260)}…'; print('$k\n $s'); } await ws.close(); }