Class Protocol<S, T>Abstract

A specification which defines Discord communication protocol used within DisConnection. It is used for implementing various transports, like WebSocket server or UNIX socket (IPC). This class is not designed to be used directly, but is meant to be extended by given transport implementation.

Type Parameters

  • S extends GenericServer

  • T extends string = string

Hierarchy

Constructors

  • Type Parameters

    • S extends GenericServer

    • T extends string = string

    Parameters

    • Optional serverGetter: [start: number, end: number, getter: ((port) => S)]
      Optional
    • cConsole: null | Console = console
    • Optional color: fgColor
      Optional

    Returns Protocol<S, T>

Properties

details?: Promise<ServerDetails<S>>
name: T

A name which indicates the given implementation of the protocol.

Accessors

  • get safeName(): sanitizeResult<T, "a-z", "_", "both">
  • A name variant which contains only English lowercase letters with other incompatible characters replaced with underscore (_).

    Returns sanitizeResult<T, "a-z", "_", "both">

Methods

  • Adds a hook to the given hook list if it doesn't exist in it.

    Type Parameters

    • T extends "INVITE_BROWSER" | "GUILD_TEMPLATE_BROWSER" | "AUTHORIZE" | "SET_ACTIVITY" | "DEEP_LINK_CHANNEL"

    Parameters

    • name: T

      A name of hook list.

    • value: HookFn<T>

      A function that will be added to hook list.

    Returns number | false

    number of hooks of given key or false if value were added before

    Throws

    TypeError on invalid function parameter types.

    Since

    v1.0.0

  • Whenever any of hooks will execute by server.

    Type Parameters

    • T extends "INVITE_BROWSER" | "GUILD_TEMPLATE_BROWSER" | "AUTHORIZE" | "SET_ACTIVITY" | "DEEP_LINK_CHANNEL"

    Parameters

    • name: T

      A name of hook list.

    Returns boolean

    whenever hooks are active

    Throws

    TypeError on invalid hook list name.

    Since

    v1.0.0

  • Writes a debug message, which will be visible whenever NODE_DEBUG includes a disconnection-{{@link #safeName}}.

    Parameters

    • Rest ...args: unknown[]
      Rest

    Returns void

  • Removes references in class properties and methods either by replacing values with a reference to the function that throws an error (for methods and some required properties using getters) or sets them to a nullish value (for optional properties).

    As it is hard to guarantee the Garbage Collector will ever deallocate memory after dereferencing all of the objects, the goal is to prevent API consumers from using class method that no longer make sense than implement any kind of the memory cleanup logic.

    Note: This operation is designed to be irreversible! You will have to initialize the new class instance if you want to use given transport again.

    Returns void

    Throws

    Error in case object has been already destroyed.

    Since

    v1.1.0

  • Writes an error message to stderr.

    Parameters

    • Rest ...args: unknown[]
      Rest

    Returns void

  • Lists all hooks from the given hook list.

    Type Parameters

    • T extends "INVITE_BROWSER" | "GUILD_TEMPLATE_BROWSER" | "AUTHORIZE" | "SET_ACTIVITY" | "DEEP_LINK_CHANNEL"

    Parameters

    • name: T

      A name of hook list.

    Returns HookFn<T>[]

    Array of hooks

    Throws

    TypeError on invalid hook list name.

    Since

    v1.0.0

  • Whenever this class has been destroyed.

    Returns boolean

    See

    destroy for more details about this state.

  • Writes a regular message (log) in the console to stdout.

    Parameters

    • Rest ...args: unknown[]
      Rest

    Returns void

  • Removes all hooks from the given hook list.

    Type Parameters

    • T extends "INVITE_BROWSER" | "GUILD_TEMPLATE_BROWSER" | "AUTHORIZE" | "SET_ACTIVITY" | "DEEP_LINK_CHANNEL"

    Parameters

    • name: T

      A name of hook list.

    Returns boolean

    if hook list wasn't empty before removing — values from it

    Throws

    TypeError on invalid hook list name.

    Since

    v1.0.0

  • Removes given hook function from the given hook list.

    Type Parameters

    • T extends "INVITE_BROWSER" | "GUILD_TEMPLATE_BROWSER" | "AUTHORIZE" | "SET_ACTIVITY" | "DEEP_LINK_CHANNEL"

    Parameters

    • name: T

      A name of hook list.

    • value: HookFn<T>

    Returns boolean

    whenever hook has been deleted

    Throws

    TypeError on invalid function parameter types.

    Since

    v1.0.0

  • Switches state of a given hook list, which can either disable it or not.

    Type Parameters

    • T extends "INVITE_BROWSER" | "GUILD_TEMPLATE_BROWSER" | "AUTHORIZE" | "SET_ACTIVITY" | "DEEP_LINK_CHANNEL"

    Parameters

    • name: T

      A name of hook list.

    • active: boolean = !this.#hooks[name].active

      New state of hooks. Defaults to negation of previous state.

    Returns boolean

    current state of given hook (i.e if it is active or not)

    Throws

    TypeError on invalid function parameter types.

    Since

    v1.0.0