Skip to content

Commit 316e8bb

Browse files
committed
🐛 Return window.io, not io
1 parent fb3c55e commit 316e8bb

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

socket.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ import type {
99
} from "./types/socketIO/index.ts";
1010
export type { Manager, ManagerOptions, Socket, SocketOptions };
1111

12-
declare function io(
13-
uri: string,
14-
opts?: Partial<ManagerOptions & SocketOptions>,
15-
): Socket;
12+
declare global {
13+
interface Window {
14+
io(
15+
uri: string,
16+
opts?: Partial<ManagerOptions & SocketOptions>,
17+
): Socket;
18+
}
19+
}
1620
const version = "4.2.0";
1721

1822
export async function socketIO() {
@@ -23,17 +27,17 @@ export async function socketIO() {
2327
});
2428
}
2529

26-
function importSocketIO(): Promise<typeof io> {
30+
function importSocketIO(): Promise<Window["io"]> {
2731
const url =
2832
`https://cdnjs.cloudflare.com/ajax/libs/socket.io/${version}/socket.io.min.js`;
2933
if (document.querySelector(`script[src="${url}"]`)) {
30-
return Promise.resolve(io);
34+
return Promise.resolve(window.io);
3135
}
3236

3337
const script = document.createElement("script");
3438
script.src = url;
3539
return new Promise((resolve, reject) => {
36-
script.onload = () => resolve(io);
40+
script.onload = () => resolve(window.io);
3741
script.onerror = (e) => reject(e);
3842
document.head.append(script);
3943
});

0 commit comments

Comments
 (0)