Spaces:
Runtime error
Runtime error
Added WebSocket documentation
Browse files- server/README.md +156 -0
server/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
# HapticTouch Server
|
| 2 |
|
| 3 |
## Instructions
|
|
|
|
| 4 |
```
|
| 5 |
git clone https://github.com/AnujPanthri/HapticLink
|
| 6 |
cd HapticLink/server
|
|
@@ -18,5 +19,160 @@ To run use:
|
|
| 18 |
|
| 19 |
Both HTTP and WebSocket server are running on the same port
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
**GET** `/`
|
| 22 |
Responds with homepage.
|
|
|
|
| 1 |
# HapticTouch Server
|
| 2 |
|
| 3 |
## Instructions
|
| 4 |
+
|
| 5 |
```
|
| 6 |
git clone https://github.com/AnujPanthri/HapticLink
|
| 7 |
cd HapticLink/server
|
|
|
|
| 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 `message` 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 |
+
"message": "test_connection"
|
| 39 |
+
}
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
**Type:** `server -> client <private>`
|
| 43 |
+
**Response:**
|
| 44 |
+
|
| 45 |
+
```typescript
|
| 46 |
+
{
|
| 47 |
+
"message": "test_connection_response",
|
| 48 |
+
"latency": number,
|
| 49 |
+
}
|
| 50 |
+
```
|
| 51 |
+
|
| 52 |
+
### Enter Room
|
| 53 |
+
|
| 54 |
+
**Type:** `client -> server`
|
| 55 |
+
**Description:** Used to enter a room. Join an existing room by including roomId.
|
| 56 |
+
**Payload:**
|
| 57 |
+
|
| 58 |
+
```typescript
|
| 59 |
+
{
|
| 60 |
+
"message": "enter_room",
|
| 61 |
+
"roomId"?: string; // Room Id, optional
|
| 62 |
+
}
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
**Type:** `server -> client <private>`
|
| 66 |
+
**Payload:**
|
| 67 |
+
|
| 68 |
+
```typescript
|
| 69 |
+
{
|
| 70 |
+
"message": "enter_room_response"
|
| 71 |
+
"roomId": string,
|
| 72 |
+
"users": []{
|
| 73 |
+
username: string,
|
| 74 |
+
id: string,
|
| 75 |
+
online: boolean,
|
| 76 |
+
lastOnline: number, // ms epoch time
|
| 77 |
+
},
|
| 78 |
+
"status": "joined" | "created" | "failed"; // Failed likely means room doesn't exist
|
| 79 |
+
}
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
### Leave Room
|
| 83 |
+
|
| 84 |
+
**Type:** `client -> server`
|
| 85 |
+
**Description:** Used to enter a room.
|
| 86 |
+
**Payload:**
|
| 87 |
+
|
| 88 |
+
```typescript
|
| 89 |
+
{
|
| 90 |
+
"message": "enter_room",
|
| 91 |
+
"roomId": string; // Room Id, optional
|
| 92 |
+
}
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
**Type:** `server -> client <private>`
|
| 96 |
+
**Payload:**
|
| 97 |
+
|
| 98 |
+
```typescript
|
| 99 |
+
{
|
| 100 |
+
"message": "enter_room_response"
|
| 101 |
+
"roomId": string,
|
| 102 |
+
"users": []{
|
| 103 |
+
username: string,
|
| 104 |
+
id: string,
|
| 105 |
+
online: boolean,
|
| 106 |
+
lastOnline: number, // ms epoch time
|
| 107 |
+
},
|
| 108 |
+
"status": "joined" | "created" | "failed"; // Failed likely means room doesn't exist
|
| 109 |
+
}
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
### Room Update
|
| 113 |
+
|
| 114 |
+
**Type:** `server -> client <room>`
|
| 115 |
+
**Description:** Server message that is sent when the room gets updated such as someone joins or leaves
|
| 116 |
+
**Payload:**
|
| 117 |
+
|
| 118 |
+
```typescript
|
| 119 |
+
{
|
| 120 |
+
"message": "room_update",
|
| 121 |
+
"roomId": string,
|
| 122 |
+
"users": []{
|
| 123 |
+
username: string,
|
| 124 |
+
id: string,
|
| 125 |
+
online: boolean,
|
| 126 |
+
lastOnline: number, // ms epoch time
|
| 127 |
+
},
|
| 128 |
+
}
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
### Send Touch
|
| 132 |
+
|
| 133 |
+
**Type:** `client -> server`
|
| 134 |
+
**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 creatin/last update it will automatically be disabled.
|
| 135 |
+
**Payload:**
|
| 136 |
+
|
| 137 |
+
```typescript
|
| 138 |
+
{
|
| 139 |
+
"message": "send_touch",
|
| 140 |
+
"id": number, // Used to indentify vibrations for updating or disabling them
|
| 141 |
+
"type": "enable" | "disable", // Whether the vibration is active or not.
|
| 142 |
+
"position": {
|
| 143 |
+
x: number,
|
| 144 |
+
y: number,
|
| 145 |
+
},
|
| 146 |
+
"color"?: string, // Hex value. Default: random
|
| 147 |
+
"intensity"?: number, // Vibration intensity. Default: 1
|
| 148 |
+
}
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
### Receive Touch
|
| 152 |
+
|
| 153 |
+
**Type:** `server -> client <room>`
|
| 154 |
+
**Description:**
|
| 155 |
+
**Payload:**
|
| 156 |
+
|
| 157 |
+
```typescript
|
| 158 |
+
{
|
| 159 |
+
"message": "receieve_touch",
|
| 160 |
+
"id": string, // format: [userID]_[id]
|
| 161 |
+
"type": "enable" | "disable", // Whether the vibration is active or not.
|
| 162 |
+
"user": {
|
| 163 |
+
username: string,
|
| 164 |
+
id: string,
|
| 165 |
+
},
|
| 166 |
+
"position": {
|
| 167 |
+
x: number,
|
| 168 |
+
y: number,
|
| 169 |
+
},
|
| 170 |
+
"color": string, // Hex value.
|
| 171 |
+
"intensity": number, // Vibration intensity.
|
| 172 |
+
}
|
| 173 |
+
```
|
| 174 |
+
|
| 175 |
+
## API
|
| 176 |
+
|
| 177 |
**GET** `/`
|
| 178 |
Responds with homepage.
|