Flow Studio
Establishing Connection
The useExecutionSignalR hook manages the full lifecycle of the SignalR WebSocket connection — building it, authenticating, subscribing to the execution group, and tearing it down when the execution ends or the component unmounts.
useExecutionSignalR
// useExecutionSignalR.ts (simplified)
export function useExecutionSignalR(executionId: string) {
const connectionRef = useRef<HubConnection | null>(null);
useEffect(() => {
const connection = new HubConnectionBuilder()
.withUrl('/hubs/execution', {
accessTokenFactory: () => getAuthToken() // JWT
})
.withAutomaticReconnect([1000, 2000, 5000, 10000])
.build();
connection.start().then(() => {
connection.invoke('JoinExecution', executionId);
});
// Register event handlers
connection.on('NodeExecutionStarted', handleNodeStarted);
connection.on('NodeExecutionCompleted', handleNodeCompleted);
connection.on('NodeExecutionFailed', handleNodeFailed);
connection.on('WorkflowExecutionCompleted', handleWorkflowCompleted);
connectionRef.current = connection;
// Cleanup on unmount or executionId change
return () => {
connection.invoke('LeaveExecution', executionId);
connection.stop();
};
}, [executionId]);
}
Authentication
The SignalR connection includes the user's JWT bearer token via the accessTokenFactory. The backend hub validates the token on connection. If the token expires during a long execution, SignalR automatically reconnects with a fresh token.
Hub URL and Transport
| Setting | Value |
|---|---|
| Hub URL | /hubs/execution |
| Preferred transport | WebSocket |
| Fallback transports | Server-Sent Events, then Long-Polling |
| Reconnect delays | 1s, 2s, 5s, 10s (then gives up and falls back to polling) |
Connection States
| State | Meaning | UI Indicator |
|---|---|---|
| Connecting | WebSocket handshake in progress | Spinner in Observer Panel header |
| Connected | WebSocket open and subscribed | Green dot in Observer Panel header |
| Reconnecting | Connection lost; attempting to restore | Amber dot + "Reconnecting..." |
| Disconnected | Connection lost permanently; polling fallback active | Red dot + "Live updates unavailable" |