30 lines
755 B
JavaScript
30 lines
755 B
JavaScript
export class PeerInfo {
|
|
constructor(peer) {
|
|
this.peer = peer;
|
|
this.info = {};
|
|
}
|
|
|
|
async fetch(name) {
|
|
const req = name
|
|
? { type: 'peer/info', peer: this.peer.socketId, name }
|
|
: { type: 'peer/info', peer: this.peer.socketId };
|
|
|
|
const rinfo = await this.peer.mwse.EventPooling.request(req);
|
|
if (rinfo.status === 'success') {
|
|
this.info = rinfo.info;
|
|
} else {
|
|
console.warn(rinfo.message);
|
|
}
|
|
return this.info;
|
|
}
|
|
|
|
set(name, value) {
|
|
this.info[name] = value;
|
|
this.peer.mwse.WSTSProtocol.SendOnly({ type: 'auth/info', name, value });
|
|
}
|
|
|
|
get(name) {
|
|
return name ? this.info[name] : this.info;
|
|
}
|
|
}
|