Anne Lefebvre commited on
Commit
2c59077
·
unverified ·
1 Parent(s): c4ca913

Corrected documentations

Browse files
Files changed (1) hide show
  1. server/README.md +94 -71
server/README.md CHANGED
@@ -1,6 +1,8 @@
1
  # HapticTouch Server
2
 
3
- ## Instructions
 
 
4
 
5
  ```
6
  git clone https://github.com/AnujPanthri/HapticLink
@@ -15,69 +17,77 @@ To build use:
15
  To run use:
16
  `npm start`
17
 
18
- ## Documentation
19
 
20
  Both HTTP and WebSocket server are running on the same port
21
 
22
- # WORK IN PROGRESS
23
-
24
- ## WebSocket API
25
 
26
- WebSockets payload will be in JSON and require atleast a `route` property
27
  Types can be `client -> server`, `server -> client <private | room>`.
28
- Private messages are sent directly to client
29
- Room messages are sent to everyone in a room
30
 
31
- ## Test Connection
32
 
33
  **Type:** `client -> server`
34
  **Payload:**
35
 
36
  ```typescript
37
  {
38
- "route": "test_connection"
39
  }
40
  ```
41
 
42
  **Type:** `server -> client <private>`
43
- **Response:**
44
 
45
  ```typescript
46
  {
47
- "message": "test_connection_response",
 
 
 
 
 
 
48
  }
49
  ```
50
 
51
- ## Set Username
52
 
53
  **Type:** `client -> server`
 
54
  **Payload:**
55
 
56
  ```typescript
57
  {
58
- "route": "set_username",
59
- "username": string,
 
60
  }
61
  ```
62
 
63
  **Type:** `server -> client <private>`
64
- **Payload:**
65
 
66
  ```typescript
67
  {
68
- "message": "set_username_response",
69
  "status": string,
70
  }
71
  ```
72
 
73
- ## Get User Info
74
 
75
  **Type:** `client -> server`
 
76
  **Payload:**
77
 
78
  ```typescript
79
  {
80
- "route": "get_user_info",
 
81
  }
82
  ```
83
 
@@ -86,50 +96,52 @@ Room messages are sent to everyone in a room
86
 
87
  ```typescript
88
  {
89
- "message": "set_username_response",
90
- "status": string,
91
- "user": {
92
- "username": string,
93
- "id": string,
94
- "currentRoom": string,
95
- }
96
  }
97
  ```
98
 
99
- ## Join Room
100
 
101
- **Type:** `client -> server`
102
- **Description:** Used to enter a room. Join an existing room by including roomId, or if room doesn't exist, create one with that roomId
103
  **Payload:**
104
 
105
  ```typescript
106
  {
107
- "route": "join_room",
108
- "roomId"?: string, // Room Id, optional
109
- "username"?: string,
110
- }
111
- ```
112
-
113
- **Type:** `server -> client <private>`
114
- **Payload (If error):**
115
-
116
- ```typescript
117
- {
118
- "message": "enter_room_response",
119
- "status": string,
120
  }
121
  ```
122
 
123
- ## Leave Room
124
 
125
  **Type:** `client -> server`
126
- **Description:** Used to enter a room.
127
  **Payload:**
128
 
129
  ```typescript
130
  {
131
- "route": "leave_room",
132
- "roomId": string; // Room Id, optional
 
 
 
 
 
 
 
133
  }
134
  ```
135
 
@@ -138,33 +150,32 @@ Room messages are sent to everyone in a room
138
 
139
  ```typescript
140
  {
141
- "route": "leave_room_response",
142
- "status": string,
143
  }
144
- ```
145
 
146
- ## Get Rooms
 
147
 
148
  **Type:** `client -> server`
149
- **Description:** Used to get list of joined rooms
150
  **Payload:**
151
 
152
  ```typescript
153
  {
154
- "route": "get_rooms"
155
  }
156
  ```
157
 
158
  **Type:** `server -> client <private>`
159
- **Payload:**
160
 
161
  ```typescript
162
  {
163
- "message": "get_rooms_response",
164
- "rooms": [{id: string, userCount: number}]
165
  }
166
  ```
167
 
 
168
  ## Room Update
169
 
170
  **Type:** `server -> client <room>`
@@ -204,27 +215,39 @@ Room messages are sent to everyone in a room
204
  }
205
  ```
206
 
207
- ## Receive Touch
208
 
209
- **Type:** `server -> client <room>`
210
- **Description:**
211
  **Payload:**
212
 
213
  ```typescript
214
  {
215
- "message": "receieve_touch",
216
- "id": string, // format: [userID]_[id]
217
- "type": "enable" | "disable", // Whether the vibration is active or not.
218
- "user": {
219
- username: string,
220
- id: string,
221
- },
222
- "position": {
223
- x: number,
224
- y: number,
225
- },
226
- "color": string, // Hex value.
227
- "intensity": number, // Vibration intensity.
 
 
 
 
 
 
 
 
 
 
 
 
228
  }
229
  ```
230
 
 
1
  # HapticTouch Server
2
 
3
+ The HapticTouch server is a NodeJS/TypeScript WebSocket and Express server used to manage HapticTouch.
4
+
5
+ # Instructions
6
 
7
  ```
8
  git clone https://github.com/AnujPanthri/HapticLink
 
17
  To run use:
18
  `npm start`
19
 
20
+ # Documentation
21
 
22
  Both HTTP and WebSocket server are running on the same port
23
 
24
+ # WebSocket API
 
 
25
 
26
+ WebSockets payload will be in JSON and require atleast a `route` property.
27
  Types can be `client -> server`, `server -> client <private | room>`.
28
+ Private messages are sent directly to the client.
29
+ Room messages are sent to everyone in a room.
30
 
31
+ ## Get User Info
32
 
33
  **Type:** `client -> server`
34
  **Payload:**
35
 
36
  ```typescript
37
  {
38
+ "route": "get_user_info",
39
  }
40
  ```
41
 
42
  **Type:** `server -> client <private>`
43
+ **Payload:**
44
 
45
  ```typescript
46
  {
47
+ "message": "set_username_response",
48
+ "status": string,
49
+ "user": {
50
+ "username": string,
51
+ "id": string,
52
+ "currentRoom": string,
53
+ }
54
  }
55
  ```
56
 
57
+ ## Join Room
58
 
59
  **Type:** `client -> server`
60
+ **Description:** Used to enter a room. Join an existing room by including roomId, or if room doesn't exist, create one with a random ID
61
  **Payload:**
62
 
63
  ```typescript
64
  {
65
+ "route": "join_room",
66
+ "roomId"?: string, // Room Id, optional
67
+ "username"?: string,
68
  }
69
  ```
70
 
71
  **Type:** `server -> client <private>`
72
+ **Payload (only sent if there's an error, else room_update is sent):**
73
 
74
  ```typescript
75
  {
76
+ "message": "join_room_response",
77
  "status": string,
78
  }
79
  ```
80
 
81
+ ## Leave Room
82
 
83
  **Type:** `client -> server`
84
+ **Description:** Used to leave a room.
85
  **Payload:**
86
 
87
  ```typescript
88
  {
89
+ "route": "leave_room",
90
+ "roomId": string; // Room Id, optional
91
  }
92
  ```
93
 
 
96
 
97
  ```typescript
98
  {
99
+ "route": "leave_room_response",
100
+ "status": string,
 
 
 
 
 
101
  }
102
  ```
103
 
104
+ ## Receive Touch
105
 
106
+ **Type:** `server -> client <room>`
107
+ **Description:** Broadcasted to all members of a room when any user sends a successful send_touch request
108
  **Payload:**
109
 
110
  ```typescript
111
  {
112
+ "message": "receive_touch",
113
+ "id": string, // format: [userID]_[id]
114
+ "type": "enable" | "disable", // Whether the vibration is active or not.
115
+ "user": {
116
+ username: string,
117
+ id: string,
118
+ },
119
+ "position": {
120
+ x: number,
121
+ y: number,
122
+ },
123
+ "color": string, // Hex value.
124
+ "intensity": number, // Vibration intensity.
125
  }
126
  ```
127
 
128
+ ## Send Touch
129
 
130
  **Type:** `client -> server`
131
+ **Description:** Used to send touch/vibration data to room. Client assigns a number for an ID. That ID is then used to update the vibration. Re-use `send_touch` to update previous vibration. Use `"type": "disable"` to disable the vibration. If an update isn't sent within 1 second of creation/last update it should automatically be disabled.
132
  **Payload:**
133
 
134
  ```typescript
135
  {
136
+ "route": "send_touch",
137
+ "id": number, // Used to indentify vibrations for updating or disabling them, generated by client. Doesn't need to be secure.
138
+ "type": "enable" | "disable", // Whether the vibration is active or not.
139
+ "position": {
140
+ x: number,
141
+ y: number,
142
+ },
143
+ "color"?: string, // Hex value. Default: random
144
+ "intensity"?: number, // Vibration intensity. Default: 1
145
  }
146
  ```
147
 
 
150
 
151
  ```typescript
152
  {
153
+ "message": "set_username_response",
154
+ "status": string,
155
  }
 
156
 
157
+ ```
158
+ ## Test Connection
159
 
160
  **Type:** `client -> server`
 
161
  **Payload:**
162
 
163
  ```typescript
164
  {
165
+ "route": "test_connection"
166
  }
167
  ```
168
 
169
  **Type:** `server -> client <private>`
170
+ **Response:**
171
 
172
  ```typescript
173
  {
174
+ "message": "test_connection_response",
 
175
  }
176
  ```
177
 
178
+
179
  ## Room Update
180
 
181
  **Type:** `server -> client <room>`
 
215
  }
216
  ```
217
 
218
+ ## Set Username
219
 
220
+ **Type:** `client -> server`
221
+ **Description**: Used to set username.
222
  **Payload:**
223
 
224
  ```typescript
225
  {
226
+ "route": "set_username",
227
+ "username": string,
228
+ }
229
+ ```
230
+
231
+ ## Get Rooms
232
+ *WARNING: not implemented yet*
233
+
234
+ **Type:** `client -> server`
235
+ **Description:** Used to get list of joined rooms
236
+ **Payload:**
237
+
238
+ ```typescript
239
+ {
240
+ "route": "get_rooms"
241
+ }
242
+ ```
243
+
244
+ **Type:** `server -> client <private>`
245
+ **Payload:**
246
+
247
+ ```typescript
248
+ {
249
+ "message": "get_rooms_response",
250
+ "rooms": [{id: string, userCount: number}]
251
  }
252
  ```
253