I initially had trouble getting peers to only connect within some socket room using the function p2pSocket (socket, next, room). The source of the confusion was on the server side in the socket.io-p2p-server/index.js code:
function p2pSocket (socket, next, room) {
clients[socket.id] = socket
if (typeof room === 'object') {
var connectedClients = socket.adapter.rooms[room.name]
} else {
var connectedClients = clients
}
//...
where this requires that the input room be an object. I was passing in room as a string, so this socket.io-p2p-server was connecting me to all clients rather than clients within the room.
Is there any reason that p2pSocket (socket, next, room) requires room to be an object? Based on the code, room is only used to access the room.name string to find the clients in that socket room in that first block cited above. Why not allow clients to pass in room as a string. I think this would reduce some confusion about using p2pSocket. Or maybe even something like:
if (typeof room === 'object') {
// ...
} else if (typeof room === 'string') {
// ...
} else {
// ...
}
In the mean time, as a hack I have been invoking this function p2pSocket like:
// ...
var p2p = require('socket.io-p2p-server').Server;
// ...
p2p(socket, null, {name: room});
so that the room input is recognized as an object.
Thanks!
I initially had trouble getting peers to only connect within some socket room using the function
p2pSocket (socket, next, room). The source of the confusion was on the server side in the socket.io-p2p-server/index.js code:where this requires that the input
roombe an object. I was passing inroomas a string, so this socket.io-p2p-server was connecting me to all clients rather than clients within theroom.Is there any reason that
p2pSocket (socket, next, room)requiresroomto be an object? Based on the code,roomis only used to access theroom.namestring to find the clients in that socket room in that first block cited above. Why not allow clients to pass in room as a string. I think this would reduce some confusion about usingp2pSocket. Or maybe even something like:In the mean time, as a hack I have been invoking this function
p2pSocketlike:so that the room input is recognized as an object.
Thanks!