-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUser.ts
39 lines (36 loc) · 1.39 KB
/
User.ts
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
import type WebSocket from "ws"
import { gender } from "./types"
export default class User {
id: any
socket: WebSocket
available: boolean
gender: gender
interestedIn: gender
screenSize: { width: number, height: number }
/**
* Creates a new user for a room 🤠
* @param {number} id UID of the user
* @param {string} name Name of the user
* @param {"host" | "co-host" | "participant"} role Role of the user
* @param {WebSocket} [socket] WebSocket connection of the user
* @param {Room} room Room of the user
*/
constructor(id: string, details: { gender: gender, interestedIn: gender, screenSize: { width: number, height: number } }, socket: WebSocket) {
this.id = id
this.gender = details.gender
this.interestedIn = details.interestedIn
this.screenSize = details.screenSize
this.socket = socket
this.available = true
}
/**
* Sends a message to the user ⚡
* @param {"system" | "system-reply" | "signaling"} type Type of the message
* @param {string} content Content of the message
* @param {any} value Value of the message
* @param {number} [by] UID of the user who send the message
*/
send(type: "system" | "system-reply" | "signaling", content: string, value: any, by?: string) {
this.socket.send(JSON.stringify({ type, content, value, by }))
}
}