Spaces:
Paused
Paused
Anne Lefebvre
commited on
Corrected documentations
Browse files- server/README.md +94 -71
server/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
# HapticTouch Server
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 19 |
|
| 20 |
Both HTTP and WebSocket server are running on the same port
|
| 21 |
|
| 22 |
-
#
|
| 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 |
-
##
|
| 32 |
|
| 33 |
**Type:** `client -> server`
|
| 34 |
**Payload:**
|
| 35 |
|
| 36 |
```typescript
|
| 37 |
{
|
| 38 |
-
"route": "
|
| 39 |
}
|
| 40 |
```
|
| 41 |
|
| 42 |
**Type:** `server -> client <private>`
|
| 43 |
-
**
|
| 44 |
|
| 45 |
```typescript
|
| 46 |
{
|
| 47 |
-
"message": "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
}
|
| 49 |
```
|
| 50 |
|
| 51 |
-
##
|
| 52 |
|
| 53 |
**Type:** `client -> server`
|
|
|
|
| 54 |
**Payload:**
|
| 55 |
|
| 56 |
```typescript
|
| 57 |
{
|
| 58 |
-
"route": "
|
| 59 |
-
"
|
|
|
|
| 60 |
}
|
| 61 |
```
|
| 62 |
|
| 63 |
**Type:** `server -> client <private>`
|
| 64 |
-
**Payload:**
|
| 65 |
|
| 66 |
```typescript
|
| 67 |
{
|
| 68 |
-
"message": "
|
| 69 |
"status": string,
|
| 70 |
}
|
| 71 |
```
|
| 72 |
|
| 73 |
-
##
|
| 74 |
|
| 75 |
**Type:** `client -> server`
|
|
|
|
| 76 |
**Payload:**
|
| 77 |
|
| 78 |
```typescript
|
| 79 |
{
|
| 80 |
-
"route": "
|
|
|
|
| 81 |
}
|
| 82 |
```
|
| 83 |
|
|
@@ -86,50 +96,52 @@ Room messages are sent to everyone in a room
|
|
| 86 |
|
| 87 |
```typescript
|
| 88 |
{
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
"user": {
|
| 92 |
-
"username": string,
|
| 93 |
-
"id": string,
|
| 94 |
-
"currentRoom": string,
|
| 95 |
-
}
|
| 96 |
}
|
| 97 |
```
|
| 98 |
|
| 99 |
-
##
|
| 100 |
|
| 101 |
-
**Type:** `
|
| 102 |
-
**Description:**
|
| 103 |
**Payload:**
|
| 104 |
|
| 105 |
```typescript
|
| 106 |
{
|
| 107 |
-
"
|
| 108 |
-
"
|
| 109 |
-
"
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
"
|
| 119 |
-
"
|
| 120 |
}
|
| 121 |
```
|
| 122 |
|
| 123 |
-
##
|
| 124 |
|
| 125 |
**Type:** `client -> server`
|
| 126 |
-
**Description:** Used to
|
| 127 |
**Payload:**
|
| 128 |
|
| 129 |
```typescript
|
| 130 |
{
|
| 131 |
-
"route": "
|
| 132 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
}
|
| 134 |
```
|
| 135 |
|
|
@@ -138,33 +150,32 @@ Room messages are sent to everyone in a room
|
|
| 138 |
|
| 139 |
```typescript
|
| 140 |
{
|
| 141 |
-
|
| 142 |
-
|
| 143 |
}
|
| 144 |
-
```
|
| 145 |
|
| 146 |
-
|
|
|
|
| 147 |
|
| 148 |
**Type:** `client -> server`
|
| 149 |
-
**Description:** Used to get list of joined rooms
|
| 150 |
**Payload:**
|
| 151 |
|
| 152 |
```typescript
|
| 153 |
{
|
| 154 |
-
"route": "
|
| 155 |
}
|
| 156 |
```
|
| 157 |
|
| 158 |
**Type:** `server -> client <private>`
|
| 159 |
-
**
|
| 160 |
|
| 161 |
```typescript
|
| 162 |
{
|
| 163 |
-
"message": "
|
| 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 |
-
##
|
| 208 |
|
| 209 |
-
**Type:** `
|
| 210 |
-
**Description
|
| 211 |
**Payload:**
|
| 212 |
|
| 213 |
```typescript
|
| 214 |
{
|
| 215 |
-
"
|
| 216 |
-
"
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
|