Sync update: 2026-05-18 15:45:06

This commit is contained in:
Hamza-Ayed
2026-05-18 15:45:07 +03:00
parent 30d32df1c0
commit 82650b8c1f
141 changed files with 5255 additions and 24 deletions

View File

@@ -51,6 +51,7 @@ class WhatsAppService extends GetxService {
status.value = WsStatus.connecting;
_reconnectTimer?.cancel();
print('[WS] Attempting to connect to ${AppConfig.wsUrl}...');
try {
_channel = WebSocketChannel.connect(Uri.parse(AppConfig.wsUrl));
@@ -62,15 +63,18 @@ class WhatsAppService extends GetxService {
);
status.value = WsStatus.connected;
_reconnectCount = 0;
print('[WS] Connected successfully.');
// Request initial status check
ping();
} catch (e) {
print('[WS] Connection exception: $e');
_scheduleReconnect();
}
}
void _onData(dynamic raw) {
print('[WS RECV] $raw');
Map<String, dynamic> data;
try {
data = jsonDecode(raw as String);
@@ -127,10 +131,12 @@ class WhatsAppService extends GetxService {
}
void _onError(Object err) {
print('[WS ERROR] $err');
_handleDisconnect();
}
void _onDone() {
print('[WS DONE] Connection closed by server');
_handleDisconnect();
}
@@ -169,16 +175,18 @@ class WhatsAppService extends GetxService {
_pending[id] = completer;
try {
_channel?.sink.add(jsonEncode(payload));
final jsonMsg = jsonEncode(payload);
print('[WS SEND] $jsonMsg');
_channel?.sink.add(jsonMsg);
} catch (e) {
_pending.remove(id);
completer.completeError(e);
return completer.future;
}
// Timeout after 15s
// Timeout after 60s
return completer.future.timeout(
const Duration(seconds: 15),
const Duration(seconds: 60),
onTimeout: () {
_pending.remove(id);
throw TimeoutException('Request timed out: ${payload['type']}');
@@ -204,6 +212,9 @@ class WhatsAppService extends GetxService {
Future<Map<String, dynamic>> searchConversations(String query) =>
_request({ 'type': 'search_conversations', 'query': query });
Future<Map<String, dynamic>> sendFcmToken(String token) =>
_request({ 'type': 'register_fcm', 'token': token });
Future<Map<String, dynamic>> ping() =>
_request({ 'type': 'ping' });
}