Skip to content

Commit

Permalink
Merge pull request CS3219-AY2324S1#233 from JrmCkh/execution-branch
Browse files Browse the repository at this point in the history
Dockerise Excecution branch and fixed exec bugs.
  • Loading branch information
JrmCkh authored Nov 8, 2023
2 parents d07946f + 4e31011 commit ee79575
Show file tree
Hide file tree
Showing 20 changed files with 397 additions and 272 deletions.
63 changes: 34 additions & 29 deletions Collaboration/src/CollaborationServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ try {
},
});

io.on(Event.CONNECTION, (socket) => {
io.on(Event.Socket.CONNECT, (socket) => {
// Handle room joining
socket.on(Event.JOIN_ROOM, (data) => {
socket.on(Event.Socket.JOIN_ROOM, (data) => {
const room = data.room;
const user = data.user;

Expand All @@ -40,7 +40,7 @@ try {
});

// Handle room leaving
socket.on(Event.LEAVE_ROOM, (data) => {
socket.on(Event.Socket.LEAVE_ROOM, (data) => {
const room = data.room;
const user = data.user;

Expand All @@ -52,66 +52,71 @@ try {
io.to(room).emit(Event.Communication.CHAT_RECEIVE, message);
});

// Handle chat messages
socket.on(Event.Communication.CHAT_SEND, (data) => {
// Handle question changes
socket.on(Event.Question.CHANGE, (data) => {
const room = data.room;
const message = data.message;
const question = data.question;

io.to(room).emit(Event.Communication.CHAT_RECEIVE, message);
io.to(room).emit(Event.Question.UPDATE, question);
});

// Handle code changes
socket.on(Event.Collaboration.CODE_CHANGE, (data) => {
socket.on(Event.Code.CHANGE, (data) => {
const room = data.room;
const code = data.updatedCode;

io.to(room).emit(Event.Collaboration.CODE_UPDATE, code);
});

// Handle code results
socket.on(Event.Collaboration.RESULT_CHANGE, (data) => {
io.to(data.room).emit(Event.Collaboration.RESULT_UPDATE, data.updatedResult);
io.to(room).emit(Event.Code.UPDATE, code);
});

// Handle language changes
socket.on(Event.Collaboration.LANGUAGE_CHANGE, (data) => {
socket.on(Event.Language.CHANGE, (data) => {
const room = data.room;
const language = data.updatedLanguage;

io.to(room).emit(Event.Collaboration.LANGUAGE_UPDATE, language);
io.to(room).emit(Event.Language.UPDATE, language);
});

// Handle question changes
socket.on(Event.Question.QUESTION_CHANGE, (data) => {
// Handle code execution result changes
socket.on(Event.Result.CHANGE, (data) => {
const room = data.room;
const question = data.question;
const result = data.updatedResult;

io.to(room).emit(Event.Question.QUESTION_UPDATE, question);
io.to(room).emit(Event.Result.UPDATE, result);
});

// Handle execution button disabling when code is executing
socket.on(Event.Button.DISABLE_EXEC, (data) => {
const room = data.roomId;
const btnState = data.isButtonDisabled;

io.to(room).emit(Event.Button.UPDATE_EXEC, btnState);
});

// Handle mouse position changes
socket.on(Event.Collaboration.MOUSE_POSITION, (data) => {
socket.on(Event.Mouse.POSITION, (data) => {
const room = data.room;
const user = data.user;
const jwt = data.jwt;
const mousePosition = data.position;
const message = {user: user, jwt: jwt, position: mousePosition};
const message = { user: user, jwt: jwt, position: mousePosition };

io.to(room).emit(Event.Collaboration.MOUSE_POSITION, message);
io.to(room).emit(Event.Mouse.POSITION, message);
});


// Handle mouse leave
socket.on(Event.Collaboration.MOUSE_LEAVE, (data) => {
socket.on(Event.Mouse.LEAVE, (data) => {
const room = data.room;
const jwt = data.jwt;

io.to(room).emit(Event.Collaboration.MOUSE_LEAVE, jwt);
io.to(room).emit(Event.Mouse.LEAVE, jwt);
});

// Handle disconnects
socket.on(Event.DISCONNECT, () => {
logger.log('A user disconnected');
// Handle chat messages
socket.on(Event.Communication.CHAT_SEND, (data) => {
const room = data.room;
const message = data.message;

io.to(room).emit(Event.Communication.CHAT_RECEIVE, message);
});
});

Expand Down
44 changes: 28 additions & 16 deletions Collaboration/src/constants/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
const Event = {
CONNECTION: 'connection',
DISCONNECT: 'disconnect',
JOIN_ROOM: 'join-room',
LEAVE_ROOM: 'leave-room',
Socket: {
CONNECT: 'connection',
DISCONNECT: 'disconnect',
JOIN_ROOM: 'join-room',
LEAVE_ROOM: 'leave-room',
},
Question: {
QUESTION_CHANGE: 'question-change',
QUESTION_UPDATE: 'question-update',
},
Collaboration: {
CODE_CHANGE: 'code-change',
CODE_UPDATE: 'code-update',
LANGUAGE_CHANGE: 'language-change',
LANGUAGE_UPDATE: 'language-update',
MOUSE_POSITION: 'mouse-position',
MOUSE_LEAVE: 'mouse-leave',
RESULT_CHANGE: 'result-change',
RESULT_UPDATE: 'result-update',
CHANGE: 'question-change',
UPDATE: 'question-update',
},
Code: {
CHANGE: 'code-change',
UPDATE: 'code-update',
},
Language: {
CHANGE: 'language-change',
UPDATE: 'language-update',
},
Result: {
CHANGE: 'result-change',
UPDATE: 'result-update',
},
Button: {
DISABLE_EXEC: 'disable-exec-button',
UPDATE_EXEC: 'update-exec-button',
},
Mouse: {
POSITION: 'mouse-position',
LEAVE: 'mouse-leave',
},
Communication: {
CHAT_SEND: 'chat-send',
Expand Down
8 changes: 7 additions & 1 deletion Execution/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ FROM node:18
# Create app directory to hold application code inside the image.
WORKDIR /usr/src/app

# Install Python3 and Java.
RUN apt-get update && apt-get install -y \
python3 \
openjdk-17-jdk-headless \
curl

# The image comes with Node.js and NPM already installed.
# We just need to install the rest of our dependencies.
# Copy package.json and package-lock.json to the app directory on the image.
Expand All @@ -19,7 +25,7 @@ RUN npm install
COPY . .

# Expose ports so they can be mapped by Docker daemon.
# Should expose ${AUTH_PORT}
# Should expose ${EXECUTION_PORT}
EXPOSE 9001

# Define the command to run your app using CMD which defines your runtime.
Expand Down
106 changes: 33 additions & 73 deletions Execution/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Execution/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.5.1",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2"
"express": "^4.18.2",
"tree-kill": "^1.2.2",
"uuidv4": "^6.2.13"
},
"devDependencies": {
"nodemon": "^3.0.1"
Expand Down
Loading

0 comments on commit ee79575

Please sign in to comment.