Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Connection

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.

Hierarchy

  • Connection

Index

Constructors

constructor

  • new Connection(data: any, callCreateMethods?: boolean): Connection
  • Parameters

    • data: any

      The specifics of this connection

    • Default value callCreateMethods: boolean = true

      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.

    Returns Connection

Properties

canChat

canChat: boolean

Can this connection use the chat system?

connectedAt

connectedAt: number

The timestamp of when this connection was created

destroyed

destroyed: boolean

Optional error

error: Error

If there's a local error

Optional extension

extension: string

If there's a local extension to the request

fingerprint

fingerprint: 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

id

id: string

A unique string identifer for this connection.

messageId

messageId: string

The Id of the latest message this connection has sent to the server.

params

Any params this connection has saved for use in subsequent Actions.

pendingActions

pendingActions: number

How many actions are currently running for this connection? Most server types have a limit

rawConnection

rawConnection: any

Any connection-specific properties. For, example, the HTTP res and req objects for web connections are here

remoteIP

remoteIP: string

The remote connection's IP address (as best as we can tell). May be either IPv4 or IPv6.

remotePort

remotePort: number

The remote connection's port. Related to connection.remoteIP

rooms

rooms: Array<string>

Any rooms this connection is a member of, it it can chat

totalActions

totalActions: number

How many actions has this connection run since it connected.

type

type: string

The type of this connection (web, websocket, etc) as defined by the name of the server which created it

Methods

destroy

  • destroy(): Promise<void>
  • 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.

    Returns Promise<void>

Private generateID

  • generateID(): string

localize

  • localize(message: string): any
  • 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})

    Parameters

    • message: string

    Returns any

sendFile

  • sendFile(path: string): Promise<void>
  • 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

    Parameters

    • path: string

    Returns Promise<void>

sendMessage

  • sendMessage(message: string | object | Array<any>, verb?: string): Promise<void>
  • Send a message to a connection. Uses Server#sendMessage.

    Parameters

    • message: string | object | Array<any>
    • Optional verb: string

    Returns Promise<void>

Private set

  • set(key: any, value: any): void

Private setup

  • setup(data: any): void

Private verbs

  • verbs(verb: string, words: Array<string>): Promise<any>
  • Try to run a verb command for a connection

    Parameters

    • verb: string
    • words: Array<string>

    Returns Promise<any>

Static Private callConnectionCreateMethods

  • callConnectionCreateMethods(connection: Connection): Promise<void>

Static createAsync

Generated using TypeDoc