Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/Event.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interface InitOptions {
host: string;
port: number;
port?: number;
protocol: string;
}
type Callback<T = any> = (payload: T) => void;
Expand Down
3 changes: 2 additions & 1 deletion client/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
5 changes: 3 additions & 2 deletions client/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ const callbacks: Record<string, Set<Callback>> = {};

interface InitOptions {
host: string;
port: number;
port?: number;
protocol: string;
}
type Callback<T = any> = (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));
Expand Down