Skip to content

Connection

dysolix edited this page Apr 8, 2024 · 3 revisions

Connect Function Documentation

Description

The connect function establishes a connection to the LCU using specified options. This function supports various authentication strategies, allowing users to choose the most suitable method for their needs.

Method Signature

public async connect(options?: ConnectionOptions): Promise<void>

Parameters

  • options (optional): An object containing connection options. If not provided, default values will be used.

Returns

A Promise that resolves when the connection is established successfully, or rejects if an error occurs during the connection process.

Connection Options

The connect function accepts an object of type ConnectionOptions to customize the connection process. If omitted, Hasagi will use the Process Authentication Strategy.

Properties

  • useWebSocket (optional): Specifies whether to use the LCU WebSocket for the connection. Events do not work if disabled. Defaults to true.
  • maxConnectionAttempts (optional): The maximum number of connection attempts before failing. Defaults to infinite.
  • connectionAttemptDelay (optional): The delay in milliseconds between each (re)connection attempt. Defaults to 5000 milliseconds.
  • certificate (optional): The self-signed Riot Games certificate in string format. Use null to disable certificate validation or omit to use the built-in certificate.

Authentication Strategies

The ConnectionOptions object allows for different authentication strategies, each tailored to specific authentication methods.

1. Process Authentication Strategy

  • Description: Uses a process for authentication.
  • Options: None
  • Example:
    {
        authenticationStrategy: "process"
    }

2. Lockfile Authentication Strategy

  • Description: Uses a lockfile for authentication.
  • Options:
    • lockfile: Either the lockfile's content or an absolute path to the lockfile (including file name).
  • Example:
    {
        authenticationStrategy: "lockfile",
        lockfile: "C:/Riot Games/League of Legends/lockfile"
    }

3. Manual Authentication Strategy

  • Description: Manually provide credentials for authentication.
  • Options:
    • credentials: An object containing authentication credentials.
      • processId (optional): The process ID.
      • port: The port number.
      • password: The password.
  • Example:
    {
        authenticationStrategy: "manual",
        credentials: {
            port: 25565,
            password: "unencoded_password"
        }
    }

Reconnecting

Hasagi does not automatically reconnect, but can enable it like this.

const client = new HasagiClient();
client.on("disconnected", () => client.connect());
client.connect();