65 lines
1.5 KiB
TypeScript
65 lines
1.5 KiB
TypeScript
import EventTarget from "./EventTarget";
|
|
import MWSE from "./index";
|
|
|
|
interface IPeerOptions{
|
|
|
|
};
|
|
|
|
|
|
export default class Peer extends EventTarget
|
|
{
|
|
public mwse : MWSE;
|
|
public options! : IPeerOptions;
|
|
public socketId? : string;
|
|
public selfSocket : boolean = false;
|
|
public active : boolean = false;
|
|
constructor(wsts:MWSE){
|
|
super();
|
|
this.mwse = wsts;
|
|
}
|
|
setPeerOptions(options: string | IPeerOptions){
|
|
if(typeof options == "string")
|
|
{
|
|
this.setSocketId(options)
|
|
}else{
|
|
this.options = options;
|
|
}
|
|
}
|
|
setSocketId(uuid: string){
|
|
this.socketId = uuid;
|
|
}
|
|
async metadata() : Promise<any>
|
|
{
|
|
if(this.socketId == 'me')
|
|
{
|
|
let result = await this.mwse.EventPooling.request({
|
|
type:'my/socketid'
|
|
});
|
|
this.selfSocket = true;
|
|
this.active ||= true;
|
|
this.socketId = result;
|
|
this.emit('scope');
|
|
this.activeScope = true;
|
|
return result;
|
|
}
|
|
}
|
|
async enablePairAuth(){
|
|
await this.mwse.EventPooling.request({
|
|
type:'auth/pair-system',
|
|
value: 'everybody'
|
|
});
|
|
}
|
|
async disablePairAuth(){
|
|
await this.mwse.EventPooling.request({
|
|
type:'auth/pair-system',
|
|
value: 'disable'
|
|
});
|
|
}
|
|
async send(pack: any){
|
|
await this.mwse.EventPooling.request({
|
|
type:'pack/to',
|
|
pack,
|
|
to: this.socketId
|
|
});
|
|
}
|
|
} |