This commit is contained in:
@@ -31,9 +31,13 @@ export const ExamGridProctor: React.FC<ExamGridProctorProps> = ({
|
|||||||
);
|
);
|
||||||
const onlineKey = useMemo(() => onlineIds.join(','), [onlineIds]);
|
const onlineKey = useMemo(() => onlineIds.join(','), [onlineIds]);
|
||||||
|
|
||||||
|
const onlineIdsRef = useRef<number[]>(onlineIds);
|
||||||
|
onlineIdsRef.current = onlineIds;
|
||||||
|
|
||||||
const syncSubscriptions = (ws: WebSocket) => {
|
const syncSubscriptions = (ws: WebSocket) => {
|
||||||
if (ws.readyState !== WebSocket.OPEN) return;
|
if (ws.readyState !== WebSocket.OPEN) return;
|
||||||
const target = new Set(onlineIds);
|
const currentOnlineIds = onlineIdsRef.current;
|
||||||
|
const target = new Set(currentOnlineIds);
|
||||||
const prev = subscribedRef.current;
|
const prev = subscribedRef.current;
|
||||||
|
|
||||||
prev.forEach((id) => {
|
prev.forEach((id) => {
|
||||||
@@ -42,7 +46,7 @@ export const ExamGridProctor: React.FC<ExamGridProctorProps> = ({
|
|||||||
prev.delete(id);
|
prev.delete(id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
onlineIds.forEach((id) => {
|
currentOnlineIds.forEach((id) => {
|
||||||
if (!prev.has(id)) {
|
if (!prev.has(id)) {
|
||||||
ws.send(JSON.stringify({ event: 'teacher:subscribe', data: { studentId: id } }));
|
ws.send(JSON.stringify({ event: 'teacher:subscribe', data: { studentId: id } }));
|
||||||
prev.add(id);
|
prev.add(id);
|
||||||
|
|||||||
Reference in New Issue
Block a user