toggleVideo method

Future<void> toggleVideo()

Toggle video on/off

Implementation

Future<void> toggleVideo() async {
  if (_room == null || !_isConnected) {
    debugPrint(
      '[BaxcloudLiveStreamingSeats] Cannot toggle video: not connected',
    );
    return;
  }

  if (_isVideoEnabled) {
    // Turn video off
    if (_localVideoTrack != null) {
      await _localVideoTrack!.mute();
    }
    _isVideoEnabled = false;
  } else {
    // Turn video on
    if (_localVideoTrack == null) {
      // Create and publish video track if it doesn't exist
      try {
        await startPublishing(
          enableVideo: true,
          enableAudio: _isAudioEnabled,
        );
      } catch (e) {
        debugPrint('[BaxcloudLiveStreamingSeats] Error enabling video: $e');
        rethrow;
      }
    } else {
      // Unmute existing track
      await _localVideoTrack!.unmute();
      _isVideoEnabled = true;
    }
  }
  notifyListeners();
}