Skip to content

Commit

Permalink
allow Client endpoint with relative URL. bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Apr 27, 2024
1 parent 2c4fdb9 commit 0b8d396
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "colyseus.js",
"version": "0.15.18",
"version": "0.15.19",
"description": "Colyseus Multiplayer SDK for JavaScript/TypeScript",
"author": "Endel Dreyer",
"license": "MIT",
Expand Down
6 changes: 5 additions & 1 deletion src/Client.ts
Expand Up @@ -36,10 +36,14 @@ export class Client {

constructor(settings: string | EndpointSettings = DEFAULT_ENDPOINT) {
if (typeof (settings) === "string") {

//
// endpoint by url
//
const url = new URL(settings);
const url = (settings.startsWith("/"))
? new URL(settings, DEFAULT_ENDPOINT)
: new URL(settings);

const secure = (url.protocol === "https:" || url.protocol === "wss:");
const port = Number(url.port || (secure ? 443 : 80));

Expand Down
6 changes: 6 additions & 0 deletions test/client_test.ts
Expand Up @@ -40,6 +40,12 @@ describe("Client", function () {
wsEndpoint: "wss://localhost/custom/path/processId/roomId?",
wsEndpointPublicAddress: "wss://node-1.colyseus.cloud/processId/roomId?"
},
'/api': {
settings: { hostname: "127.0.0.1", port: 2567, secure: false, pathname: "/api" },
httpEndpoint: "http://127.0.0.1:2567/api/",
wsEndpoint: "ws://127.0.0.1:2567/api/processId/roomId?",
wsEndpointPublicAddress: "ws://node-1.colyseus.cloud/processId/roomId?"
},
};

for (const url in settingsByUrl) {
Expand Down

0 comments on commit 0b8d396

Please sign in to comment.