From 0b8d39630763908f82c166958a4ccdcd48deebb8 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Sat, 27 Apr 2024 09:09:46 -0300 Subject: [PATCH] allow Client endpoint with relative URL. bump version --- package-lock.json | 4 ++-- package.json | 2 +- src/Client.ts | 6 +++++- test/client_test.ts | 6 ++++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index c351496..ae1968b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "colyseus.js", - "version": "0.15.18", + "version": "0.15.19", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "colyseus.js", - "version": "0.15.18", + "version": "0.15.19", "license": "MIT", "dependencies": { "@colyseus/schema": "^2.0.4", diff --git a/package.json b/package.json index fcee546..aa15de9 100644 --- a/package.json +++ b/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", diff --git a/src/Client.ts b/src/Client.ts index 917ae17..e280d3e 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -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)); diff --git a/test/client_test.ts b/test/client_test.ts index b877276..df003b7 100644 --- a/test/client_test.ts +++ b/test/client_test.ts @@ -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) {