This commit is contained in:
payacom
2026-07-23 15:58:15 +03:30
parent af5b27b610
commit a1d7db5e7e
445 changed files with 23456 additions and 8865 deletions

View File

@@ -0,0 +1,35 @@
"use client";
import { useEffect } from "react";
import { useUser } from "@/hooks/useUser";
import {
acquireChatSocket,
joinUserRoom,
releaseChatSocket,
} from "@/lib/chat/socketClient";
export default function ChatSocketProvider({
children,
}: {
children: React.ReactNode;
}) {
const user = useUser();
useEffect(() => {
if (!user?._id) return;
const socket = acquireChatSocket();
const uid = String(user._id);
const join = () => joinUserRoom(uid);
socket.on("connect", join);
if (socket.connected) join();
return () => {
socket.off("connect", join);
releaseChatSocket();
};
}, [user?._id]);
return children;
}