Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate collaboration service with matching service #60

Merged
merged 94 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
e074bf0
Merge pull request #12 from CS3219-AY2425S1/merged-user-question
AndrewOng2066 Oct 6, 2024
03e8cd4
Merge pull request #13 from CS3219-AY2425S1/main
AndrewOng2066 Oct 10, 2024
d8c3500
Solve the input box css in the signup page
Oct 11, 2024
024e14b
Create pages for matching services
Oct 13, 2024
23e4e87
Functions for matching-service
Oct 15, 2024
1761e30
Merge pull request #43 from AndrewOng2066/matching-service-RabbitMQ-T…
AndrewOng2066 Oct 15, 2024
3e75831
Comment the code
Oct 15, 2024
74a03c5
Implement retry matching function in matching-service
Oct 15, 2024
a39f56b
Merge pull request #44 from AndrewOng2066/matching-service-RabbitMQ-T…
AndrewOng2066 Oct 15, 2024
69e1bba
Add logged in route restriction
iynixil Oct 16, 2024
481fd2f
Add cancel matching functionality
iynixil Oct 16, 2024
1b70d27
Add username when adding message to message queue, display username i…
iynixil Oct 16, 2024
534c64b
Update login page css to be contained within login page
iynixil Oct 16, 2024
2322b4a
Add id tag in matching select page
iynixil Oct 16, 2024
1e472fa
Fix css import in match finding page
iynixil Oct 16, 2024
0551810
Adjust match finding loading text height
iynixil Oct 16, 2024
fe1d6dd
Add navbar to matching selection page
iynixil Oct 16, 2024
472d2bf
Add homepage component and styling
iynixil Oct 16, 2024
f6f5668
Configure routing to homepage in routes, navbar, login and logout pages
iynixil Oct 16, 2024
ef2e6e4
Merge pull request #45 from iynixil/matching-service
iynixil Oct 16, 2024
82189a1
Merge pull request #14 from CS3219-AY2425S1/matching-service-xy
AndrewOng2066 Oct 16, 2024
b5f93db
Remove unnecessary code in cancel matching functionality
iynixil Oct 16, 2024
3573680
Merge pull request #46 from iynixil/matching-service
iynixil Oct 16, 2024
2955f72
Edit match found message
iynixil Oct 16, 2024
264934a
Add options for retrying matching
iynixil Oct 16, 2024
b24baa5
Update cancel match functionality, add button to go back to criteria …
iynixil Oct 16, 2024
ee2efa1
Merge pull request #47 from iynixil/matching-service
iynixil Oct 16, 2024
be6177b
Fix message shown to user when matching is cancelled
iynixil Oct 16, 2024
23240a8
Merge pull request #15 from CS3219-AY2425S1/matching-service-xy
AndrewOng2066 Oct 17, 2024
c85c0a6
Merge branch 'matching-service-xy' into matching-service-tsu
tsulim Oct 17, 2024
7528445
Fix the priority bug for matching service
Oct 17, 2024
ddb5e23
Merge pull request #48 from AndrewOng2066/matching_xy
AndrewOng2066 Oct 17, 2024
9c5b449
Add navigation on backtracking and allow user to stay on match found …
iynixil Oct 17, 2024
6d9e0f1
Merge remote-tracking branch 'upstream/matching_Andrew' into matching…
iynixil Oct 17, 2024
99951e8
Extract rabbitMQ from `matchingController.js`
tsulim Oct 17, 2024
a750081
Merge remote-tracking branch 'upstream/matching-service-tsu' into mat…
iynixil Oct 17, 2024
941a376
Update matching controller with updated connection modifications
iynixil Oct 17, 2024
87296f9
Add persistent storage for `match`
tsulim Oct 17, 2024
e5813fe
Merge remote-tracking branch 'upstream/matching-service-tsu' into mat…
iynixil Oct 17, 2024
313d590
Merge remote-tracking branch 'upstream/matching-service-xy' into matc…
tsulim Oct 17, 2024
1e854a9
Modify default page to home page
tsulim Oct 17, 2024
e204223
Update queuing priority to only check any if user has indicated any
iynixil Oct 17, 2024
07a78f7
Merge remote-tracking branch 'upstream/matching-service-xy' into matc…
tsulim Oct 17, 2024
7b20c8f
Fix any matching functionality
iynixil Oct 17, 2024
13107ad
Merge remote-tracking branch 'upstream/matching-service-xy' into matc…
tsulim Oct 17, 2024
b11ac6c
Shift `firebase.js` and `rabbitMQ.js` into `config` folder
tsulim Oct 17, 2024
c7c101b
Extract socket handler from `matchingController.js` and rename to `qu…
tsulim Oct 17, 2024
6441348
Remove `matchingRoute.js`
tsulim Oct 17, 2024
ad4d1c8
Remove redundant lines and update path
tsulim Oct 17, 2024
dac2a3f
Fix self-matching in 'any' queues
iynixil Oct 18, 2024
5afbf85
Merge remote-tracking branch 'upstream/matching-service-tsu' into mat…
iynixil Oct 18, 2024
897df1a
Fix logout delay
iynixil Oct 18, 2024
d4009a7
Merge pull request #16 from CS3219-AY2425S1/matching-service-xy
AndrewOng2066 Oct 18, 2024
5104ed7
Fix backtrack exit queue
iynixil Oct 18, 2024
c89a9f7
Modify the fields being stored for `match`
tsulim Oct 18, 2024
6240c0b
Merge remote-tracking branch 'upstream/matching-service-xy' into matc…
tsulim Oct 18, 2024
235d06d
Changing the priority level setting
Oct 18, 2024
09ec143
Implement full priority level setting
Oct 18, 2024
ea91785
Merge pull request #50 from AndrewOng2066/matching_xy
AndrewOng2066 Oct 18, 2024
e9ea37f
fix the matching between any and any bug
Oct 19, 2024
43a8513
Merge branch 'matching-service-tsu' into matching_xy
AndrewOng2066 Oct 19, 2024
7c4767b
Merge pull request #51 from AndrewOng2066/matching_xy
AndrewOng2066 Oct 19, 2024
af1add9
Fix the priority matching bug
Oct 19, 2024
0be9e1d
Merge branch 'matching_xy' of https://github.com/AndrewOng2066/cs3219…
Oct 19, 2024
7f5b907
Merge pull request #52 from AndrewOng2066/matching_xy
AndrewOng2066 Oct 19, 2024
ec2a450
Change loading animation and cancel match if leaving finding match page
iynixil Oct 19, 2024
b820909
Merge remote-tracking branch 'upstream/matching_Andrew' into matching…
iynixil Oct 19, 2024
cebf8ed
Fix leave page event cancel matching
iynixil Oct 19, 2024
0ca17c7
Remove unnecessary comment
Oct 19, 2024
fe9e95e
Remove unnecessary comment
Oct 19, 2024
261a2bb
Remove debugging comments in code
iynixil Oct 19, 2024
838614a
Add docker containerization files for matching service
iynixil Oct 20, 2024
73851af
Edit cancel matching debugging message
iynixil Oct 20, 2024
cdfa790
Update finding match functionality to let user requeue on page refresh
iynixil Oct 20, 2024
f64a29a
Merge branch 'matching_final' into matching-service-xy
AndrewOng2066 Oct 20, 2024
88eca8d
Merge pull request #18 from CS3219-AY2425S1/matching-service-xy
AndrewOng2066 Oct 20, 2024
1267f12
Add another hostname to rabbitmq connection config
iynixil Oct 20, 2024
2919764
Remove unnecessary imports and fix indentations
iynixil Oct 20, 2024
8ea938a
Merge remote-tracking branch 'upstream/matching-service-xy' into matc…
iynixil Oct 20, 2024
e964829
Update timer for rabbitmq, frontend to 60 seconds
iynixil Oct 20, 2024
6b1bae0
Change log messages for successful match
iynixil Oct 20, 2024
1e72853
Merge pull request #19 from CS3219-AY2425S1/matching-service-xy
AndrewOng2066 Oct 20, 2024
bb834c9
Print the number of users in the queue when cancelling the match
Oct 20, 2024
8065040
Merge pull request #55 from AndrewOng2066/matching_final
AndrewOng2066 Oct 20, 2024
8691d28
Merge branch 'matching-service-xy' into collaboration-service-tsu
tsulim Oct 20, 2024
d1f06ed
Remove duplicate route
tsulim Oct 20, 2024
ff93c6e
Remove unused rabbitmq
tsulim Oct 23, 2024
f0dd450
Remove temporary match files used for collab
tsulim Oct 23, 2024
b73c52c
Combine `socket.js` contents
tsulim Oct 23, 2024
8adc9c3
Update `.env.sample` files
tsulim Oct 23, 2024
4692a56
Rename `HOSTNAME` to `RABBIT_HOSTNAME` in `rabbitMQ.js`
tsulim Oct 23, 2024
25e7379
Add `useSessionStorage`
tsulim Oct 23, 2024
81a11bf
Combine `usePersistState` into `useLocalStorage`
tsulim Oct 23, 2024
51134b9
Integrate `collaboration-service` with `matching-service`
tsulim Oct 23, 2024
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
9 changes: 4 additions & 5 deletions backend/collaboration-service/.env.sample
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Port numbers
PORT = 5003
SOCKET_PORT = 8000
PORT=5003

# Firebase
PRIVATE_KEY =
PRIVATE_KEY=

# Rabbit MQ
RABBIT_PASSWORD =
RABBIT_PASSWORD=

# Service URL
URL_QUESTION_SERVICE =
URL_QUESTION_SERVICE=
46 changes: 0 additions & 46 deletions backend/collaboration-service/controller/matchController.js

This file was deleted.

25 changes: 14 additions & 11 deletions backend/collaboration-service/handler/socketHandler.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
// Author(s): Xue Ling, Xiu Jia
const { createMatch } = require("../controller/matchController");
const { getRandomQuestion, getComplexity } = require("../service/questionService");

let socketMap = {};

const handleSocketIO = (io) => {
io.on("connection", (socket) => {
console.log(`A user connected with socket ID: ${socket.id}`);

// Temporary in here because no match service right now
socket.on("match_found", async (data) => {
socket.on("createSocketRoom", async ({ data, id, currentUser }) => {
// Store the socket id for the user
socketMap[currentUser] = socket.id;

const { user1, user2 } = data;
const { roomId } = await createMatch(user1, user2);

const complexity = getComplexity(user1, user2);

const questionData = await getRandomQuestion(user1.category, complexity);

socket.join(roomId);
socket.join(id);

console.log(`User with socket ID ${socket.id} joined room with ID ${id}`);

socket.emit("readyForCollab", {
roomId,
socket.emit("readyForCollab", {
id: id,
user1,
user2,
questionData
});
console.log(`User with socket ID ${socket.id} joined room with ID ${roomId}`);
});
});

socket.on("sendContent", ({ roomId, content }) => {
socket.to(roomId).emit("receiveContent", { content });
socket.on("sendContent", ({ id, content }) => {
socket.to(id).emit("receiveContent", { content: content });
});

// Handle disconnection
Expand Down
5 changes: 2 additions & 3 deletions backend/collaboration-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ require("dotenv").config();

const http = require("http");
const { Server } = require("socket.io");
const port = process.env.PORT; // 5003
const socketPort = process.env.SOCKET_PORT; // 8000
const port = process.env.PORT || 5003;

// Import the socket handler
const { handleSocketIO } = require("./handler/socketHandler.js");
Expand All @@ -13,7 +12,7 @@ const { handleSocketIO } = require("./handler/socketHandler.js");
const server = http.createServer();

// Initialize the Socket.IO server
const io = new Server(socketPort, {
const io = new Server(server, {
cors: {
origin: "*", // Allow all origins, adjust as needed
methods: ["GET", "POST"],
Expand Down
4 changes: 2 additions & 2 deletions backend/collaboration-service/service/questionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const url_question_service = process.env.URL_QUESTION_SERVICE;
const getRandomQuestion = async (category, complexity = "") => {
const qnURL = `${url_question_service}/random/${category}/${complexity}`

console.log("qnURL", qnURL);
// console.log("qnURL", qnURL);
const response = await fetch(qnURL).then((response) => {
return response.json();
});

console.log("response", response);
// console.log("response", response);
return response;
};

Expand Down
2 changes: 2 additions & 0 deletions backend/matching-service/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
9 changes: 9 additions & 0 deletions backend/matching-service/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Port numbers
PORT=5002

# Firebase
PRIVATE_KEY=

# Rabbit MQ
RABBIT_HOSTNAME=
RABBIT_PASSWORD=
20 changes: 20 additions & 0 deletions backend/matching-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use an official Node.js runtime as a parent image
FROM node:20-alpine

# Set the working directory in the container
WORKDIR /app

# Copy package.json and package-lock.json
COPY package*.json ./

# Install any dependencies
RUN npm install

# Bundle app source inside the Docker image
COPY . .

# Make port 5001 available to the world outside this container
EXPOSE 5002

# Define the command to run your app
CMD ["npm", "start"]
24 changes: 24 additions & 0 deletions backend/matching-service/config/firebase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Author(s): Andrew, Xiu Jia
require("dotenv").config();
const admin = require("firebase-admin");

const firebaseConfig = {
type: "service_account",
project_id: "cs3219-d4ee1",
private_key_id: "d9899e20a23a397cdce523437f42d50696aede61",
private_key: process.env.PRIVATE_KEY,
client_email: "firebase-adminsdk-hba0d@cs3219-d4ee1.iam.gserviceaccount.com",
client_id: "106098472779235960036",
auth_uri: "https://accounts.google.com/o/oauth2/auth",
token_uri: "https://oauth2.googleapis.com/token",
auth_provider_x509_cert_url: "https://www.googleapis.com/oauth2/v1/certs",
client_x509_cert_url: "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-hba0d%40cs3219-d4ee1.iam.gserviceaccount.com",
universe_domain: "googleapis.com"
};

admin.initializeApp({
credential: admin.credential.cert(firebaseConfig)
});
const db = admin.firestore();

module.exports = db;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const amqp = require('amqplib');

const rabbitSettings = {
protocol: 'amqp',
hostname: process.env.HOSTNAME || 'localhost',
hostname: `rabbitmq` || process.env.RABBIT_HOSTNAME || 'localhost',
port: 5672,
username: 'guest',
password: process.env.RABBIT_PASSWORD,
Expand Down
46 changes: 46 additions & 0 deletions backend/matching-service/controller/matchController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Author(s): Calista, Xiu Jia, Xue Ling
const db = require("../config/firebase");
const matchCollection = db.collection("matches");

/**
* POST /add
*
* Creates match and stores in firebase
*
* Responses:
* - 500: Server error if something goes wrong while fetching data.
*/
const createMatch = async (user1, user2) => {
try {
const matchJson = {
user1: {
email: user1.email,
category: user1.topic,
complexity: user1.difficultyLevel,
isAny: user1.isAny
},
user2: {
email: user2.email,
category: user2.topic,
complexity: user2.difficultyLevel,
isAny: user2.isAny
},
createdAt: new Date().toLocaleString("en-SG")
};

const matchRef = await matchCollection.doc();

await matchRef.set(matchJson);

// Get match id
const id = matchRef.id;

return { status: 200, msg: "Match created successfully", matchData: matchJson, id };
} catch (error) {
return { status: 500, error: error.message };
}
}

module.exports = {
createMatch
};
Loading