Stage 249
This commit is contained in:
parent
d7900f827f
commit
446583afa0
|
@ -49,6 +49,39 @@ addService(({
|
||||||
}
|
}
|
||||||
break;
|
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":{
|
case "pack/room":{
|
||||||
let {to,pack, handshake,wom} = message;
|
let {to,pack, handshake,wom} = message;
|
||||||
if(Room.rooms.has(to))
|
if(Room.rooms.has(to))
|
||||||
|
|
|
@ -6,6 +6,9 @@ export default class EventPool
|
||||||
public wsts : MWSE;
|
public wsts : MWSE;
|
||||||
public events : Map<number, [Function,Function]> = new Map();
|
public events : Map<number, [Function,Function]> = new Map();
|
||||||
public signals : Map<string, Function[]> = new Map();
|
public signals : Map<string, Function[]> = new Map();
|
||||||
|
|
||||||
|
public requests : Map<number, [Function,Function]> = new Map();
|
||||||
|
|
||||||
public count = 0;
|
public count = 0;
|
||||||
constructor(wsts:MWSE){
|
constructor(wsts:MWSE){
|
||||||
this.wsts = wsts;
|
this.wsts = wsts;
|
||||||
|
|
|
@ -42,7 +42,14 @@ export default class Peer extends EventTarget
|
||||||
this.activeScope = true;
|
this.activeScope = true;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
async request(pack:any){
|
||||||
|
if(this.active)
|
||||||
|
{
|
||||||
|
return await this.mwse.request(this.socketId as string, pack);
|
||||||
|
}
|
||||||
|
};
|
||||||
async isReachable()
|
async isReachable()
|
||||||
{
|
{
|
||||||
return await this.mwse.EventPooling.request({
|
return await this.mwse.EventPooling.request({
|
||||||
|
|
|
@ -3,7 +3,7 @@ import EventPool from "./EventPool";
|
||||||
import EventTarget from "./EventTarget";
|
import EventTarget from "./EventTarget";
|
||||||
import Peer from "./Peer";
|
import Peer from "./Peer";
|
||||||
import Room, { IRoomOptions } from "./Room";
|
import Room, { IRoomOptions } from "./Room";
|
||||||
import WSTSProtocol from "./WSTSProtocol";
|
import WSTSProtocol, { Message } from "./WSTSProtocol";
|
||||||
export default class MWSE extends EventTarget {
|
export default class MWSE extends EventTarget {
|
||||||
public server! : Connection;
|
public server! : Connection;
|
||||||
public WSTSProtocol! : WSTSProtocol;
|
public WSTSProtocol! : WSTSProtocol;
|
||||||
|
@ -31,12 +31,38 @@ export default class MWSE extends EventTarget {
|
||||||
});
|
});
|
||||||
this.packMessagingSystem();
|
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()
|
private packMessagingSystem()
|
||||||
{
|
{
|
||||||
this.EventPooling.signal('pack',(payload : {to:string,pack:any}) => {
|
this.EventPooling.signal('pack',(payload : {to:string,pack:any}) => {
|
||||||
let {to,pack} = payload;
|
let {to,pack} = payload;
|
||||||
this.peer(to).emit('message', pack);
|
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}) => {
|
this.EventPooling.signal('pack/room',(payload : {to:string,pack:any}) => {
|
||||||
let {to,pack} = payload;
|
let {to,pack} = payload;
|
||||||
this.room(to).emit('message', pack);
|
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
Loading…
Reference in New Issue