|
35 | 35 | - You should open 2 tabs on Postman to simulate 2 users in the Collab Service.
|
36 | 36 |
|
37 | 37 | - Select the `Socket.IO` option and set URL to `http://localhost:3003`. Click `Connect`.
|
38 |
| -  |
| 38 | + |
| 39 | +  |
39 | 40 |
|
40 | 41 | - Add the following events in the `Events` tab and listen to them.
|
41 |
| -  |
42 | 42 |
|
43 |
| - - To send a message, go to the `Message` tab and ensure that your message is being parsed as `JSON`. |
44 |
| -  |
| 43 | +  |
| 44 | + |
| 45 | + - In the `Headers` tab, add a valid JWT token in the `Authorization` header. |
| 46 | + |
| 47 | +  |
| 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. |
45 | 50 |
|
46 |
| - - In the `Event name` input, input the correct event name. Click on `Send` to send a message. |
47 |
| -  |
| 51 | +  |
48 | 52 |
|
49 | 53 | ## Events Available
|
50 | 54 |
|
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 | +``` |
0 commit comments