Connection.ts
618 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;
public room?: Room;
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);
}
}