webssh2-server
Version:
A Websocket to SSH2 gateway using xterm.js, socket.io, ssh2
75 lines (74 loc) • 1.91 kB
TypeScript
/**
* Centralized state store for session management
*/
import type { SessionId } from '../types/branded.js';
import type { SessionState, StateListener } from './types.js';
import type { SessionAction } from './actions.js';
/**
* Session state store with subscription mechanism
*/
export declare class SessionStore {
private readonly states;
private readonly listeners;
private readonly actionHistory;
private readonly maxHistorySize;
constructor(options?: {
maxHistorySize?: number;
});
/**
* Create a new session with initial state
*/
createSession(sessionId: SessionId): SessionState;
/**
* Get current state for a session
*/
getState(sessionId: SessionId): SessionState | undefined;
/**
* Get all active session IDs
*/
getSessionIds(): SessionId[];
/**
* Dispatch an action to update session state
*/
dispatch(sessionId: SessionId, action: SessionAction): void;
/**
* Subscribe to state changes for a session
*/
subscribe(sessionId: SessionId, listener: StateListener): () => void;
/**
* Remove a session and clean up resources
*/
removeSession(sessionId: SessionId): void;
/**
* Get action history for debugging
*/
getActionHistory(sessionId: SessionId): SessionAction[];
/**
* Clear all sessions (for testing)
*/
clear(): void;
/**
* Get store statistics
*/
getStats(): {
sessionCount: number;
listenerCount: number;
totalActions: number;
};
/**
* Notify listeners of state change
*/
private notifyListeners;
/**
* Record action in history
*/
private recordAction;
}
/**
* Get singleton store instance
*/
export declare const getStore: () => SessionStore;
/**
* Reset store (for testing)
*/
export declare const resetStore: () => void;