actionhero
Version:
actionhero.js is a multi-transport API Server with integrated cluster capabilities and delayed tasks
83 lines (82 loc) • 3.96 kB
TypeScript
/**
* The generic representation of a connection for all server types is an Actionhero.Connection. You will never be creating these yourself via an action or task, but you will find them in your Actions and Action Middleware.
*/
export declare class Connection {
/**A unique string identifer for this connection. */
id: string;
/** A unique string identifer for this connection, but common among subsequent requests. For example, all web requests from the same client have the same fingerprint, but not the same id */
fingerprint: string;
/**The type of this connection (web, websocket, etc) as defined by the name of the server which created it */
type: string;
/**Any rooms this connection is a member of, it it can chat */
rooms: Array<string>;
/**Can this connection use the chat system? */
canChat: boolean;
/**Any params this connection has saved for use in subsequent Actions. */
params: ConnectionParams;
/**How many actions are currently running for this connection? Most server types have a limit */
pendingActions: number;
/**How many actions has this connection run since it connected. */
totalActions: number;
/**The Id of the latest message this connection has sent to the server. */
messageId: string;
/**The timestamp of when this connection was created */
connectedAt: number;
/**The remote connection's IP address (as best as we can tell). May be either IPv4 or IPv6. */
remoteIP: string;
/**The remote connection's port. Related to connection.remoteIP */
remotePort: number;
/**Any connection-specific properties. For, example, the HTTP res and req objects for `web` connections are here */
rawConnection: any;
/**If there's a local error */
error?: Error;
/**If there's a local extension to the request*/
extension?: string;
destroyed: boolean;
/** for specHelper */
messages?: Array<{
message: string;
[key: string]: any;
}>;
setHeader?: (key: string, value: string) => {};
setStatusCode?: (code: number) => {};
matchedRoute?: string;
pipe?: Function;
/**
* @param data The specifics of this connection
* @param callCreateMethods The specifics of this connection will calls create methods in the constructor. This property will exist for backward compatibility. If you want to construct connection and call create methods within async, you can use `await Actionhero.Connection.createAsync(details)` for construction.
*/
constructor(data: any, callCreateMethods?: boolean);
/**
* @param data The specifics of this connection
*/
static createAsync(data: any): Promise<Connection>;
private static callConnectionCreateMethods;
private setup;
/**
* Localize a key for this connection's locale. Keys usually look like `messages.errors.notFound`, and are defined in your locales directory. Strings can be interpolated as well, connection.localize('the count was {{count}}', {count: 4})
*/
localize(message: string): any;
/**
* Send a file to a connection (usually in the context of an Action). Be sure to set `data.toRender = false` in the action!
* Uses Server#processFile and will set `connection.params.file = path`
*/
sendFile(path: string): Promise<void>;
/**
* Send a message to a connection. Uses Server#sendMessage.
*/
sendMessage(message: string | object | Array<any>, verb?: string): Promise<void>;
private generateID;
/**
* Destroys the connection. If the type/sever of the connection has a goodbye message, it will be sent. The connection will be removed from all rooms. The connection's socket will be closed when possible.
*/
destroy(): Promise<void>;
private set;
/**
* Try to run a verb command for a connection
*/
private verbs;
}
export interface ConnectionParams {
[key: string]: any;
}