avallef commited on
Commit
61ffaad
·
1 Parent(s): ba51620

Added set_username

Browse files
server/README.md CHANGED
@@ -38,6 +38,22 @@ Room messages are sent to everyone in a room
38
  "route": "test_connection"
39
  }
40
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  **Type:** `server -> client <private>`
43
  **Response:**
@@ -57,7 +73,8 @@ Room messages are sent to everyone in a room
57
  ```typescript
58
  {
59
  "route": "join_room",
60
- "roomId"?: string; // Room Id, optional
 
61
  }
62
  ```
63
 
 
38
  "route": "test_connection"
39
  }
40
  ```
41
+ ### Set Username
42
+ **Type:** `client -> server`
43
+ **Payload:**
44
+ ```typescript
45
+ {
46
+ "route": "set_username",
47
+ "username": string,
48
+ }
49
+ ```
50
+ **Type:** `server -> client <private>`
51
+ **Payload:**
52
+ ```typescript
53
+ {
54
+ "message": "set_username_response",
55
+ "status": string,
56
+ }
57
 
58
  **Type:** `server -> client <private>`
59
  **Response:**
 
73
  ```typescript
74
  {
75
  "route": "join_room",
76
+ "roomId"?: string, // Room Id, optional
77
+ "username"?: string,
78
  }
79
  ```
80
 
server/src/socket/routes/get_rooms.ts CHANGED
@@ -1,14 +1,8 @@
1
  import { z } from "zod";
2
  import { Context, Route } from "../hapticLinkServer";
3
 
4
- interface GetRoomsPayload {
5
- roomId?: string;
6
- username?: string;
7
- }
8
- const GetRoomsSchema = z.object({
9
- roomId: z.string().optional(),
10
- username: z.string().optional(),
11
- })
12
 
13
  interface RoomData {
14
  id: string;
 
1
  import { z } from "zod";
2
  import { Context, Route } from "../hapticLinkServer";
3
 
4
+ interface GetRoomsPayload {}
5
+ const GetRoomsSchema = z.object({})
 
 
 
 
 
 
6
 
7
  interface RoomData {
8
  id: string;
server/src/socket/routes/set_username.ts ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { z } from "zod";
2
+ import { Context, Route } from "../hapticLinkServer";
3
+
4
+ interface SetUsernamePayload {
5
+ username: string;
6
+ }
7
+ const SetUsernameSchema = z.object({
8
+ username: z.string(),
9
+ })
10
+
11
+ interface RoomData {
12
+ id: string;
13
+ userCount: number;
14
+ }
15
+
16
+ const SetUsernameRoute: Route<SetUsernamePayload> = {
17
+ name: "get_rooms",
18
+ handler: function(ctx: Context<SetUsernamePayload>) {
19
+
20
+ ctx.user.username = ctx.payload.username;
21
+
22
+ return ctx.ws.send(JSON.stringify({
23
+ "message": "set_username_response",
24
+ "status": "success"
25
+ }))
26
+ },
27
+ schema: SetUsernameSchema,
28
+ }
29
+
30
+ export default SetUsernameRoute;