MWSE/frontend/PeerInfo.ts

48 lines
1.2 KiB
TypeScript

import Peer from "./Peer";
export class PeerInfo
{
public peer : Peer;
public info : {[key:string]: any} = {};
constructor(mwse : Peer){
this.peer = mwse;
};
public async fetch(name?:string)
{
if(name)
{
let rinfo = await this.peer.mwse.EventPooling.request(({
type: "peer/info",
peer: this.peer.socketId,
name
}));
if(rinfo.status == "success")
{
this.info = rinfo.info;
}else console.warn(rinfo.message);
}else{
let rinfo = await this.peer.mwse.EventPooling.request(({
type: "peer/info",
peer: this.peer.socketId
}));
if(rinfo.status == "success")
{
this.info = rinfo.info;
}else console.warn(rinfo.message);
};
return this.info;
}
public set(name: string, value: string | number)
{
this.info[name] = value;
this.peer.mwse.WSTSProtocol.SendOnly({
type: "auth/info",
name,
value
});
}
public get(name?:string)
{
return name ? this.info[name] : this.info;
}
}