52 lines
1.4 KiB
TypeScript
52 lines
1.4 KiB
TypeScript
import Room from "./Room";
|
|
|
|
export class RoomInfo
|
|
{
|
|
public room : Room;
|
|
public info : {[key:string]: any} = {};
|
|
constructor(room : Room){
|
|
this.room = room;
|
|
this.room.on('updateinfo',(name:string,value:any) => {
|
|
this.info[name] = value;
|
|
})
|
|
};
|
|
public async fetch(name?:string)
|
|
{
|
|
if(name)
|
|
{
|
|
let rinfo = await this.room.mwse.EventPooling.request(({
|
|
type: "room/getinfo",
|
|
roomId: this.room.roomId,
|
|
name
|
|
}));
|
|
if(rinfo.status == "success")
|
|
{
|
|
this.info = rinfo.value;
|
|
}else console.warn(rinfo.message);
|
|
}else{
|
|
let rinfo = await this.room.mwse.EventPooling.request(({
|
|
type: "room/info",
|
|
roomId: this.room.roomId
|
|
}));
|
|
if(rinfo.status == "success")
|
|
{
|
|
this.info = rinfo.value;
|
|
}else console.warn(rinfo.message);
|
|
};
|
|
return this.info;
|
|
}
|
|
public set(name: string, value: string | number)
|
|
{
|
|
this.info[name] = value;
|
|
this.room.mwse.WSTSProtocol.SendOnly({
|
|
type: "room/setinfo",
|
|
roomId: this.room.roomId,
|
|
name,
|
|
value
|
|
});
|
|
}
|
|
public get(name?:string)
|
|
{
|
|
return name ? this.info[name] : this.info;
|
|
}
|
|
} |