Communication is performed with StarCraft 2 through a WebSocket connection. A Request object is sent to the game, and it returns a Response object.

For more information, see: https://github.com/Blizzard/s2client-proto/blob/master/docs/protocol.md

This class provides methods for each type of request. For example, to send a "ping" request, you invoke the ping method.

Before using this class, you must connect to the game with the connect method.

Constructors

Properties

IDCounter: number = 0

Starts at 0 and is incremented with each request sent to StarCraft 2.

connecting: DeferredTask = ...

A DeferredTask object is used to detect when the WebSocket connection has successfully connected.

lastStatus: Status = Status.unknown

The status of StarCraft 2 is returned with each API response object and we record it. This is useful so that end-users can query for what the current status of StarCraft 2 is.

For example, they might want to skip creating a game if a game is already created.

requestResolvers: Map<number, RequestResolver> = ...

For each request sent over the wire, we keep track of it with a promise. The resolver function of the promise is fired when the response is received.

The keys of the map are equal to the ID of the request that was sent. (The response will have a matching ID.)

After the response is received and the resolver is retrieved/fired, the resolver is removed from the map.

verbose: boolean
ws: undefined | WebSocket

The "ws" library is used to handle the underlying WebSocket connection to StarCraft 2.

Methods

  • Connects to StarCraft 2 via a WebSocket connection.

    You must use this method before using any of the other methods on this class.

    Parameters

    • hostname: string = DEFAULT_HOSTNAME

      Optional. If not specified, 127.0.0.1 will be used.

    • port: number = DEFAULT_PORT

      Optional. If not specified, 5000 will be used.

    Returns Promise<Status>

    The current status of StarCraft 2 (e.g. whether it is in a game, in a replay, etc.).

  • Type Parameters

    Parameters

    • requestType: T
    • requestObject: RequestTypeToRequestObject[T]

    Returns Promise<RequestTypeToResponseObject[T]>

Generated using TypeDoc