Skip to content

Commit 092d26a

Browse files
committed
Fix after merge
1 parent f039836 commit 092d26a

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

collab/main.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
AUTH_FAIL = "auth_fail"
2323
CLOSE_SESSION = "close_session"
2424
CONTENT_CHANGE = "content_change"
25+
PING = "ping"
2526
)
2627

2728
var upgrader = websocket.Upgrader{
@@ -299,8 +300,8 @@ func handleMessages(
299300

300301
log.Println("Client authenticated successfully")
301302
}
302-
// i can comment out this whole block and it would work
303303

304+
// old logic before type changes
304305
// if msgData["type"] == "ping" {
305306
// //receives ping from client1, need to send a ping to client2
306307
// //eventually, if present, client2 will send the ping back, which will be broadcasted back to client1.
@@ -343,6 +344,13 @@ func handleMessages(
343344
Type: msgData.Type,
344345
UserID: msgData.UserID,
345346
}
347+
} else if msgData.Type == PING {
348+
// Broadcast the message to other clients
349+
hub.broadcast <- Message{
350+
RoomID: client.roomID,
351+
Type: msgData.Type,
352+
UserID: msgData.UserID,
353+
}
346354
} else {
347355
log.Printf("Unknown message type: %s", msgData.Type)
348356
}

peerprep/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ WORKDIR /frontend
66
COPY package*.json ./
77
RUN npm install --force
88
COPY . .
9-
#RUN npm run build
9+
RUN npm run build
1010
EXPOSE 3000
11-
CMD ["npm", "run", "dev"]
11+
CMD ["npm", "run", "start"]

peerprep/components/questionpage/CollabEditor.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { callFormatter } from "@/app/api/internal/formatter/helper";
2121
import { Ace } from "ace-builds";
2222
import { connect } from "http2";
2323

24-
const PING_INTERVAL_MILLISECONDS = 15000;
24+
const PING_INTERVAL_MILLISECONDS = 5000;
2525
const languages: Language[] = ["javascript", "python", "c_cpp"];
2626

2727
const themes = [
@@ -162,8 +162,8 @@ export default function CollabEditor({
162162
};
163163

164164
newSocket.onmessage = (event) => {
165-
// console.log("Event is", event);
166-
console.error(event.data);
165+
console.log("Event is", event);
166+
// console.error(event.data);
167167

168168
const message: Message = JSON.parse(event.data);
169169

@@ -248,7 +248,6 @@ export default function CollabEditor({
248248
console.log("PINGING WS FROM " + userId);
249249
const msg: Message = {
250250
type: MessageTypes.PING.valueOf(),
251-
data: "pinging",
252251
userId: userId,
253252
};
254253
socket.send(JSON.stringify(msg));
@@ -272,6 +271,7 @@ export default function CollabEditor({
272271
clearInterval(disconnectCheckInterval);
273272
}
274273
}, PING_INTERVAL_MILLISECONDS);
274+
275275
return () => {
276276
clearInterval(interval);
277277
clearInterval(disconnectCheckInterval);

0 commit comments

Comments
 (0)