Skip to content

Commit e5be523

Browse files
committed
Update readme
1 parent 81a87f8 commit e5be523

File tree

9 files changed

+62
-9
lines changed

9 files changed

+62
-9
lines changed

backend/matching-service/README.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,55 @@
2828

2929
## After running
3030

31-
1. To view Matching Service documentation, go to http://localhost:3002/docs.
31+
1. Using applications like Postman, you can interact with the Matching Service on port 3002. If you wish to change this, please update the `.env` file.
3232

33-
2. Using applications like Postman, you can interact with the Matching Service on port 3002. If you wish to change this, please update the `.env` file.
33+
2. Setting up Socket.IO connection on Postman:
34+
35+
- You should open 2 tabs on Postman to simulate 2 users in the Matching Service.
36+
37+
- Select the `Socket.IO` option and set URL to `http://localhost:3002`. Click `Connect`.
38+
39+
![image1.png](./docs/images/postman-setup1.png)
40+
41+
- Add the following events in the `Events` tab and listen to them.
42+
43+
![image2.png](./docs/images/postman-setup2.png)
44+
45+
- In the `Headers` tab, add a valid JWT token in the `Authorization` header.
46+
47+
![image3.png](./docs/images/postman-setup3.png)
48+
49+
- In the `Message` tab, select `JSON` in the bottom left dropdown to ensure that your message is being parsed correctly. In the `Event name` input field, enter the name of the event you would like to send a message to. Click on `Send` to send a message.
50+
51+
![image4.png](./docs/images/postman-setup4.png)
52+
53+
## Events Available
54+
55+
| Event Name | Description | Parameters | Response Event |
56+
| ------------------------- | ----------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
57+
| **user_connected** | User joins the matching process | `uid` (string): ID of the user. | None |
58+
| **user_disconnected** | User leaves the matching process | `uid` (string): ID of the user. | **match_unsuccessful**: If the user left during the match offer phase, notify the partner user that the match was unsuccessful |
59+
| **match_request** | Sends a match request | `matchRequest` (`MatchRequest`): Match request details. <br><br> `callback` (`(requested: boolean) => void`): To check if the match request was successfully sent. | **match_request_exists**: Notify the user that only one match request can be processed at a time. <br><br> **match_request_error**: Notify the user that the match request failed to send. |
60+
| **match_cancel_request** | Cancels the match request | `uid` (string): ID of the user. | None |
61+
| **match_accept_request** | Accepts the match request | `uid` (string): ID of the user. | **match_successful**: If both users have accepted the match offer, notify them that the match is successful. |
62+
| **match_decline_request** | Declines the match request | `uid` (string): ID of the user. <br><br> `matchId` (string): ID of the user. <br><br> `isTimeout` (boolean): Whether the match was declined due to match offer timeout. | **match_unsuccessful**: If the match was not declined due to match offer timeout (was explicitly rejected by the user), notify the partner user that the match is unsuccessful. |
63+
| **rematch_request** | Sends a rematch request | `matchId` (string): ID of the match. <br><br> `partnerId` (string): ID of the partner user. <br><br> `rematchRequest` (`MatchRequest`): Rematch request details. <br><br> `callback` (`(requested: boolean) => void`): To check if the rematch request was successfully sent. | **match_request_error**: Notify the user that the rematch request failed to send. |
64+
| **match_end_request** | User leaves the matching process upon leaving the collaboration session | `uid` (string): ID of the user. <br><br> `matchId` (string): ID of the match. | None |
65+
66+
### Event Parameter Types
67+
68+
```typescript
69+
interface MatchUser {
70+
id: string;
71+
username: string;
72+
profile?: string;
73+
}
74+
75+
interface MatchRequest {
76+
user: MatchUser;
77+
complexity: string;
78+
category: string;
79+
language: string;
80+
timeout: number;
81+
}
82+
```
48.2 KB
Loading
34.1 KB
Loading
29.2 KB
Loading
25.2 KB
Loading

backend/matching-service/src/handlers/websocketHandler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { sendToProducer } from "../config/rabbitmq";
1515
enum MatchEvents {
1616
// Receive
1717
MATCH_REQUEST = "match_request",
18-
CANCEL_MATCH_REQUEST = "cancel_match_request",
18+
MATCH_CANCEL_REQUEST = "match_cancel_request",
1919
MATCH_ACCEPT_REQUEST = "match_accept_request",
2020
MATCH_DECLINE_REQUEST = "match_decline_request",
2121
REMATCH_REQUEST = "rematch_request",
@@ -114,7 +114,7 @@ export const handleWebsocketMatchEvents = (socket: Socket) => {
114114
}
115115
);
116116

117-
socket.on(MatchEvents.CANCEL_MATCH_REQUEST, (uid: string) => {
117+
socket.on(MatchEvents.MATCH_CANCEL_REQUEST, (uid: string) => {
118118
userConnections.delete(uid);
119119
});
120120

@@ -154,7 +154,7 @@ export const handleWebsocketMatchEvents = (socket: Socket) => {
154154
matchId: string,
155155
partnerId: string,
156156
rematchRequest: MatchRequest,
157-
callback: (result: boolean) => void
157+
callback: (requested: boolean) => void
158158
) => {
159159
const matchDeleted = handleMatchDelete(matchId);
160160
if (matchDeleted) {
@@ -233,7 +233,7 @@ const endMatchOnUserDisconnect = (socket: Socket, uid: string) => {
233233
if (matchId) {
234234
const matchDeleted = handleMatchDelete(matchId);
235235
if (matchDeleted) {
236-
socket.to(matchId).emit(MatchEvents.MATCH_UNSUCCESSFUL); // on matching page
236+
socket.to(matchId).emit(MatchEvents.MATCH_UNSUCCESSFUL);
237237
}
238238
}
239239
};

frontend/src/components/CollabSessionControls/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const CollabSessionControls: React.FC = () => {
7070
collabSocket.off(CollabEvents.END_SESSION);
7171
collabSocket.off(CollabEvents.PARTNER_DISCONNECTED);
7272
};
73+
// eslint-disable-next-line react-hooks/exhaustive-deps
7374
}, []);
7475

7576
useEffect(() => {
@@ -91,6 +92,7 @@ const CollabSessionControls: React.FC = () => {
9192
if (qnHistoryId) {
9293
setStopTime(false);
9394
}
95+
// eslint-disable-next-line react-hooks/exhaustive-deps
9496
}, [qnHistoryId]);
9597

9698
useEffect(() => {

frontend/src/contexts/MatchContext.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type MatchCriteria = {
3535
enum MatchEvents {
3636
// Send
3737
MATCH_REQUEST = "match_request",
38-
CANCEL_MATCH_REQUEST = "cancel_match_request",
38+
MATCH_CANCEL_REQUEST = "match_cancel_request",
3939
MATCH_ACCEPT_REQUEST = "match_accept_request",
4040
MATCH_DECLINE_REQUEST = "match_decline_request",
4141
REMATCH_REQUEST = "rematch_request",
@@ -365,7 +365,7 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
365365
appNavigate(MatchPaths.HOME);
366366
return;
367367
case MatchPaths.MATCHING:
368-
matchSocket.emit(MatchEvents.CANCEL_MATCH_REQUEST, matchUser?.id);
368+
matchSocket.emit(MatchEvents.MATCH_CANCEL_REQUEST, matchUser?.id);
369369
appNavigate(MatchPaths.HOME);
370370
return;
371371
case MatchPaths.MATCHED:
@@ -446,7 +446,7 @@ const MatchProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
446446
};
447447

448448
const matchingTimeout = () => {
449-
matchSocket.emit(MatchEvents.CANCEL_MATCH_REQUEST, matchUser?.id);
449+
matchSocket.emit(MatchEvents.MATCH_CANCEL_REQUEST, matchUser?.id);
450450
appNavigate(MatchPaths.TIMEOUT);
451451
};
452452

frontend/src/pages/NewQuestion/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable react-refresh/only-export-components */
2+
13
import { useEffect, useState, useReducer } from "react";
24
import { useNavigate } from "react-router-dom";
35
import {

0 commit comments

Comments
 (0)