Node.js Game Server Client SDK

This is the Node.js version of the Agones Game Server Client SDK.

Check the Client SDK Documentation for more details on each of the SDK functions and how to run the SDK locally.

SDK Functionality

Area Action Implemented
Lifecycle Ready ✔️
Lifecycle Health ✔️
Lifecycle Reserve ✔️
Lifecycle Allocate ✔️
Lifecycle Shutdown ✔️
Configuration GetGameServer ✔️
Configuration WatchGameServer ✔️
Metadata SetAnnotation ✔️
Metadata SetLabel ✔️
Counters GetCounterCount
Counters SetCounterCount
Counters IncrementCounter
Counters DecrementCounter
Counters SetCounterCapacity
Counters GetCounterCapacity
Lists AppendListValue
Lists DeleteListValue
Lists SetListCapacity
Lists GetListCapacity
Lists ListContains
Lists GetListLength
Lists GetListValues
Player Tracking GetConnectedPlayers ✔️
Player Tracking GetPlayerCapacity ✔️
Player Tracking GetPlayerCount ✔️
Player Tracking IsPlayerConnected ✔️
Player Tracking PlayerConnect ✔️
Player Tracking PlayerDisconnect ✔️
Player Tracking SetPlayerCapacity ✔️

Prerequisites

  • Node.js >= 10.13.0

Usage

Add the agones dependency to your project:

npm install @google-cloud/agones-sdk

If you need to download the source, rather than install from NPM, you can find it on GitHub .

To begin working with the SDK, create an instance of it.

const AgonesSDK = require('@google-cloud/agones-sdk');

let agonesSDK = new AgonesSDK();

To connect to the SDK server, either local or when running on Agones, run the async method sdk.connect(), which will resolve once connected or reject on error or if no connection can be made after 30 seconds.

await agonesSDK.connect();

To send a health check ping call health(errorCallback). The error callback is optional and if provided will receive an error whenever emitted from the health check stream.

agonesSDK.health((error) => {
	console.error('error', error);
});

To mark the game server as ready to receive player connections, call the async method ready(). The result will be an empty object in this case.

let result = await agonesSDK.ready();

Similarly shutdown(), allocate(), setAnnotation(key, value) and setLabel(key, value) are async methods that perform an action and return an empty result.

To get details of the backing GameServer call the async method getGameServer(). The result will be an object representing GameServer defined in `sdk.proto` .

let result = await agonesSDK.getGameServer();

To get updates on the backing GameServer as they happen, call watchGameServer(callback, errorCallback). The callback will be called with a parameter matching the result of getGameServer(). The error callback is optional and if provided will receive an error whenever emitted from the watch stream.

agonesSDK.watchGameServer((result) => {
	console.log('watch', result);
}, (error) => {
	console.error('error', error);
});

To mark the game server as reserved for a period of time, call the async method reserve(seconds). The result will be an empty object.

For more information, please read the SDK Overview, check out agonesSDK.js and also look at the Node.js example .


Last modified March 19, 2024: Update Supported Kubernetes to 1.27, 1.28, 1.29 (#3654) (ace51d6)