Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AkeraConnection

This is used to establish a connection to an akera.io application server in order to exchange messages using a specific exchange protocol.

Hierarchy

  • EventEmitter
    • AkeraConnection

Index

Constructors

constructor

  • new AkeraConnection(streamIn: Duplex, pipe?: boolean | Writable, autoClose?: boolean): AkeraConnection
  • Creates a Connection as a wrapper over a socket connection established to the akera.io application server.

    constructor

    Parameters

    • streamIn: Duplex

      The input stream.

    • Optional pipe: boolean | Writable

      The optional writable stream to pipe data to.

    • Optional autoClose: boolean

    Returns AkeraConnection

Properties

autoClose

autoClose: boolean = true

Static defaultMaxListeners

defaultMaxListeners: number

Accessors

logger

  • Sets the logger for this connection.

    memberof

    Connection

    Parameters

    • logger: AkeraLogger

      The logger instance that will be used by the connection.

    Returns void

Static logger

  • Sets the 'default' logger for all new connections.

    static
    memberof

    Connection

    Parameters

    Returns void

Methods

addListener

  • addListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

address

  • address(): string | AddressInfo
  • Returns the address of this connection

    Returns string | AddressInfo

    The address of the input open stream.

close

  • close(timeout?: number): Promise<void>
  • Closes the connection by closing the open socket stream, if already closed this is a no-op.

    Parameters

    • Optional timeout: number

    Returns Promise<void>

    A promise that is resolved when connection is closed or rejected in case of error.

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

enable

  • enable(): boolean
  • Enables the data handler on the open stream to start reading messages. If the connection is paused this just resumes reading.

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

getMaxListeners

  • getMaxListeners(): number
  • Returns number

isClosed

  • isClosed(): boolean
  • Check whether the connection is allready closed or not.

    Returns boolean

listenerCount

  • listenerCount(type: string | symbol): number
  • Parameters

    • type: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

off

  • off(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

onData

  • onData(handler: function): void
  • Add a listener for the DATA event. The handler function need to receive one parameter of type Buffer.

    Parameters

    • handler: function
        • (Buffer: any): void
        • Parameters

          • Buffer: any

          Returns void

    Returns void

onDone

  • onDone(handler: function): void
  • Add a listener for the DONE event. Only fired when received a message of type DONE.

    Parameters

    • handler: function
        • (): void
        • Returns void

    Returns void

onError

  • onError(handler: function): void
  • Add a listener for the ERROR event. The handler function needs to receive one parameter of type Error.

    Parameters

    • handler: function
        • (Error: any): void
        • Parameters

          • Error: any

          Returns void

    Returns void

onMessage

  • onMessage(handler: function): void
  • Add a listener for the MESSAGE event, fired when a complete message is received.

    The handler function will receive the complete message as input.

    Parameters

    • handler: function
        • (AkeraMessage: any): void
        • Parameters

          • AkeraMessage: any

          Returns void

    Returns void

onTimeout

  • onTimeout(handler: function): void
  • Add a listener for the TIMEOUT event on open stream (only if {Socket}).

    Parameters

    • handler: function
        • (): void
        • Returns void

    Returns void

once

  • once(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

pause

  • pause(): void
  • Pauses the reading on the open stream, that's it no messages will be processed until resumed.

    Returns void

pipe

  • pipe(writable: Writable): void
  • Pipe all data read from input stream to the given pipe (passthrough).

    Parameters

    • writable: Writable

      The writable stream where data received on the open stream are to be pipe to.

    Returns void

prependListener

  • prependListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

resume

  • resume(): void
  • Resumes reading on the open stream.

    Returns void

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

setTimeout

  • setTimeout(timeout: number, callback: function): void
  • Sets a timeout on the open stream, the callback function will be called if the time elapse while no data is received through the open stream.

    Parameters

    • timeout: number

      The time out period in milliseconds.

    • callback: function

      The callback function to be called when/if time elapse.

        • (): void
        • Returns void

    Returns void

unpipe

  • unpipe(): void
  • Stop sending data from the input stream to the previous 'pipe' stream if any.

    Returns void

write

  • Write a message through the open connection stream. Returns a promise that will be resolved when message is written in full or rejected in case of error.

    Parameters

    • message: AkeraMessage

      The message to write to the open stream.

    Returns Promise<void>

Static connect

  • Establish a connection (socket) to an akera.io application server (host, port). Returns a promise that is either rejected in case of error or resolves with a AkeraConnection.

    static

    Parameters

    • host: string | ConnectInfo

      It can be either a string with the host name/address or a complete connect info.

    • Optional port: number

      The server port number, unless the first parameter is a ConnectInfo.

    • Optional ssl: boolean | ConnectionOptions

      The SSL options, unless the first parameter is a ConnectInfo.

    Returns Promise<AkeraConnection>

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number