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));