Skip to content
Merged

fix #68

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/app/room/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,12 @@ function RoomInner() {

s.on("connect", () => {
if (sessionIdRef.current) {
s.emit("session:join", { sessionId: sessionIdRef.current });
s.emit("session:join", { sessionId: sessionIdRef.current }, (error?: string) => {
if (!error) setSocket(s);
});
} else {
setSocket(s);
}
setSocket(s);
});

s.on("session:ended", () => {
Expand Down
5 changes: 4 additions & 1 deletion src/socket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export async function initSocketIO(
console.log(`[Socket.IO] Client connected: ${socket.id} (user: ${socket.data.userId})`);

// Session room management
socket.on("session:join", async (payload) => {
socket.on("session:join", async (payload, ack) => {
if (payload?.sessionId && typeof payload.sessionId === "string") {
const userId = socket.data.userId;

Expand All @@ -149,6 +149,7 @@ export async function initSocketIO(

if (!sessionRecord) {
socket.emit("question:error", { message: "Session not found." });
if (typeof ack === "function") ack("Session not found.");
return;
}

Expand All @@ -173,6 +174,7 @@ export async function initSocketIO(
reason: "not enrolled",
});
socket.emit("question:error", { message: "You are not enrolled in this session." });
if (typeof ack === "function") ack("Not enrolled.");
return;
}

Expand All @@ -192,6 +194,7 @@ export async function initSocketIO(
}

await broadcastViewerCount(payload.sessionId);
if (typeof ack === "function") ack();
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/socket/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export interface ViewerSyncPayload {
export interface ClientToServerEvents {
"question:create": (payload: QuestionCreatePayload) => void;
"answer:create": (payload: AnswerCreatePayload) => void;
"session:join": (payload: SessionJoinPayload) => void;
"session:join": (payload: SessionJoinPayload, ack?: (error?: string) => void) => void;
"session:leave": (payload: SessionLeavePayload) => void;
"question:upvote": (payload: QuestionUpvotePayload) => void;
"answer:upvote": (payload: AnswerUpvotePayload) => void;
Expand Down
Loading