From 2b954eaaae5d474f6de93f681a96d7ec39de878f Mon Sep 17 00:00:00 2001 From: Halil Ibrahim Cengel Date: Fri, 8 Aug 2025 13:51:04 +0300 Subject: [PATCH] Make port optional in Event client initialization Updated InitOptions to allow port to be optional. Adjusted socket connection logic to handle cases where port is not provided, improving flexibility for different connection scenarios. --- client/Event.d.ts | 2 +- client/Event.js | 3 ++- client/Event.ts | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/client/Event.d.ts b/client/Event.d.ts index 9bef6ca..07896dd 100644 --- a/client/Event.d.ts +++ b/client/Event.d.ts @@ -1,6 +1,6 @@ interface InitOptions { host: string; - port: number; + port?: number; protocol: string; } type Callback = (payload: T) => void; diff --git a/client/Event.js b/client/Event.js index 7e7ea86..5211e6c 100644 --- a/client/Event.js +++ b/client/Event.js @@ -9,7 +9,8 @@ var event = { var host = _a.host, port = _a.port, protocol = _a.protocol; if (socket) return; - socket = (0, socket_io_client_1.io)("".concat(protocol, "://").concat(host, ":").concat(port)); + var socketPath = port ? "".concat(protocol, "://").concat(host, ":").concat(port) : "".concat(protocol, "://").concat(host); + socket = (0, socket_io_client_1.io)(socketPath); socket.on("event", function (_a) { var type = _a.type, payload = _a.payload; if (callbacks[type]) { diff --git a/client/Event.ts b/client/Event.ts index f9d3603..7bd2f2a 100644 --- a/client/Event.ts +++ b/client/Event.ts @@ -5,7 +5,7 @@ const callbacks: Record> = {}; interface InitOptions { host: string; - port: number; + port?: number; protocol: string; } type Callback = (payload: T) => void; @@ -13,7 +13,8 @@ type Callback = (payload: T) => void; const event = { init({ host, port, protocol }: InitOptions) { if (socket) return; - socket = io(`${protocol}://${host}:${port}`); + const socketPath = port ? `${protocol}://${host}:${port}` : `${protocol}://${host}`; + socket = io(socketPath); socket.on("event", ({ type, payload }: { type: string; payload: any }) => { if (callbacks[type]) { callbacks[type].forEach((cb) => cb(payload));