Co-authored-by: Jason Woltje <jason@diversecanvas.com> Co-committed-by: Jason Woltje <jason@diversecanvas.com>
16 lines
358 B
TypeScript
16 lines
358 B
TypeScript
import { io, type Socket } from 'socket.io-client';
|
|
|
|
const GATEWAY_URL = process.env['NEXT_PUBLIC_GATEWAY_URL'] ?? 'http://localhost:4000';
|
|
|
|
let socket: Socket | null = null;
|
|
|
|
export function getSocket(): Socket {
|
|
if (!socket) {
|
|
socket = io(`${GATEWAY_URL}/chat`, {
|
|
withCredentials: true,
|
|
autoConnect: false,
|
|
});
|
|
}
|
|
return socket;
|
|
}
|