37 lines
996 B
JavaScript
37 lines
996 B
JavaScript
export class RoomInfo {
|
|
constructor(room) {
|
|
this.room = room;
|
|
this.info = {};
|
|
// Keep local cache in sync with server-pushed updates.
|
|
this.room.on('updateinfo', (name, value) => { this.info[name] = value; });
|
|
}
|
|
|
|
async fetch(name) {
|
|
const req = name
|
|
? { type: 'room/getinfo', roomId: this.room.roomId, name }
|
|
: { type: 'room/info', roomId: this.room.roomId };
|
|
|
|
const rinfo = await this.room.mwse.EventPooling.request(req);
|
|
if (rinfo.status === 'success') {
|
|
this.info = rinfo.value;
|
|
} else {
|
|
console.warn(rinfo.message);
|
|
}
|
|
return this.info;
|
|
}
|
|
|
|
set(name, value) {
|
|
this.info[name] = value;
|
|
this.room.mwse.WSTSProtocol.SendOnly({
|
|
type: 'room/setinfo',
|
|
roomId: this.room.roomId,
|
|
name,
|
|
value
|
|
});
|
|
}
|
|
|
|
get(name) {
|
|
return name ? this.info[name] : this.info;
|
|
}
|
|
}
|