Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peer closing issue #78

Open
ghost opened this issue Apr 23, 2018 · 3 comments
Open

Peer closing issue #78

ghost opened this issue Apr 23, 2018 · 3 comments

Comments

@ghost
Copy link

ghost commented Apr 23, 2018

I tried to implement multi connections at a time
same time A can communicate B and C and communicate with D , while I disconnect A from B , C and D also disconnected , how to close a specific peer connection without affecting other peer connections .

@nitobuendia
Copy link
Contributor

Hello @sarathkumar654

Thanks a lot for your interest on WebRTC and being so active on this repository.

I can see you have posted #72, #74, and #75 with very similar questions. Are those duplicates or already resolved? Can we consider them as duplicates and close them? Have you read my comments there? I have been providing some guidance on them.

The codelab is designed to connect only two peers. In order to connect several peers you can follow the comments on #72 or check the examples on WebRTC samples: live demo and code. I have also submitted #77 to have future reference to this very same ideas.

In general, we would also need to know how to reproduce the error. Does this happen only when you disconnect peer A (aka: room creator) or also when you disconnect any of the other peers? What are the steps to reproduce? If you have made changes to the code (it seems you did as the codelab only takes two peers) and now you are having new issues, we would need to see the code you are trying to use to help you here. As it is not really part of the codelab, I would advise leveraging #webRTC on StackOverflow where many people could chime in and provide good guidance.

// cc: @samdutton

@ghost
Copy link
Author

ghost commented Apr 24, 2018

we were following the below code
var os = require('os');
var nodeStatic = require('node-static');
var http = require('http');
var socketIO = require('socket.io');

var fileServer = new(nodeStatic.Server)();
var app = http.createServer(function(req, res) {
fileServer.serve(req, res);
}).listen(8080);

var io = socketIO.listen(app);

var clientsArray = {};
var roomNow;

io.sockets.on('connection', function(socket) {

// convenience function to log server messages on the client
function log() {
	var array = ['Message from server:'];
	array.push.apply(array, arguments);
	socket.emit('log', array);
}

socket.on('message', function(message) {
	
	io.sockets.in(roomNow).emit('message', message);

});

socket.on('create or join', function(room) {

	roomNow = room;

	if(clientsArray[room] === undefined)
		clientsArray[room] = [];
	clientsArray[room].push(socket.id);

	log('Received request to create or join room ' + room);

						console.log(clientsArray);

	//var numClients = Object.keys(io.sockets.sockets).length;
	var numClients = clientsArray[room].length;
	log('Room ' + room + ' now has ' + numClients + ' client(s)');

	if (numClients === 1) {
		socket.join(room);
		log('Client ID ' + socket.id + ' created room ' + room);
		io.sockets.in(room).emit('created', room, socket.id);
	} else if (numClients === 2) {
		log('Client ID ' + socket.id + ' joined room ' + room);
		io.sockets.in(room).emit('join', room);
		socket.join(room);
		io.sockets.in(room).emit('joined', room, socket.id);
	} else { // max two clients
		socket.emit('full', room);
	}
});

socket.on('disconnect', function() {
	for(var key in clientsArray) {
		for(var i=0; i<clientsArray[key].length; i++) {
			if(clientsArray[key][i] == socket.id) {
				clientsArray[key].splice(i, 1);
			}
		}
	}
});

socket.on('ipaddr', function() {
	var ifaces = os.networkInterfaces();
	for (var dev in ifaces) {
		ifaces[dev].forEach(function(details) {
			if (details.family === 'IPv4' && details.address !== '127.0.0.1') {
				socket.emit('ipaddr', details.address);
			}
		});
	}
});

});

while disconnect a room all the rooms connection has been disconnected

@nitobuendia
Copy link
Contributor

@sarathkumar654 In what step-xx did you apply this code? Otherwise, I am unable to test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant