Localhost causing issues connecting to game engine server

Crosspost from Discord. I am having an issue with using the websocket API in a localhost environment. Basically, I am trying to create a low impact webpage to track the number of guests in my space, but whenever I run the websocket code in my localhost environment, the Game.ts program sets the overrideServer to my localhost environment too. The code in the .ts file is:

if (isBrowser && window.location.hostname === “localhost”) {
this.overrideServer(“ws://” + window.location.host + “/__dev-websocket”);
}

Is there a way to disable overrideServer? I thought this might be a debugging tool, but I cant be sure if I’m just not understanding the intention. Thanks!

Well, is there a problem running a nodejs at local to do what you want to monitor? I use nodejs directly on my computer. I didn’t get why it should be running in a website?

My hope would be to deploy this to an external ftp or server, so I can access the function from any computer, and not just my own machine. Localhost would, in a perfect world, let me test UI, CSS, menuing, etc along with the code accessing the websocket, pre-deployment.

As it currently stands, I’ll probably have to deploy the site untested, and hope the localhost issue is resolved by that. Then I can do all the debugging and designing.

I am hoping I might get some info on if this is an intended functionality or not, so I can plan the next step. Or of I’m just missing a call to let me avoid the override server.

I see, but I still think there’s no problem following the official examples to use nodejs to serve the SDK and you still can build your own local website to communicate with the node server.

@jcyh I definitely can run my code off my own computer, that hasn’t been the issue. The issue has been trying to test any server style environment in localhost, due to the code in Game.ts I showed in the initial post.

Even the most basic nodejs http server uses localhost as a testing ground, which the code then takes and modifies the engine server address to include the localhost path. Because I am not running a local copy of the websocket server (though that offers interesting options), all my attempts to then connect to the websocket fail because the server url it is pointed at doesn’t exist.

When I get home from holiday I will post some error logs, assuming nothing new pops up. Hopefully that will show more detail on what I am experiencing.

Hi there, sorry it’s taken me a bit to reply to this.
Do I have it right that you’re trying to run gather-game-client inside of a browser instance, in localhost, but have it connect to a space that is NOT localhost?

If so, yes, you can disable overrideServer- after you construct Game, but before you call connect() , set game.debugOverrideServer to null. It will cause this check to be skipped when getGameServerUrl is called, and your server should be assigned normally.

Please let me know if that works for you!

@opalrose Thanks for getting back to this. I am trying to run some code in the browser, basically as a proof of concept, where I am testing in localhost for a gather instance on a normal server.

I have set debugOverrideServer to null, undefined, “null”, “”, “undefined”, and maybe a few attempts at forcing a connection to some urls which I have had engines connect to in the past.

All of these attempts basically resulted in the same outcome, where it still tries to connect to “https://localhost:8080/api/v2/game-servers” and “https://localhost:8080/api/v2/spaces/{SPACE ID HERE}/game-server-assignment?body=%7B%7D”. This is, based on my console logs, after debugOverrideServer was disabled.

There is a pattern of the game destroying the engine, then throwing the errors, so I wonder if there is some sort of reconnection/reconstruction issue. If you need more of the code or some example error logs, I may be able to provide those more directly.

Spent a couple of hours finally able to repeat the problem. I think the ws sdk seems not designed for running in browser currently unless you have a Gather official server running locally? Do you really need to use it in browser? I use the ws sdk in node server can still verify ideas quickly. Just some suggestions to save time.

I tried to modify the sdk source code but no luck and got a CORS error. I think they blocked the usage for using ws sdk in a browser to request their public server unless you are doing a development in “their internal environment”.