import { IncomingMessage } from 'http';
import { BaseMessage, HandlerRequestData, InvokePrefixes, ISrpcServerOptions, RequestData, ResponseData, SrpcDisconnectCause, SrpcMeta, SrpcStream, TSrpcMessageHandlerFnOrClass } from './types';
export declare class SrpcServer<TMeta extends SrpcMeta = SrpcMeta, TClientOutput extends BaseMessage = BaseMessage, TServerOutput extends BaseMessage = BaseMessage> {
    private options;
    private standardSrpcAuthKey?;
    private authClockDriftMs;
    private useRealIpHeader;
    private logger;
    private wsServer;
    private httpServer;
    private inboundType;
    private outboundType;
    private clientAuthorizer?;
    private clientKeyFetcher?;
    private streamConnectionHandlers;
    private blockedClientRequests;
    private pendingClientRequests;
    private streamMessageHandlers;
    private streamDisconnectionHandlers;
    private inactivityCheckInterval;
    readonly streamsById: Map<string, SrpcStream<TMeta>>;
    readonly streamsByClientId: Map<string, SrpcStream<TMeta>>;
    protected readonly pendingStreamsByClientId: Map<string, SrpcStream<TMeta>>;
    constructor(options: ISrpcServerOptions<TClientOutput, TServerOutput>);
    private verifyClient;
    private attachConnection;
    private handleWsMessage;
    private write;
    private writeToStream;
    protected getCurrentStreamByClientId(clientId: string): SrpcStream<TMeta> | undefined;
    protected isCurrentStream(stream: SrpcStream<TMeta>): boolean;
    private activateStream;
    private static readonly CLOSE_CODES;
    private closeStreamWithError;
    private validateClientAuth;
    private fetchClientKey;
    setClientAuthorizer(authorizer: (metadata: SrpcMeta, req: IncomingMessage) => Promise<boolean | SrpcMeta>): void;
    setClientKeyFetcher(fetcher: (clientId: string) => Promise<false | string>): void;
    close(): void;
    private handleStreamEstablished;
    /**
     * Async hook called after a stream is registered in local maps but before
     * the initial handshake ping is sent. Return true to reject the stream;
     * the subclass must call cleanupStream() before returning true. The base
     * implementation accepts all streams immediately.
     */
    protected postEstablishCheck(_stream: SrpcStream<TMeta>): Promise<boolean>;
    private handleStreamDisconnected;
    private handleStreamError;
    private terminateInactiveStreams;
    protected cleanupStream(stream: SrpcStream<TMeta>, forceCause?: SrpcDisconnectCause): void;
    private handleStreamDataReceived;
    private handleByteSubstreamOperation;
    private handleClientRequest;
    private openClientRequests;
    protected runMessageHandler(handler: TSrpcMessageHandlerFnOrClass<SrpcStream<TMeta>, any, any>, stream: SrpcStream<TMeta>, data: any): Promise<any>;
    protected onStreamConnected(stream: SrpcStream<TMeta>): Promise<void>;
    protected onStreamActivated(_stream: SrpcStream<TMeta>): void | Promise<void>;
    protected onStreamDisconnected(stream: SrpcStream<TMeta>, cause: SrpcDisconnectCause): void;
    /**
     * Register a handler that runs after the initial handshake ping is sent.
     * Throwing or rejecting aborts activation and disconnects the stream.
     */
    registerConnectionHandler(handler: (stream: SrpcStream<TMeta>) => void | Promise<void>): void;
    /**
     * Register a handler for client requests.
     * @example server.registerMessageHandler('uEcho', async (stream, data) => ({ message: `Echo: ${data.message}` }))
     */
    registerMessageHandler<P extends InvokePrefixes<TClientOutput, TServerOutput>>(prefix: P, handler: TSrpcMessageHandlerFnOrClass<SrpcStream<TMeta>, HandlerRequestData<TClientOutput, P>, ResponseData<TServerOutput, P>>): void;
    registerDisconnectHandler(handler: (stream: SrpcStream<TMeta>, cause: SrpcDisconnectCause) => void): void;
    /**
     * Invoke a client method.
     * @example server.invoke(stream, 'dNotify', { notification: 'hello' })
     */
    invoke<P extends InvokePrefixes<TServerOutput, TClientOutput>>(stream: SrpcStream<TMeta>, prefix: P, data: RequestData<TServerOutput, P>, timeoutMs?: number): Promise<ResponseData<TClientOutput, P>>;
    static createInvoke<TM extends SrpcMeta, TCO extends BaseMessage, TSO extends BaseMessage>(instanceFn: () => SrpcServer<TM, TCO, TSO>): SrpcServer<TM, TCO, TSO>['invoke'];
}
//# sourceMappingURL=SrpcServer.d.ts.map