MWSE/frontend/Room.ts

47 lines
1.1 KiB
TypeScript

import WSTS from "./index";
export interface IRoomOptions
{
name: string;
description?:string;
joinType: "free"|"invite"|"password"|"lock";
credential?: string;
ifexistsJoin?: boolean;
accessType?: "public"|"private";
notifyActionInvite?: boolean;
notifyActionJoined?: boolean;
notifyActionEjected?: boolean;
}
export default class Room
{
public wsts : WSTS;
public options! : IRoomOptions;
public events : {[key:string]:Function[]} = {};
constructor(wsts:WSTS){
this.wsts = wsts;
}
public setRoomOptions(options : IRoomOptions)
{
this.options = options;
}
private emit(eventName :string, ...args:any[])
{
if(this.events[eventName])
{
for (const callback of this.events[eventName]) {
callback(...args);
}
}
}
public on(eventName :string, callback:Function)
{
if(this.events[eventName])
{
this.events[eventName].push(callback)
}else{
this.events[eventName] = [callback];
}
}
}