import 'package:flutter/services.dart'; /// Bridge verso engine nativo Android (CameraX + RootEncoder). class StreamingChannel { StreamingChannel._(); static const MethodChannel _channel = MethodChannel('com.matchlivetv.match_live_tv/streaming'); static const EventChannel _metricsChannel = EventChannel('com.matchlivetv.match_live_tv/streaming_events'); static Future startPreview() async { await _channel.invokeMethod('startPreview'); } static Future bindPreview() async { final ok = await _channel.invokeMethod('bindPreview'); return ok ?? false; } static Future stopPreview() async { await _channel.invokeMethod('stopPreview'); } static Future startStream({ required String rtmpUrl, int targetBitrate = 2500000, int targetFps = 30, }) async { await _channel.invokeMethod('startStream', { 'rtmpUrl': rtmpUrl, 'videoBitrate': targetBitrate, 'fps': targetFps, }); } /// Ripresa dopo pausa: resetta stati RTMP residui (CONNECTING/RECONNECTING). static Future resumeStream({ required String rtmpUrl, int targetBitrate = 2500000, int targetFps = 30, }) async { await _channel.invokeMethod('resumeStream', { 'rtmpUrl': rtmpUrl, 'videoBitrate': targetBitrate, 'fps': targetFps, }); } static Future stopStream() async { await _channel.invokeMethod('stopStream'); } static Future pauseStream() async { await _channel.invokeMethod('pauseStream'); } static Future?> getMetrics() async { final result = await _channel.invokeMethod>('getMetrics'); return result?.map((key, value) => MapEntry(key.toString(), value)); } static EventChannel get metricsStream => _metricsChannel; }