dobrograd-13-06-2022/octolib/core/socket/client.ts

28 lines
585 B
TypeScript
Raw Normal View History

2023-11-16 15:01:19 +05:00
import WebSocket from 'ws'
import { Message } from './message'
import { SocketServer } from './server'
export class ClientSocket extends WebSocket {
public client?: Client
}
export class Client {
public clientID: string
public socket: ClientSocket
public server: SocketServer
constructor(server: SocketServer, socket: ClientSocket, id: string) {
this.server = server
this.socket = socket
this.clientID = id
}
send(message: Message) {
this.socket.send(message.toJSON())
}
request(method: string, data?: any) {
return this.server.request(this, method, data)
}
}