chore(mining-app): remove WebSocket debug logs
移除前端 WebSocket 相关的调试日志 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c05bcc9a76
commit
94153058d8
|
|
@ -1,5 +1,4 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:flutter/foundation.dart';
|
|
||||||
import 'package:socket_io_client/socket_io_client.dart' as IO;
|
import 'package:socket_io_client/socket_io_client.dart' as IO;
|
||||||
|
|
||||||
/// 价格更新数据
|
/// 价格更新数据
|
||||||
|
|
@ -75,8 +74,6 @@ class PriceWebSocketService {
|
||||||
///
|
///
|
||||||
/// [baseUrl] API 基础地址,例如 https://api.example.com
|
/// [baseUrl] API 基础地址,例如 https://api.example.com
|
||||||
void connect(String baseUrl) {
|
void connect(String baseUrl) {
|
||||||
debugPrint('[PriceWS] 🔌 connect() called with baseUrl: $baseUrl');
|
|
||||||
|
|
||||||
// 构建 WebSocket URL
|
// 构建 WebSocket URL
|
||||||
// https://api.example.com -> wss://api.example.com/ws/price
|
// https://api.example.com -> wss://api.example.com/ws/price
|
||||||
_wsUrl = baseUrl
|
_wsUrl = baseUrl
|
||||||
|
|
@ -84,8 +81,6 @@ class PriceWebSocketService {
|
||||||
.replaceFirst('http://', 'ws://');
|
.replaceFirst('http://', 'ws://');
|
||||||
_wsUrl = '$_wsUrl/ws/price';
|
_wsUrl = '$_wsUrl/ws/price';
|
||||||
|
|
||||||
debugPrint('[PriceWS] 🔌 Constructed WebSocket URL: $_wsUrl');
|
|
||||||
|
|
||||||
_doConnect();
|
_doConnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,7 +91,6 @@ class PriceWebSocketService {
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateStatus(WebSocketStatus.connecting);
|
_updateStatus(WebSocketStatus.connecting);
|
||||||
debugPrint('[PriceWS] Connecting to $_wsUrl');
|
|
||||||
|
|
||||||
_socket = IO.io(
|
_socket = IO.io(
|
||||||
_wsUrl,
|
_wsUrl,
|
||||||
|
|
@ -111,14 +105,12 @@ class PriceWebSocketService {
|
||||||
);
|
);
|
||||||
|
|
||||||
_socket!.onConnect((_) {
|
_socket!.onConnect((_) {
|
||||||
debugPrint('[PriceWS] ✅ Connected successfully to $_wsUrl');
|
|
||||||
_updateStatus(WebSocketStatus.connected);
|
_updateStatus(WebSocketStatus.connected);
|
||||||
_reconnectAttempts = 0;
|
_reconnectAttempts = 0;
|
||||||
_cancelReconnectTimer();
|
_cancelReconnectTimer();
|
||||||
});
|
});
|
||||||
|
|
||||||
_socket!.onDisconnect((reason) {
|
_socket!.onDisconnect((_) {
|
||||||
debugPrint('[PriceWS] ❌ Disconnected, reason: $reason');
|
|
||||||
_updateStatus(WebSocketStatus.disconnected);
|
_updateStatus(WebSocketStatus.disconnected);
|
||||||
// 如果不是主动断开,尝试重连
|
// 如果不是主动断开,尝试重连
|
||||||
if (_status != WebSocketStatus.disconnected) {
|
if (_status != WebSocketStatus.disconnected) {
|
||||||
|
|
@ -126,31 +118,26 @@ class PriceWebSocketService {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_socket!.onConnectError((error) {
|
_socket!.onConnectError((_) {
|
||||||
debugPrint('[PriceWS] ❌ Connect error: $error');
|
|
||||||
debugPrint('[PriceWS] URL was: $_wsUrl');
|
|
||||||
_updateStatus(WebSocketStatus.disconnected);
|
_updateStatus(WebSocketStatus.disconnected);
|
||||||
_scheduleReconnect();
|
_scheduleReconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
_socket!.onError((error) {
|
_socket!.onError((_) {
|
||||||
debugPrint('[PriceWS] ⚠️ Socket error: $error');
|
// 错误处理
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听连接超时
|
|
||||||
_socket!.onConnectTimeout((_) {
|
_socket!.onConnectTimeout((_) {
|
||||||
debugPrint('[PriceWS] ⏰ Connection timeout');
|
// 连接超时处理
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听价格更新事件
|
// 监听价格更新事件
|
||||||
_socket!.on('priceUpdate', (data) {
|
_socket!.on('priceUpdate', (data) {
|
||||||
try {
|
try {
|
||||||
debugPrint('[PriceWS] 📊 Received price update: $data');
|
|
||||||
final update = PriceUpdate.fromJson(data as Map<String, dynamic>);
|
final update = PriceUpdate.fromJson(data as Map<String, dynamic>);
|
||||||
debugPrint('[PriceWS] 📊 Parsed: price=${update.price}, burnMultiplier=${update.burnMultiplier}');
|
|
||||||
_priceUpdateController.add(update);
|
_priceUpdateController.add(update);
|
||||||
} catch (e) {
|
} catch (_) {
|
||||||
debugPrint('[PriceWS] ❌ Parse error: $e, data: $data');
|
// 解析错误处理
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -161,20 +148,16 @@ class PriceWebSocketService {
|
||||||
///
|
///
|
||||||
/// 调用此方法后不会自动重连
|
/// 调用此方法后不会自动重连
|
||||||
void disconnect() {
|
void disconnect() {
|
||||||
debugPrint('[PriceWS] 🔌 disconnect() called, current status: $_status');
|
|
||||||
_cancelReconnectTimer();
|
_cancelReconnectTimer();
|
||||||
_reconnectAttempts = 0;
|
_reconnectAttempts = 0;
|
||||||
|
|
||||||
if (_socket != null) {
|
if (_socket != null) {
|
||||||
debugPrint('[PriceWS] 🔌 Disposing socket...');
|
|
||||||
_socket!.disconnect();
|
_socket!.disconnect();
|
||||||
_socket!.dispose();
|
_socket!.dispose();
|
||||||
_socket = null;
|
_socket = null;
|
||||||
debugPrint('[PriceWS] 🔌 Socket disposed');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateStatus(WebSocketStatus.disconnected);
|
_updateStatus(WebSocketStatus.disconnected);
|
||||||
debugPrint('[PriceWS] 🔌 Disconnect complete');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 检查是否已连接
|
/// 检查是否已连接
|
||||||
|
|
@ -183,7 +166,6 @@ class PriceWebSocketService {
|
||||||
/// 安排重连
|
/// 安排重连
|
||||||
void _scheduleReconnect() {
|
void _scheduleReconnect() {
|
||||||
if (_reconnectAttempts >= _maxReconnectAttempts) {
|
if (_reconnectAttempts >= _maxReconnectAttempts) {
|
||||||
debugPrint('[PriceWS] Max reconnect attempts reached');
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,7 +182,6 @@ class PriceWebSocketService {
|
||||||
);
|
);
|
||||||
|
|
||||||
_reconnectAttempts++;
|
_reconnectAttempts++;
|
||||||
debugPrint('[PriceWS] Reconnect attempt $_reconnectAttempts in ${delay.inSeconds}s');
|
|
||||||
|
|
||||||
_reconnectTimer = Timer(delay, () {
|
_reconnectTimer = Timer(delay, () {
|
||||||
if (_status != WebSocketStatus.connected) {
|
if (_status != WebSocketStatus.connected) {
|
||||||
|
|
|
||||||
|
|
@ -48,15 +48,11 @@ class _AssetPageState extends ConsumerState<AssetPage> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
debugPrint('[AssetPage] 📱 initState - connecting WebSocket');
|
|
||||||
// 连接 WebSocket
|
|
||||||
_connectWebSocket();
|
_connectWebSocket();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
debugPrint('[AssetPage] 📱 dispose - disconnecting WebSocket');
|
|
||||||
// 断开 WebSocket
|
|
||||||
_disconnectWebSocket();
|
_disconnectWebSocket();
|
||||||
_refreshTimer?.cancel();
|
_refreshTimer?.cancel();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|
@ -64,33 +60,25 @@ class _AssetPageState extends ConsumerState<AssetPage> {
|
||||||
|
|
||||||
/// 连接 WebSocket
|
/// 连接 WebSocket
|
||||||
void _connectWebSocket() {
|
void _connectWebSocket() {
|
||||||
debugPrint('[AssetPage] 🔌 _connectWebSocket called');
|
|
||||||
final wsService = PriceWebSocketService.instance;
|
final wsService = PriceWebSocketService.instance;
|
||||||
// 使用 AppConstants 的 baseUrl
|
|
||||||
debugPrint('[AssetPage] 🔌 Using baseUrl: ${AppConstants.baseUrl}');
|
|
||||||
wsService.connect(AppConstants.baseUrl);
|
wsService.connect(AppConstants.baseUrl);
|
||||||
|
|
||||||
// 监听价格更新
|
// 监听价格更新
|
||||||
_priceSubscription = wsService.priceUpdates.listen((update) {
|
_priceSubscription = wsService.priceUpdates.listen((update) {
|
||||||
debugPrint('[AssetPage] 📊 Received price update: price=${update.price}, multiplier=${update.burnMultiplier}');
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_currentPrice = update.price;
|
_currentPrice = update.price;
|
||||||
_currentBurnMultiplier = update.burnMultiplier;
|
_currentBurnMultiplier = update.burnMultiplier;
|
||||||
});
|
});
|
||||||
debugPrint('[AssetPage] 📊 State updated: _currentPrice=$_currentPrice, _currentBurnMultiplier=$_currentBurnMultiplier');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
debugPrint('[AssetPage] 🔌 WebSocket listener attached');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 断开 WebSocket
|
/// 断开 WebSocket
|
||||||
void _disconnectWebSocket() {
|
void _disconnectWebSocket() {
|
||||||
debugPrint('[AssetPage] 🔌 _disconnectWebSocket called');
|
|
||||||
_priceSubscription?.cancel();
|
_priceSubscription?.cancel();
|
||||||
_priceSubscription = null;
|
_priceSubscription = null;
|
||||||
PriceWebSocketService.instance.disconnect();
|
PriceWebSocketService.instance.disconnect();
|
||||||
debugPrint('[AssetPage] 🔌 WebSocket disconnected');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 启动定时器(使用外部传入的每秒增长值)
|
/// 启动定时器(使用外部传入的每秒增长值)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue