Disconnected pair event added
This commit is contained in:
parent
73b5ade3e1
commit
4cd68f4a7f
|
@ -125,7 +125,7 @@ Client.prototype.isSecure = function(client)
|
|||
return false;
|
||||
}
|
||||
/**
|
||||
* @returns {{pairs:Map<string, Client>,roompairs:Map<string, Client>}}
|
||||
* @returns {{pairs:Map<string, Client>,roompairs:Map<string, Client>,intersection:Map<string, Client>}}
|
||||
*/
|
||||
Client.prototype.getSucureClients = function()
|
||||
{
|
||||
|
@ -152,7 +152,11 @@ Client.prototype.getSucureClients = function()
|
|||
};
|
||||
return {
|
||||
pairs,
|
||||
roompairs
|
||||
roompairs,
|
||||
intersection : new Map([
|
||||
...pairs,
|
||||
...roompairs
|
||||
])
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,19 @@
|
|||
const { Client } = require("../Client.js");
|
||||
let {addService, addListener} = require("../WebSocket.js");
|
||||
|
||||
addListener('disconnect',(global, xclient)=>{
|
||||
const {intersection} = xclient.getSucureClients();
|
||||
for (const [clientid, client] of intersection)
|
||||
{
|
||||
client.send([
|
||||
{
|
||||
id: clientid
|
||||
},
|
||||
"peer/disconnect"
|
||||
])
|
||||
}
|
||||
});
|
||||
|
||||
addService(({
|
||||
client,
|
||||
message,
|
||||
|
@ -62,7 +75,7 @@ addService(({
|
|||
message: 'ALREADY-PAIRED'
|
||||
})
|
||||
}
|
||||
if(client.pairs.add(to))
|
||||
if(client.pairs.has(to))
|
||||
{
|
||||
return end({
|
||||
status: 'fail',
|
||||
|
|
|
@ -38,12 +38,21 @@ addService(({
|
|||
if(Client.clients.has(to))
|
||||
{
|
||||
let otherPeer = Client.clients.get(to);
|
||||
if(otherPeer.requiredPair && !otherPeer.pairs.has(to))
|
||||
if(otherPeer.requiredPair)
|
||||
{
|
||||
console.error("Client, güvenilir olmayan bir cliente mesaj iletiyor")
|
||||
return handshake && end({
|
||||
type: 'fail'
|
||||
})
|
||||
if(!otherPeer.pairs.has(to))
|
||||
{
|
||||
console.error("Client, güvenilir olmayan bir cliente mesaj iletiyor")
|
||||
return handshake && end({
|
||||
type: 'fail'
|
||||
})
|
||||
}
|
||||
}else{
|
||||
if(!otherPeer.pairs.has(to))
|
||||
{
|
||||
otherPeer.pairs.add(client.id);
|
||||
client.pairs.add(otherPeer.id);
|
||||
}
|
||||
}
|
||||
|
||||
if(!otherPeer.packWriteable()){
|
||||
|
@ -72,10 +81,18 @@ addService(({
|
|||
if(Client.clients.has(to))
|
||||
{
|
||||
let otherPeer = Client.clients.get(to);
|
||||
if(otherPeer.requiredPair && !otherPeer.pairs.has(to))
|
||||
if(otherPeer.requiredPair)
|
||||
{
|
||||
console.error("response istenen peer güvenli değil")
|
||||
return;
|
||||
if(!otherPeer.pairs.has(to))
|
||||
{
|
||||
console.error("Client, güvenilir olmayan bir clientden veri istiyor")
|
||||
return handshake && end({
|
||||
type: 'fail'
|
||||
})
|
||||
}
|
||||
}else{
|
||||
otherPeer.pairs.add(client.id);
|
||||
client.pairs.add(otherPeer.id);
|
||||
}
|
||||
otherPeer.send([{
|
||||
from: client.id,
|
||||
|
|
|
@ -149,7 +149,7 @@ export default class MWSE extends EventTarget {
|
|||
this.EventPooling.signal('room/ejected',(payload : {id:string,roomid:any,ownerid:string}) => {
|
||||
let {id,roomid} = payload;
|
||||
let room = this.room(roomid);
|
||||
let peer = this.peer(id);
|
||||
let peer = this.peer(id, true);
|
||||
room.peers.delete(peer.socketId as string);
|
||||
room.emit('eject', peer);
|
||||
})
|
||||
|
@ -162,27 +162,32 @@ export default class MWSE extends EventTarget {
|
|||
})
|
||||
this.EventPooling.signal("pair/info", (payload : {from : string,name: string, value: string | number | boolean}) => {
|
||||
let {from, name, value} = payload;
|
||||
let peer = this.peer(from);
|
||||
let peer = this.peer(from, true);
|
||||
peer.info.info[name] = value;
|
||||
peer.emit("info", name, value);
|
||||
})
|
||||
this.EventPooling.signal("request/pair", (payload : {from : string,info: any}) => {
|
||||
let {from, info} = payload;
|
||||
let peer = this.peer(from);
|
||||
let peer = this.peer(from, true);
|
||||
peer.info.info = info;
|
||||
peer.emit("request/pair", peer);
|
||||
this.peer('me').emit('request/pair', peer);
|
||||
})
|
||||
this.EventPooling.signal("peer/disconnect", (payload : {id : string}) => {
|
||||
let {id} = payload;
|
||||
let peer = this.peer(id, true);
|
||||
peer.emit("disconnect", peer);
|
||||
})
|
||||
this.EventPooling.signal("accepted/pair", (payload : {from : string,info: any}) => {
|
||||
let {from, info} = payload;
|
||||
let peer = this.peer(from);
|
||||
let peer = this.peer(from, true);
|
||||
peer.info.info = info;
|
||||
peer.emit("accepted/pair", peer);
|
||||
this.peer('me').emit('accepted/pairr', peer);
|
||||
})
|
||||
this.EventPooling.signal("end/pair", (payload : {from : string,info: any}) => {
|
||||
let {from, info} = payload;
|
||||
let peer = this.peer(from);
|
||||
let peer = this.peer(from, true);
|
||||
peer.emit("endPair", info);
|
||||
this.peer('me').emit('endPair', from, info);
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue