Connection.ts
596 Bytes
import { Socket } from "socket.io";
import { MessageHandlerRegistry } from "../message/MessageHandlerRegistry";
import { Message } from "../message/types";
import { Room } from "../room/Room";
import { User } from "../user/User";
export class Connection {
public readonly socket: Socket;
public user?: User;
constructor(socket: Socket) {
this.socket = socket;
MessageHandlerRegistry.registerHandlers(this);
}
public get authenticated(): boolean {
return this.user !== undefined;
}
public send(message: Message) {
this.socket.emit(message.type, message);
}
}