Only show own activity in last activity
This commit is contained in:
@@ -15,8 +15,14 @@ class LastHeardWebSocketClient {
|
||||
static const int _maxReconnectAttempts = 5;
|
||||
static const Duration _reconnectDelay = Duration(seconds: 5);
|
||||
|
||||
final List<int>? _radioIds;
|
||||
int _receivedCount = 0;
|
||||
static const int _maxItems = 200;
|
||||
|
||||
final Completer<void> _readyCompleter = Completer<void>();
|
||||
|
||||
LastHeardWebSocketClient({List<int>? radioIds}) : _radioIds = radioIds;
|
||||
|
||||
// Socket.IO Engine.IO v4 WebSocket URL for Last Heard
|
||||
static const String _wsUrl =
|
||||
'wss://api.brandmeister.network/lh/?EIO=4&transport=websocket';
|
||||
@@ -37,7 +43,8 @@ class LastHeardWebSocketClient {
|
||||
}
|
||||
|
||||
_isConnecting = true;
|
||||
_shouldReconnect = true;
|
||||
// Don't reconnect if radio IDs are supplied (one-time search query)
|
||||
_shouldReconnect = _radioIds == null || _radioIds.isEmpty;
|
||||
|
||||
try {
|
||||
debugPrint('LastHeard WS: Connecting to $_wsUrl');
|
||||
@@ -71,7 +78,7 @@ class LastHeardWebSocketClient {
|
||||
_handleOpenPacket(messageStr);
|
||||
} else if (messageStr.startsWith('2')) {
|
||||
_sendPong();
|
||||
} else if (messageStr == '40') {
|
||||
} else if (messageStr.startsWith('40')) {
|
||||
_handleNamespaceConnect();
|
||||
} else if (messageStr.startsWith('42')) {
|
||||
_handleDataPacket(messageStr);
|
||||
@@ -133,11 +140,20 @@ class LastHeardWebSocketClient {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_radioIds == null || _radioIds.isEmpty) {
|
||||
debugPrint('LastHeard WS: No radio IDs provided, skipping search query');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Build SQL query for multiple radio IDs: SourceID = 123 OR SourceID = 456
|
||||
final sqlParts = _radioIds.map((id) => 'SourceID = $id').toList();
|
||||
final sql = sqlParts.join(' OR ');
|
||||
|
||||
final message = '42${jsonEncode([
|
||||
'searchMongo',
|
||||
{
|
||||
'query': {'sql': ''},
|
||||
'query': {'sql': sql},
|
||||
'amount': 200
|
||||
}
|
||||
])}';
|
||||
@@ -180,6 +196,15 @@ class LastHeardWebSocketClient {
|
||||
_messageController != null &&
|
||||
!_messageController!.isClosed) {
|
||||
_messageController!.add(eventData);
|
||||
|
||||
// Track received items and disconnect after receiving max items (for search queries)
|
||||
if (_radioIds != null && _radioIds.isNotEmpty) {
|
||||
_receivedCount++;
|
||||
if (_receivedCount >= _maxItems) {
|
||||
debugPrint('LastHeard WS: Received $_maxItems items, disconnecting');
|
||||
disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('LastHeard WS: Error parsing data packet: $e');
|
||||
|
||||
Reference in New Issue
Block a user