Skip to content

Commit 2344edb

Browse files
steven-supersolidmarkmandel
authored andcommitted
Add Node.js SDK, example and docs - closes agones-dev#538
1 parent 0b9af68 commit 2344edb

22 files changed

Lines changed: 6345 additions & 1 deletion

File tree

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
!.dockerignore
2020
!.golangci.yml
2121
!.gcloudignore
22+
!.eslintrc.*
23+
!.nycrc
2224
*.iml
2325
bin
2426
*.o

‎build/Makefile‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,17 @@ push-release-chart: $(ensure-build-image)
218218
build-sdks: build-sdk-cpp
219219

220220
# Run all tests
221-
test: $(ensure-build-image) test-go test-install-yaml site-test
221+
test: $(ensure-build-image) test-go test-nodejs test-install-yaml site-test
222222

223223
# Run go tests
224224
test-go:
225225
$(GO_TEST) $(agones_package)/pkg/... \
226226
$(agones_package)/sdks/... $(agones_package)/cmd/...
227227

228+
# Run Node.js SDK tests
229+
test-nodejs:
230+
docker run --rm $(common_mounts) -w $(mount_path)/sdks/nodejs $(build_tag) npm install-test
231+
228232
# Runs end-to-end tests on the current configured cluster
229233
# For minikube user the minikube-test-e2e targets
230234
test-e2e: $(ensure-build-image)
@@ -356,6 +360,7 @@ gen-gameservers-sdk-grpc: $(ensure-build-image)
356360
docker run --rm $(common_mounts) -w $(mount_path) $(build_tag) /root/gen-grpc-go.sh
357361
docker run --rm $(common_mounts) -w $(mount_path) $(build_tag) /root/gen-grpc-cpp.sh
358362
docker run --rm $(common_mounts) -w $(mount_path) $(build_tag) /root/gen-grpc-rust.sh
363+
docker run --rm $(common_mounts) -w $(mount_path) $(build_tag) /root/gen-grpc-nodejs.sh
359364

360365
# Generate the client for our CustomResourceDefinition
361366
gen-crd-client: $(ensure-build-image)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2017 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -x
18+
19+
header() {
20+
cat ./build/boilerplate.go.txt $1 >> ./tmp.js && mv ./tmp.js $1
21+
}
22+
23+
googleapis=/go/src/agones.dev/agones/vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis
24+
25+
cd /go/src/agones.dev/agones
26+
27+
protoc -I ${googleapis} -I . --grpc_out=./sdks/nodejs/lib --plugin=protoc-gen-grpc=`which grpc_node_plugin` sdk.proto
28+
protoc -I ${googleapis} -I . --js_out=import_style=commonjs,binary:./sdks/nodejs/lib sdk.proto ${googleapis}/google/api/annotations.proto ${googleapis}/google/api/http.proto
29+
30+
header ./sdks/nodejs/lib/sdk_pb.js
31+
header ./sdks/nodejs/lib/google/api/annotations_pb.js
32+
header ./sdks/nodejs/lib/google/api/http_pb.js

‎examples/nodejs-simple/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules/

‎examples/nodejs-simple/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
### Instructions
2+
`npm install` - install dependencies
3+
4+
`npm start` - start the self-running example
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"dependencies": {
3+
"agones": "../../sdks/nodejs"
4+
},
5+
"scripts": {
6+
"start": "node src/index.js"
7+
}
8+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const AgonesSDK = require('agones');
2+
3+
let agonesSDK = new AgonesSDK();
4+
5+
let connect = async function() {
6+
agonesSDK.watchGameServer((result) => {
7+
console.log('watch', result);
8+
});
9+
10+
try {
11+
await agonesSDK.ready();
12+
await agonesSDK.setLabel("label", "labelValue");
13+
await agonesSDK.setAnnotation("annotation", "annotationValue");
14+
let result = await agonesSDK.getGameServer();
15+
console.log('gameServer', result);
16+
setTimeout(() => {
17+
console.log('send health ping');
18+
agonesSDK.health();
19+
}, 2000);
20+
setTimeout(() => {
21+
console.log('send shutdown request');
22+
agonesSDK.shutdown();
23+
}, 4000);
24+
setTimeout(() => {
25+
process.exit();
26+
}, 6000);
27+
} catch (error) {
28+
console.error(error);
29+
}
30+
};
31+
32+
connect();

‎sdks/nodejs/.eslintrc.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"env": {
3+
"es6": true,
4+
"node": true
5+
},
6+
"extends": "eslint:recommended",
7+
"parserOptions": {
8+
"ecmaVersion": 2017
9+
}
10+
}

‎sdks/nodejs/.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules/
2+
/coverage/

‎sdks/nodejs/.nycrc‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"include": [
3+
"src/**/*.js"
4+
],
5+
"reporter": [
6+
"lcov",
7+
"text"
8+
]
9+
}

0 commit comments

Comments
 (0)