Spaces:
Paused
Paused
Julian Bilcke
commited on
Commit
·
ef8ee9e
1
Parent(s):
59e0f6a
fix the localhost:8080 issue
Browse files- DEPLOYMENT.md +34 -1
- README.md +9 -0
- build/web/flutter_bootstrap.js +1 -1
- build/web/flutter_service_worker.js +2 -2
- build/web/main.dart.js +0 -0
- lib/services/websocket_api_service.dart +39 -3
DEPLOYMENT.md
CHANGED
|
@@ -72,7 +72,40 @@ PRODUCT_NAME="AiTube" \
|
|
| 72 |
### Run the client (web)
|
| 73 |
|
| 74 |
```bash
|
| 75 |
-
|
| 76 |
flutter run --dart-define=CONFIG_PATH=assets/config/aitube_low.yaml -d chrome
|
|
|
|
|
|
|
|
|
|
| 77 |
```
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
### Run the client (web)
|
| 73 |
|
| 74 |
```bash
|
| 75 |
+
# For local development with default configuration
|
| 76 |
flutter run --dart-define=CONFIG_PATH=assets/config/aitube_low.yaml -d chrome
|
| 77 |
+
|
| 78 |
+
# For production build to be deployed on a server
|
| 79 |
+
flutter build web --dart-define=CONFIG_PATH=assets/config/aitube_low.yaml
|
| 80 |
```
|
| 81 |
|
| 82 |
+
### WebSocket Connection
|
| 83 |
+
|
| 84 |
+
The application automatically determines the WebSocket URL:
|
| 85 |
+
|
| 86 |
+
1. **Web Platform**:
|
| 87 |
+
- Automatically uses the same host that serves the web app
|
| 88 |
+
- Handles HTTP/HTTPS protocol correctly (ws/wss)
|
| 89 |
+
- No configuration needed for deployment
|
| 90 |
+
|
| 91 |
+
2. **Native Platforms**:
|
| 92 |
+
- Production: Automatically uses `wss://aitube.at/ws` when built with production flag
|
| 93 |
+
- Development: Uses `ws://localhost:8080/ws` by default
|
| 94 |
+
- Custom: Can override with `API_WS_URL` environment variable (highest priority)
|
| 95 |
+
|
| 96 |
+
#### Production Native Build
|
| 97 |
+
|
| 98 |
+
For production builds (connecting to aitube.at):
|
| 99 |
+
```bash
|
| 100 |
+
flutter build apk --dart-define=CONFIG_PATH=assets/config/aitube_low.yaml --dart-define=PRODUCTION_MODE=true
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
#### Custom API Server
|
| 104 |
+
|
| 105 |
+
For connecting to a different server:
|
| 106 |
+
```bash
|
| 107 |
+
flutter build apk --dart-define=CONFIG_PATH=assets/config/aitube_low.yaml --dart-define=API_WS_URL=ws://custom-api.example.com/ws
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
Note: The `API_WS_URL` parameter takes precedence over the production setting.
|
| 111 |
+
|
README.md
CHANGED
|
@@ -18,6 +18,15 @@ hf_oauth_scopes:
|
|
| 18 |
|
| 19 |
# AiTube2
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
## News
|
| 22 |
|
| 23 |
aitube2 is coming sooner than expected!
|
|
|
|
| 18 |
|
| 19 |
# AiTube2
|
| 20 |
|
| 21 |
+
## Configuration
|
| 22 |
+
|
| 23 |
+
### WebSocket Connection
|
| 24 |
+
- **Web Platform**: Automatically connects to the host serving the page (adapts to both HTTP/HTTPS)
|
| 25 |
+
- **Native Platforms**:
|
| 26 |
+
- Production: Uses `wss://aitube.at/ws` when built with `--dart-define=PRODUCTION_MODE=true`
|
| 27 |
+
- Development: Uses `ws://localhost:8080/ws` by default
|
| 28 |
+
- Custom: Set `API_WS_URL` during build with `--dart-define=API_WS_URL=ws://your-server:port/ws` (highest priority)
|
| 29 |
+
|
| 30 |
## News
|
| 31 |
|
| 32 |
aitube2 is coming sooner than expected!
|
build/web/flutter_bootstrap.js
CHANGED
|
@@ -39,6 +39,6 @@ _flutter.buildConfig = {"engineRevision":"382be0028d370607f76215a9be322e5514b263
|
|
| 39 |
|
| 40 |
_flutter.loader.load({
|
| 41 |
serviceWorkerSettings: {
|
| 42 |
-
serviceWorkerVersion: "
|
| 43 |
}
|
| 44 |
});
|
|
|
|
| 39 |
|
| 40 |
_flutter.loader.load({
|
| 41 |
serviceWorkerSettings: {
|
| 42 |
+
serviceWorkerVersion: "1946662225"
|
| 43 |
}
|
| 44 |
});
|
build/web/flutter_service_worker.js
CHANGED
|
@@ -3,11 +3,11 @@ const MANIFEST = 'flutter-app-manifest';
|
|
| 3 |
const TEMP = 'flutter-temp-cache';
|
| 4 |
const CACHE_NAME = 'flutter-app-cache';
|
| 5 |
|
| 6 |
-
const RESOURCES = {"flutter_bootstrap.js": "
|
| 7 |
"version.json": "b5eaae4fc120710a3c35125322173615",
|
| 8 |
"index.html": "f34c56fffc6b38f62412a5db2315dec8",
|
| 9 |
"/": "f34c56fffc6b38f62412a5db2315dec8",
|
| 10 |
-
"main.dart.js": "
|
| 11 |
"flutter.js": "83d881c1dbb6d6bcd6b42e274605b69c",
|
| 12 |
"favicon.png": "5dcef449791fa27946b3d35ad8803796",
|
| 13 |
"icons/Icon-192.png": "ac9a721a12bbc803b44f645561ecb1e1",
|
|
|
|
| 3 |
const TEMP = 'flutter-temp-cache';
|
| 4 |
const CACHE_NAME = 'flutter-app-cache';
|
| 5 |
|
| 6 |
+
const RESOURCES = {"flutter_bootstrap.js": "73af8f030b3b05ff5d0df3ad67a75121",
|
| 7 |
"version.json": "b5eaae4fc120710a3c35125322173615",
|
| 8 |
"index.html": "f34c56fffc6b38f62412a5db2315dec8",
|
| 9 |
"/": "f34c56fffc6b38f62412a5db2315dec8",
|
| 10 |
+
"main.dart.js": "0085961ce9c20b57a5ddbe570d5024a2",
|
| 11 |
"flutter.js": "83d881c1dbb6d6bcd6b42e274605b69c",
|
| 12 |
"favicon.png": "5dcef449791fa27946b3d35ad8803796",
|
| 13 |
"icons/Icon-192.png": "ac9a721a12bbc803b44f645561ecb1e1",
|
build/web/main.dart.js
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
lib/services/websocket_api_service.dart
CHANGED
|
@@ -47,7 +47,40 @@ class WebSocketApiService {
|
|
| 47 |
factory WebSocketApiService() => _instance;
|
| 48 |
WebSocketApiService._internal();
|
| 49 |
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
WebSocketChannel? _channel;
|
| 52 |
final _responseController = StreamController<Map<String, dynamic>>.broadcast();
|
| 53 |
final _pendingRequests = <String, Completer<Map<String, dynamic>>>{};
|
|
@@ -162,10 +195,14 @@ class WebSocketApiService {
|
|
| 162 |
|
| 163 |
// First check if server is in maintenance mode by making an HTTP request to the status endpoint
|
| 164 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
// Use conditional import to handle platform differences
|
| 166 |
if (kIsWeb) {
|
| 167 |
// For web platform, use http package instead of HttpClient which is only available in dart:io
|
| 168 |
-
final httpUrl = 'http://${baseUrl.authority}/api/status';
|
| 169 |
final response = await http.get(Uri.parse(httpUrl));
|
| 170 |
|
| 171 |
if (response.statusCode == 200) {
|
|
@@ -179,7 +216,6 @@ class WebSocketApiService {
|
|
| 179 |
}
|
| 180 |
} else {
|
| 181 |
// For non-web platforms, use HttpClient from dart:io
|
| 182 |
-
final httpUrl = 'http://${baseUrl.authority}/api/status';
|
| 183 |
final httpClient = io.HttpClient();
|
| 184 |
final request = await httpClient.getUrl(Uri.parse(httpUrl));
|
| 185 |
final response = await request.close();
|
|
|
|
| 47 |
factory WebSocketApiService() => _instance;
|
| 48 |
WebSocketApiService._internal();
|
| 49 |
|
| 50 |
+
// Dynamically build WebSocket URL based on current host in web platform
|
| 51 |
+
// or use environment variable/production URL/localhost for development on other platforms
|
| 52 |
+
static String get _wsUrl {
|
| 53 |
+
if (kIsWeb) {
|
| 54 |
+
// Get the current host and protocol from the browser window
|
| 55 |
+
final location = Uri.base;
|
| 56 |
+
final protocol = location.scheme == 'https' ? 'wss' : 'ws';
|
| 57 |
+
final url = '$protocol://${location.host}/ws';
|
| 58 |
+
debugPrint('WebSocketApiService: Using dynamic WebSocket URL: $url');
|
| 59 |
+
return url;
|
| 60 |
+
} else {
|
| 61 |
+
// First try to get WebSocket URL from environment variable (highest priority)
|
| 62 |
+
const envWsUrl = String.fromEnvironment('API_WS_URL', defaultValue: '');
|
| 63 |
+
|
| 64 |
+
if (envWsUrl.isNotEmpty) {
|
| 65 |
+
debugPrint('WebSocketApiService: Using WebSocket URL from environment: $envWsUrl');
|
| 66 |
+
return envWsUrl;
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
// Second, check if we're in production mode (determined by build flag)
|
| 70 |
+
const isProduction = bool.fromEnvironment('PRODUCTION_MODE', defaultValue: false);
|
| 71 |
+
|
| 72 |
+
if (isProduction) {
|
| 73 |
+
// Production default is aitube.at
|
| 74 |
+
const productionUrl = 'wss://aitube.at/ws';
|
| 75 |
+
debugPrint('WebSocketApiService: Using production WebSocket URL: $productionUrl');
|
| 76 |
+
return productionUrl;
|
| 77 |
+
} else {
|
| 78 |
+
// Fallback to localhost for development
|
| 79 |
+
debugPrint('WebSocketApiService: Using default localhost WebSocket URL');
|
| 80 |
+
return 'ws://localhost:8080/ws';
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
WebSocketChannel? _channel;
|
| 85 |
final _responseController = StreamController<Map<String, dynamic>>.broadcast();
|
| 86 |
final _pendingRequests = <String, Completer<Map<String, dynamic>>>{};
|
|
|
|
| 195 |
|
| 196 |
// First check if server is in maintenance mode by making an HTTP request to the status endpoint
|
| 197 |
try {
|
| 198 |
+
// Determine HTTP URL based on WebSocket URL
|
| 199 |
+
final wsUri = Uri.parse(_wsUrl);
|
| 200 |
+
final protocol = wsUri.scheme == 'wss' ? 'https' : 'http';
|
| 201 |
+
final httpUrl = '$protocol://${wsUri.authority}/api/status';
|
| 202 |
+
|
| 203 |
// Use conditional import to handle platform differences
|
| 204 |
if (kIsWeb) {
|
| 205 |
// For web platform, use http package instead of HttpClient which is only available in dart:io
|
|
|
|
| 206 |
final response = await http.get(Uri.parse(httpUrl));
|
| 207 |
|
| 208 |
if (response.statusCode == 200) {
|
|
|
|
| 216 |
}
|
| 217 |
} else {
|
| 218 |
// For non-web platforms, use HttpClient from dart:io
|
|
|
|
| 219 |
final httpClient = io.HttpClient();
|
| 220 |
final request = await httpClient.getUrl(Uri.parse(httpUrl));
|
| 221 |
final response = await request.close();
|