Node.js 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.
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()
.
agonesSDK.health();
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)
. The callback will be called with a parameter matching the result of getGameServer()
.
agonesSDK.watchGameServer((result) => {
console.log('watch', result);
});
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 .
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.