inflearn logo
Course

Course

Instructor

thelapssql3213's Posts

thelapssql3213 thelapssql3213

@thelapssql3213

Reviews Written
1
Average Rating
5.0

Posts 3

Q&A

socket.js 에서 referer로부터 roomId를 가져올 때

저도 질문자님처럼 request.referer가 undefined 뜨더라구요. 그래서 다음과 같이 작성하였어요. index.html 클라이언트에서 "roomId"를 Socket 연결 시 Url QueryString으로 전달 const socket = io.connect( `http://localhost:2000/chat?roomId=${$roomId}`, { path: "/socket.io", transports: ["websocket"], }, ); socket.ts interface IRequestQuery { roomId: string; } socket.on("disconnect", async () => { const { roomId }: IRequestQuery = socket.handshake .query as unknown as IRequestQuery; const currentRoom = chat.adapter.rooms.get(roomId); const userCount = currentRoom?.size; console.log(userCount); });

Likes
0
Comments
3
Viewcount
933