updateState method
Updates the state of a connection
Implementation
void updateState(TransportConn connection, ConnectionState newState,
{Object? error}) {
final currentState = _connections[connection];
if (currentState == null) {
throw StateError('Connection not registered with manager');
}
if (currentState == newState) {
return;
}
final stateChange = ConnectionStateChange(
previousState: currentState,
newState: newState,
error: error,
);
_connections[connection] = newState;
_stateControllers[connection]?.add(stateChange);
// 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);
}
}