Skip to content

Commit 3e41dac

Browse files
authored
feat: exported getwebsocketurl function - fix #10 (#11)
1 parent ba71877 commit 3e41dac

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/client.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ const getRandomString = (length: number) => {
4141
return result;
4242
};
4343

44+
export const getWebSocketUrl = (url: string) => {
45+
const { protocol, hostname, pathname, port } = new URL(url);
46+
47+
const socketProtocol = protocol === "http:" ? "ws:" : "wss:";
48+
return `${socketProtocol}//${hostname}${port ? `:${port}` : ""}${pathname}`;
49+
};
50+
4451
export const getClientSocket = ({
4552
url,
4653
reconnect = true,

src/utils.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,3 @@ export const getRandomString = (length: number) => {
1010
}
1111
return result;
1212
};
13-
export const getWebSocketUrl = (url: string) => {
14-
const { protocol, hostname, pathname, port } = new URL(url);
15-
16-
const socketProtocol = protocol === "http:" ? "ws:" : "wss:";
17-
return `${socketProtocol}//${hostname}${port ? `:${port}` : ""}${pathname}`;
18-
};

0 commit comments

Comments
 (0)