From 7faca63b5a044216c6da9eec2953d7bc537aef2b Mon Sep 17 00:00:00 2001 From: Mark Mandel Date: Sun, 28 Jul 2019 18:03:11 +0900 Subject: [PATCH] Trying to make a connect() function for nodejs. [skip ci] --- sdks/nodejs/src/agonesSDK.js | 15 ++++++++++++++- test/sdk/nodejs/testSDKClient.js | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/sdks/nodejs/src/agonesSDK.js b/sdks/nodejs/src/agonesSDK.js index 13b9d7b316..cd364c7374 100644 --- a/sdks/nodejs/src/agonesSDK.js +++ b/sdks/nodejs/src/agonesSDK.js @@ -23,7 +23,20 @@ class AgonesSDK { this.healthStream = undefined; this.emitters = []; } - async close(){ + + async connect() { + return new Promise((resolve, reject) => { + this.client.waitForReady(30000, (error) => { + if (error) { + reject(error); + } else { + resolve(); + } + }) + }); + } + + async close() { if (this.healthStream !== undefined){ this.healthStream.destroy() } diff --git a/test/sdk/nodejs/testSDKClient.js b/test/sdk/nodejs/testSDKClient.js index c99bf10431..e7d75120bc 100644 --- a/test/sdk/nodejs/testSDKClient.js +++ b/test/sdk/nodejs/testSDKClient.js @@ -18,6 +18,9 @@ const agonesSDK = new AgonesSDK(); const connect = async function() { var UID = "" try { + console.log("attempting to connect"); + await agonesSDK.connect(); + console.log("connected!"); var once = true; agonesSDK.watchGameServer((result) => { console.log("watch", result);