Stage 249

This commit is contained in:
Abdussamed ULUTAŞ 2022-12-23 00:14:20 +03:00
parent d7900f827f
commit 446583afa0
6 changed files with 73 additions and 4 deletions

View File

@ -49,6 +49,39 @@ addService(({
}
break;
}
case "request/to":{
let {to,pack, id} = message;
if(Client.clients.has(to))
{
let otherPeer = Client.clients.get(to);
if(otherPeer.requiredPair && !otherPeer.pairs.has(to))
{
return;
}
otherPeer.send([{
from: client.id,
pack: pack,
id
}, 'request']);
};
break;
}
case "response/to":{
let {to,pack, id} = message;
if(Client.clients.has(to))
{
let otherPeer = Client.clients.get(to);
if(otherPeer.requiredPair && !otherPeer.pairs.has(to))
{
return;
}
otherPeer.send([{
from: client.id,
pack: pack
}, id]);
};
break;
}
case "pack/room":{
let {to,pack, handshake,wom} = message;
if(Room.rooms.has(to))

View File

@ -6,6 +6,9 @@ export default class EventPool
public wsts : MWSE;
public events : Map<number, [Function,Function]> = new Map();
public signals : Map<string, Function[]> = new Map();
public requests : Map<number, [Function,Function]> = new Map();
public count = 0;
constructor(wsts:MWSE){
this.wsts = wsts;

View File

@ -42,7 +42,14 @@ export default class Peer extends EventTarget
this.activeScope = true;
return result;
}
}
};
async request(pack:any){
if(this.active)
{
return await this.mwse.request(this.socketId as string, pack);
}
};
async isReachable()
{
return await this.mwse.EventPooling.request({

View File

@ -3,7 +3,7 @@ import EventPool from "./EventPool";
import EventTarget from "./EventTarget";
import Peer from "./Peer";
import Room, { IRoomOptions } from "./Room";
import WSTSProtocol from "./WSTSProtocol";
import WSTSProtocol, { Message } from "./WSTSProtocol";
export default class MWSE extends EventTarget {
public server! : Connection;
public WSTSProtocol! : WSTSProtocol;
@ -31,12 +31,38 @@ export default class MWSE extends EventTarget {
});
this.packMessagingSystem();
}
public async request(peerId: string, pack:Message)
{
return await this.EventPooling.request({
type: 'request/to',
to: peerId,
pack
});
}
public async response(peerId: string, requestId:number, pack:Message)
{
this.WSTSProtocol.SendOnly({
type: 'response/to',
to: peerId,
pack,
id: requestId
})
}
private packMessagingSystem()
{
this.EventPooling.signal('pack',(payload : {to:string,pack:any}) => {
let {to,pack} = payload;
this.peer(to).emit('message', pack);
})
this.EventPooling.signal('request',(payload : {to:string,pack:any,id:number}) => {
let {to,pack, id} = payload;
this.peer(to).emit('request', {
body: pack,
response: (pack: Message) => {
this.response(to, id, pack);
}
});
})
this.EventPooling.signal('pack/room',(payload : {to:string,pack:any}) => {
let {to,pack} = payload;
this.room(to).emit('message', pack);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long