Selectively connect to peer ?
darkyen opened this issue · 1 comments
darkyen commented
I think with socket.io it should be rather simple to do this by allowing a peer to connect to remote peers selectively.Maybe In a discovery based method ? This would give more control to the developer, additionally authentication of peers can than be handled serverside (allows enforcing rules).
sio.on('peer-discovered', function(peer){
peer.connect();
});
and on the other hand (or maybe filter this in server)
sio.on('peer-request', async function(user, response){
const shouldAnswer = await getConfirmationAsync();
if( shouldAnswer ) return response.answer();
response.reject();
});
W4G1 commented
You can achieve this by letting the peers you want to connect together join in a room and then exchange signalling data by calling p2pserver()
on the server:
const server = require('http').createServer()
const p2pserver = require('socket.io-p2p-server').Server
const io = require('socket.io')(server)
server.listen(3030)
io.on('connection', socket => {
socket.join(room) /* Join the room */
p2pserver(socket, null, room) /* All sockets in the specified room will attempt to establish a WebRTC connection. */
})