forked from googleforgames/agones
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Node.js SDK, example and docs - closes googleforgames#538
- Loading branch information
1 parent
bc75c34
commit 2e002da
Showing
22 changed files
with
6,345 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
!.dockerignore | ||
!.golangci.yml | ||
!.gcloudignore | ||
!.eslintrc.* | ||
!.nycrc | ||
*.iml | ||
bin | ||
*.o | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Copyright 2017 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set -x | ||
|
||
header() { | ||
cat ./build/boilerplate.go.txt $1 >> ./tmp.js && mv ./tmp.js $1 | ||
} | ||
|
||
googleapis=/go/src/agones.dev/agones/vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis | ||
|
||
cd /go/src/agones.dev/agones | ||
|
||
protoc -I ${googleapis} -I . --grpc_out=./sdks/nodejs/lib --plugin=protoc-gen-grpc=`which grpc_node_plugin` sdk.proto | ||
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 | ||
|
||
header ./sdks/nodejs/lib/sdk_pb.js | ||
header ./sdks/nodejs/lib/google/api/annotations_pb.js | ||
header ./sdks/nodejs/lib/google/api/http_pb.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
### Instructions | ||
`npm install` - install dependencies | ||
|
||
`npm start` - start the self-running example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"dependencies": { | ||
"agones": "../../sdks/nodejs" | ||
}, | ||
"scripts": { | ||
"start": "node src/index.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const AgonesSDK = require('agones'); | ||
|
||
let agonesSDK = new AgonesSDK(); | ||
|
||
let connect = async function() { | ||
agonesSDK.watchGameServer((result) => { | ||
console.log('watch', result); | ||
}); | ||
|
||
try { | ||
await agonesSDK.ready(); | ||
await agonesSDK.setLabel("label", "labelValue"); | ||
await agonesSDK.setAnnotation("annotation", "annotationValue"); | ||
let result = await agonesSDK.getGameServer(); | ||
console.log('gameServer', result); | ||
setTimeout(() => { | ||
console.log('send health ping'); | ||
agonesSDK.health(); | ||
}, 2000); | ||
setTimeout(() => { | ||
console.log('send shutdown request'); | ||
agonesSDK.shutdown(); | ||
}, 4000); | ||
setTimeout(() => { | ||
process.exit(); | ||
}, 6000); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; | ||
|
||
connect(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": 2017 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/node_modules/ | ||
/coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"include": [ | ||
"src/**/*.js" | ||
], | ||
"reporter": [ | ||
"lcov", | ||
"text" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
### Instructions | ||
`npm install` - install dependencies | ||
|
||
`npm run cover` - run tests and report code coverage | ||
|
||
`npm run lint` - lint the code | ||
|
||
`npm test` - run the tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2018 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// This code was autogenerated. Do not edit directly. | ||
/** | ||
* @fileoverview | ||
* @enhanceable | ||
* @public | ||
*/ | ||
// GENERATED CODE -- DO NOT EDIT! | ||
|
||
var jspb = require('google-protobuf'); | ||
var goog = jspb; | ||
var global = Function('return this')(); | ||
|
||
var google_api_http_pb = require('../../google/api/http_pb.js'); | ||
var google_protobuf_descriptor_pb = require('google-protobuf/google/protobuf/descriptor_pb.js'); | ||
goog.exportSymbol('google.api.http', null, global); | ||
|
||
/** | ||
* A tuple of {field number, class constructor} for the extension | ||
* field named `http`. | ||
* @type {!jspb.ExtensionFieldInfo.<!proto.google.api.HttpRule>} | ||
*/ | ||
proto.google.api.http = new jspb.ExtensionFieldInfo( | ||
72295728, | ||
{http: 0}, | ||
google_api_http_pb.HttpRule, | ||
/** @type {?function((boolean|undefined),!jspb.Message=): !Object} */ ( | ||
google_api_http_pb.HttpRule.toObject), | ||
0); | ||
|
||
google_protobuf_descriptor_pb.MethodOptions.extensionsBinary[72295728] = new jspb.ExtensionFieldBinaryInfo( | ||
proto.google.api.http, | ||
jspb.BinaryReader.prototype.readMessage, | ||
jspb.BinaryWriter.prototype.writeMessage, | ||
google_api_http_pb.HttpRule.serializeBinaryToWriter, | ||
google_api_http_pb.HttpRule.deserializeBinaryFromReader, | ||
false); | ||
// This registers the extension field with the extended class, so that | ||
// toObject() will function correctly. | ||
google_protobuf_descriptor_pb.MethodOptions.extensions[72295728] = proto.google.api.http; | ||
|
||
goog.object.extend(exports, proto.google.api); |
Oops, something went wrong.