feat: Integrate WebView players with API server and add comprehensive mock tests

WebView Player Integration:
- Create PlayerEmbedService for API server integration
- Update WebView players to use server embed URLs instead of direct links
- Add fallback to direct URLs when server is unavailable
- Support for both Vibix and Alloha players with server API
- Include optional parameters (imdbId, season, episode) for TV shows
- Add health check endpoint for server availability

Mock Testing Infrastructure:
- Add comprehensive TorrentPlatformService tests with mock platform channel
- Test all torrent operations without requiring real Android engine
- Mock platform channel responses for addTorrent, removeTorrent, pauseTorrent, resumeTorrent
- Test error handling with PlatformException simulation
- Validate torrent state detection (downloading, seeding, completed)
- Test file priority management and video file detection

PlayerEmbedService Testing:
- Mock HTTP client tests for Vibix and Alloha embed URL generation
- Test server API integration with success and failure scenarios
- Validate URL encoding for special characters and non-ASCII titles
- Test fallback behavior when server is unavailable or times out
- Mock player configuration retrieval from server
- Test server health check functionality

Test Dependencies:
- Add http_mock_adapter for HTTP testing
- Ensure all tests work without real Flutter/Android environment
- Support for testing platform channels and HTTP services

This enables proper API server integration for WebView players
while maintaining comprehensive test coverage for all torrent
and player functionality without requiring Android hardware.
This commit is contained in:
factory-droid[bot]
2025-10-03 07:16:44 +00:00
parent 39f311d02e
commit 3e1a9768d8
5 changed files with 891 additions and 18 deletions

View File

@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:auto_route/auto_route.dart';
import '../../../data/services/player_embed_service.dart';
enum WebPlayerType { vibix, alloha }
@@ -71,30 +72,58 @@ class _WebViewPlayerScreenState extends State<WebViewPlayerScreen> {
_loadPlayer();
}
void _loadPlayer() {
final playerUrl = _getPlayerUrl();
_controller.loadRequest(Uri.parse(playerUrl));
}
void _loadPlayer() async {
try {
setState(() {
_isLoading = true;
_error = null;
});
String _getPlayerUrl() {
switch (widget.playerType) {
case WebPlayerType.vibix:
return _getVibixUrl();
case WebPlayerType.alloha:
return _getAllohaUrl();
final playerUrl = await _getPlayerUrl();
_controller.loadRequest(Uri.parse(playerUrl));
} catch (e) {
setState(() {
_error = 'Ошибка получения URL плеера: $e';
_isLoading = false;
});
}
}
String _getVibixUrl() {
// Vibix player URL with embedded video
final encodedVideoUrl = Uri.encodeComponent(widget.videoUrl);
return 'https://vibix.me/embed/?src=$encodedVideoUrl&autoplay=1&title=${Uri.encodeComponent(widget.title)}';
Future<String> _getPlayerUrl() async {
switch (widget.playerType) {
case WebPlayerType.vibix:
return await _getVibixUrl();
case WebPlayerType.alloha:
return await _getAllohaUrl();
}
}
String _getAllohaUrl() {
// Alloha player URL with embedded video
final encodedVideoUrl = Uri.encodeComponent(widget.videoUrl);
return 'https://alloha.tv/embed?src=$encodedVideoUrl&autoplay=1&title=${Uri.encodeComponent(widget.title)}';
Future<String> _getVibixUrl() async {
try {
// Try to get embed URL from API server first
return await PlayerEmbedService.getVibixEmbedUrl(
videoUrl: widget.videoUrl,
title: widget.title,
);
} catch (e) {
// Fallback to direct URL if server is unavailable
final encodedVideoUrl = Uri.encodeComponent(widget.videoUrl);
return 'https://vibix.me/embed/?src=$encodedVideoUrl&autoplay=1&title=${Uri.encodeComponent(widget.title)}';
}
}
Future<String> _getAllohaUrl() async {
try {
// Try to get embed URL from API server first
return await PlayerEmbedService.getAllohaEmbedUrl(
videoUrl: widget.videoUrl,
title: widget.title,
);
} catch (e) {
// Fallback to direct URL if server is unavailable
final encodedVideoUrl = Uri.encodeComponent(widget.videoUrl);
return 'https://alloha.tv/embed?src=$encodedVideoUrl&autoplay=1&title=${Uri.encodeComponent(widget.title)}';
}
}
void _toggleFullscreen() {