updateState method
Updates the state of a connection
Implementation
void updateState(TransportConn connection, ConnectionState newState, {Object? error}) {
print('Updating state for connection: $connection to $newState');
final currentState = _connections[connection];
if (currentState == null) {
print('Connection not found in manager: $connection');
print('Current connections: ${_connections.keys.join(', ')}');
throw StateError('Connection not registered with manager');
}
if (currentState == newState) {
print('State unchanged: $currentState');
return;
}
final stateChange = ConnectionStateChange(
previousState: currentState,
newState: newState,
error: error,
);
_connections[connection] = newState;
_stateControllers[connection]?.add(stateChange);
print('State updated: $currentState -> $newState');
// Update last activity timestamp for state changes
if (newState == ConnectionState.active) {
_updateActivityTimestamp(connection);
}
// Handle terminal states
if (newState == ConnectionState.closed || newState == ConnectionState.error) {
_cleanupConnection(connection);
}
}