6.0.0-rc12 • Published 1 year ago

league-connect v6.0.0-rc12

Weekly downloads
28
License
MIT
Repository
github
Last release
1 year ago

Table of Contents

Getting Started

League Connect is a NodeJs module for consuming the League of Legends Client APIs

If you're migrating from v5, please check out the migration guide

Prerequisites

To start using League Connect, ensure the following packages are installed:

  • Node (any recent version should run (download))
  • Yarn or NPM
  • League of Legends (download)

You should also check out the examples directory for code examples.

Installation

League Connect ships as an NPM module, installable through Yarn or NPM. To add the package to your project, install it through your package manager of choice.

$ yarn add league-connect
# Or ...
$ npm install league-connect

Usage

League Connect ships 4 primary APIs:

Authenticate

Credentials are passed around as an object containing a port and a password (see source). These credentials are pulled from the LeagueClientUx process and will be used to authenticate any requests or connections to the APIs.

Code Example

import { authenticate } from 'league-connect'

const credentials = await authenticate()
console.log(credentials) // { password: '37dn2gsxH3ns', port: 37241 }

By default, the authenticate function will return a rejected promise if it failed to locate a running LeagueClientUx process. If you wish to await until a client is found, you can use the optional options:

OptionDefault ValueDescription
nameLeagueClientUxLeague Client name, set to RiotClientUx if you would like to authenticate with the Riot Client
awaitConnectionfalseAwait until a LeagueClientUx process is found
pollInterval2500Duration in milliseconds between each poll. No-op if awaitConnection is false.
certificateundefinedA plain-text self-signed certificate to authenticate to the LCU API with. This option should only be used if you're self-signing with a certificate which is not the one Riot Games provides on their developer page. League Connect will default to using Riot's own self-signed certificate for authentication. If you're of what this option does, you should probably not use it.
unsafefalseIf you do not wish to authenticate safely using a self-signed certificate you can authorize while ignoring any certificate rejections. To authenticate this way, set unsafe to true. The custom certificate option will take precedence over this, meaning this option is meaningless if a custom certificate is provided.
useDeprecatedWmicfalseUse deprecated Windows WMIC command line over Get-CimInstance. Does nothing if the system is not running on Windows.
windowsShellpowershellSet the Windows shell to use. Either powershell or cmd.
import { authenticate } from 'league-connect'

const credentials = await authenticate({
  awaitConnection: true,
  pollInterval: 5000,
  // certificate: "-----BEGIN CERTIFICATE-----\nSowhdnAMyCertificate\n-----ENDCERTIFICATE-----",
  // unsafe: true
})
See source for available options

LeagueWebSocket

The League Client runs a WebSocket for an event bus which anything using the client may connect to. Developers may also connect to this socket over wss. LeagueConnect provides a function to retrieve a WebSocket connection.

import { createWebSocketConnection } from 'league-connect'

const ws = await createWebSocketConnection()

League Connect uses its own extended WebSocket class which allows subscriptions to certain API endpoints.

The socket instance automatically subscribes to Json events from the API which will be ran on the message event.

Code Example

import { createWebSocketConnection } from 'league-connect'

const ws = await createWebSocketConnection({
  authenticationOptions: {
    // any options that can also be called to authenticate()
    awaitConnection: true
  }
})

ws.on('message', message => {
  // Subscribe to any websocket event
})

The createWebSocketConnection function will retry connecting to the WebSocket 10 times by default. A rejected promise will be returned if the function is unable to connect. If you wish to change some of this behavior, you can pass in the following options to the function: | Option | Default Value | Description | |--------|---------------|-------------| | authenticationOptions | undefined | The same options that can be passed to the authenticate function | | pollInterval | 1000 | The amount of time in ms to wait between WS connection attempts | | maxRetries | 10 | The maximum amount of times to retry connecting to the WS. -1 to keep retrying until connected |

import { createWebSocketConnection } from 'league-connect'

const ws = await createWebSocketConnection({
  authenticationOptions: {
    awaitConnection: true
  },
  pollInterval: 1000,
  maxRetries: 10
})

ws.subscribe('/lol-chat/v1/conversations/active', (data, event) => {
  // data: deseralized json object from the event payload
  // event: the entire event (see EventResponse<T>)
})
See source for available options

Requests

LeagueConnect supports both HTTP/1.1 and HTTP/2.0. Use the corresponding APIs as necessary.

LeagueConnect supports sending HTTP requests to any of the League Client API endpoints (endpoints can be discovered and viewed with LCU Explorer)

If you're looking to use HTTP/2.0, you first need to create a session.

import { authenticate, createHttpSession, createHttp2Request } from 'league-connect'

const credentials = await authenticate()
const session = await createHttpSession(credentials)
const response = await createHttp2Request({
    method: 'GET',
    url: '/lol-summoner/v1/current-summoner'
}, session, credentials)

// Remember to close the session when done
session.close()

For HTTP/1.0, you can simply use the createHttp1Request function.

import { authenticate, createHttp1Request } from 'league-connect'

const credentials = await authenticate()
const response = await createHttp1Request({
    method: 'GET',
    url: '/lol-summoner/v1/current-summoner'
}, credentials)

Both createHttp1Request and createHttp2Request take the same options.

OptionDescription
urlRelative URI to send the http request to
methodHTTP verb to use
bodyOptional post body (for non GET requests) as object literal. (library serializes it)
See source for available options

LeagueClient

The LeagueClient class is an EventEmitter which will listen for the LeagueClientUx process, reporting shutdown/startup of the application. The emitter has two listeners: connect and disconnect.

Code Example

import { authenticate, LeagueClient } from 'league-connect'

const credentials = await authenticate()
const client = new LeagueClient(credentials)

client.on('connect', (newCredentials) => {
  // newCredentials: Each time the Client is started, new credentials are made
  // this variable contains the new credentials.
})

client.on('disconnect', () => {

})

client.start() // Start listening for process updates
client.stop()  // Stop listening for process updates

By default, the LeagueClient class will check for a client connection/disconnection every 2.5 seconds. This can be changed by passing an options object into the constructor.

OptionDefault ValueDescription
pollInterval2500Duration in milliseconds between process existence check
import { authenticate, LeagueClient } from 'league-connect'

const credentials = await authenticate()
const client = new LeagueClient(credentials, {
  pollInterval: 1000 // Check every second
})
See source for available options

License

Distributed under the MIT License. See LICENSE for more information.

6.0.0-rc12

1 year ago

6.0.0-rc11

1 year ago

6.0.0-rc10

1 year ago

6.0.0-rc9

1 year ago

5.5.0

2 years ago

6.0.0-rc8

2 years ago

6.0.0-rc5

2 years ago

6.0.0-rc4

2 years ago

6.0.0-rc7

2 years ago

6.0.0-rc6

2 years ago

5.5.0-rc1

2 years ago

6.0.0-rc1

2 years ago

6.0.0-rc3

2 years ago

6.0.0-rc2

2 years ago

5.4.0

2 years ago

5.3.1

2 years ago

5.3.1-rc1

2 years ago

5.3.0

3 years ago

5.2.0-rc1

3 years ago

5.2.0

3 years ago

5.1.0

3 years ago

5.0.2

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

5.0.0-beta4

3 years ago

5.0.0-beta3

3 years ago

5.0.0-beta2

3 years ago

5.0.0-beta1

3 years ago

4.0.0

4 years ago

3.0.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.1.0

4 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago