Spaces:
Runtime error
Runtime error
File size: 4,238 Bytes
cfd4c95 0f62e62 cfd4c95 0f62e62 e6f6400 0f62e62 0e0a112 0f62e62 81ad08a 0fef087 0f62e62 e6f6400 0f62e62 0fef087 0e0a112 0fef087 81ad08a 0fef087 61ffaad 0fef087 81ad08a 0fef087 61ffaad 81ad08a 0f62e62 0fef087 81ad08a 0fef087 0f62e62 0fef087 0f62e62 0e0a112 0f62e62 81ad08a 0fef087 0f62e62 86cdfc6 61ffaad 0f62e62 81ad08a 0fef087 0f62e62 86cdfc6 0f62e62 0e0a112 0f62e62 81ad08a 0fef087 0f62e62 86cdfc6 0f62e62 81ad08a 0fef087 0f62e62 86cdfc6 0f62e62 0e0a112 ba51620 81ad08a 0fef087 ba51620 81ad08a 0fef087 ba51620 0e0a112 0f62e62 81ad08a 0fef087 0f62e62 38937c3 0f62e62 ba51620 0f62e62 ba51620 0f62e62 0e0a112 0f62e62 81ad08a 307d8b2 0fef087 0f62e62 e6f6400 0f62e62 0e0a112 0f62e62 81ad08a 0fef087 0f62e62 38937c3 0f62e62 81ad08a cfd4c95 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# HapticTouch Server
## Instructions
```
git clone https://github.com/AnujPanthri/HapticLink
cd HapticLink/server
npm install
npm run dev
```
To build use:
`npm run build`
To run use:
`npm start`
## Documentation
Both HTTP and WebSocket server are running on the same port
# WORK IN PROGRESS
## WebSocket API
WebSockets payload will be in JSON and require atleast a `route` property
Types can be `client -> server`, `server -> client <private | room>`.
Private messages are sent directly to client
Room messages are sent to everyone in a room
## Test Connection
**Type:** `client -> server`
**Payload:**
```typescript
{
"route": "test_connection"
}
```
**Type:** `server -> client <private>`
**Response:**
```typescript
{
"message": "test_connection_response",
}
```
## Set Username
**Type:** `client -> server`
**Payload:**
```typescript
{
"route": "set_username",
"username": string,
}
```
**Type:** `server -> client <private>`
**Payload:**
```typescript
{
"message": "set_username_response",
"status": string,
}
```
## Get User Info
**Type:** `client -> server`
**Payload:**
```typescript
{
"route": "get_user_info",
}
```
**Type:** `server -> client <private>`
**Payload:**
```typescript
{
"message": "set_username_response",
"status": string,
"user": {
"username": string,
"id": string,
"currentRoom": string,
}
}
```
## Join Room
**Type:** `client -> server`
**Description:** Used to enter a room. Join an existing room by including roomId, or if room doesn't exist, create one with that roomId
**Payload:**
```typescript
{
"route": "join_room",
"roomId"?: string, // Room Id, optional
"username"?: string,
}
```
**Type:** `server -> client <private>`
**Payload (If error):**
```typescript
{
"message": "enter_room_response",
"status": string,
}
```
## Leave Room
**Type:** `client -> server`
**Description:** Used to enter a room.
**Payload:**
```typescript
{
"route": "leave_room",
"roomId": string; // Room Id, optional
}
```
**Type:** `server -> client <private>`
**Payload:**
```typescript
{
"route": "leave_room_response",
"status": string,
}
```
## Get Rooms
**Type:** `client -> server`
**Description:** Used to get list of joined rooms
**Payload:**
```typescript
{
"route": "get_rooms"
}
```
**Type:** `server -> client <private>`
**Payload:**
```typescript
{
"message": "get_rooms_response",
"rooms": [{id: string, userCount: number}]
}
```
## Room Update
**Type:** `server -> client <room>`
**Description:** Server message that is sent when the room gets updated such as someone joins or leaves
**Payload:**
```typescript
{
"message": "room_update",
"roomId": string,
"users": [{
username: string,
id: string,
online: boolean,
lastOnline: number, // ms epoch time
}],
}
```
## Send Touch
**Type:** `client -> server`
**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 will automatically be disabled.
**Payload:**
```typescript
{
"route": "send_touch",
"id": number, // Used to indentify vibrations for updating or disabling them
"type": "enable" | "disable", // Whether the vibration is active or not.
"position": {
x: number,
y: number,
},
"color"?: string, // Hex value. Default: random
"intensity"?: number, // Vibration intensity. Default: 1
}
```
## Receive Touch
**Type:** `server -> client <room>`
**Description:**
**Payload:**
```typescript
{
"message": "receieve_touch",
"id": string, // format: [userID]_[id]
"type": "enable" | "disable", // Whether the vibration is active or not.
"user": {
username: string,
id: string,
},
"position": {
x: number,
y: number,
},
"color": string, // Hex value.
"intensity": number, // Vibration intensity.
}
```
## API
**GET** `/`
Responds with homepage.
|