Skip to content

Commit 66d6b0e

Browse files
authored
Merge pull request #123 from ruiqi7/refactor/matching-service
Refactor matching service and add docs for socket events
2 parents 0d744bf + db94a59 commit 66d6b0e

36 files changed

+277
-336
lines changed

backend/collab-service/README.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,40 @@
3535
- You should open 2 tabs on Postman to simulate 2 users in the Collab Service.
3636

3737
- Select the `Socket.IO` option and set URL to `http://localhost:3003`. Click `Connect`.
38-
![image1.png](docs/image1.png)
38+
39+
![image1.png](./docs/images/postman-setup1.png)
3940

4041
- Add the following events in the `Events` tab and listen to them.
41-
![image2.png](docs/image2.png)
4242

43-
- To send a message, go to the `Message` tab and ensure that your message is being parsed as `JSON`.
44-
![image3.png](docs/image3.png)
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.
4550

46-
- In the `Event name` input, input the correct event name. Click on `Send` to send a message.
47-
![image4.png](docs/image4.png)
51+
![image4.png](./docs/images/postman-setup4.png)
4852

4953
## Events Available
5054

51-
| Event Name | Description | Parameters | Response Event |
52-
| -------------- | --------------------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
53-
| **join** | Joins a collaboration room. | `roomId` (string): ID of the room. | **room_full:** Notify the user if the room is full (only 2 users allowed).<br/>**connected:** Notify the user if successfully connected.<br/>**new_user_connected:** Notify the other user if a new user joins the room. |
54-
| **change** | Sends updated code to other user. | `roomId` (string): ID of the room.<br/>`code` (string): Updated code content. | **code_change:** Notify the other user with the updated code content. |
55-
| **leave** | Leaves the collaboration room. | `roomId` (string): ID of the room. | **partner_left:** Notify the other user when one leaves the room. |
56-
| **disconnect** | Disconnects from the server. | None | **partner_disconnected:** Notify the other user when one is disconnected. |
55+
| Event Name | Description | Parameters | Response Event |
56+
| ------------------------- | ------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
57+
| **join** | Joins a collaboration room | `uid` (string): ID of the user. <br><br> `roomId` (string): ID of the room. | **room_ready:** Notify both users in the room that the room is ready (when exactly 2 users have joined). |
58+
| **init_document** | Initializes the server document for the room | `roomId` (string): ID of the room. <br><br> `template` (string): Document template. <br><br> `uid1` (string): ID of the first user in the room. <br><br> `uid2` (string): ID of the second user in the room. <br><br> `language` (string): Programming language selected by both users. <br><br> `qnId` (string): ID of the selected question. <br><br> `qnTitle` (string): Title of the selected question. | **document_ready:** Notify both users in the room that the server document is ready. |
59+
| **update_request** | Sends a document update | `roomId` (string): ID of the room. <br><br> `update` (`Uint8Array`): Document update. | **updateV2:** Sends the updated server document to both users in the room. <br><br> **document_not_found:** Notify both users in the room that the server document was not found. |
60+
| **update_cursor_request** | Sends a cursor update | `roomId` (string): ID of the room. <br><br> `cursor` (`Cursor`): Cursor details. | **update_cursor:** Notify the partner user of the cursor update. |
61+
| **leave** | Leaves the collaboration room | `uid` (string): ID of the user. <br><br> `roomId` (string): ID of the room. <br><br> `isPartnerNotified` (boolean): Whether the partner user has been notified that this user has left the room. | **partner_disconnected:** Notify the partner user that this user has disconnected from the collaboration session. |
62+
| **end_session_request** | Sends a request to end the collaboration session | `roomId` (string): ID of the room. <br><br> `sessionDuration` (number): Duration of the collaboration session. | **end_session:** Notify both users in the room that the collaboration session has ended. |
63+
| **reconnect_request** | Reconnects to the collaboration session | `roomId` (string): ID of the room. | None |
64+
65+
### Event Parameter Types
66+
67+
```typescript
68+
interface Cursor {
69+
uid: string;
70+
username: string;
71+
from: number;
72+
to: number;
73+
}
74+
```
-20.9 KB
Binary file not shown.
-27.8 KB
Binary file not shown.
-14.6 KB
Binary file not shown.
File renamed without changes.
33.5 KB
Loading
26.5 KB
Loading
23.7 KB
Loading

backend/collab-service/package-lock.json

Lines changed: 0 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/collab-service/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
"express": "^4.21.1",
2424
"redis": "^4.7.0",
2525
"socket.io": "^4.8.1",
26-
"swagger-ui-express": "^5.0.1",
2726
"y-protocols": "^1.0.6",
28-
"yaml": "^2.6.0",
2927
"yjs": "^13.6.20"
3028
},
3129
"devDependencies": {

0 commit comments

Comments
 (0)