hapticlink / server /README.md
avallef's picture
Formatted readme and added get_user_info
0fef087
# 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.