Skip to content

Commit

Permalink
Fixed a bug when closing connections
Browse files Browse the repository at this point in the history
  • Loading branch information
aalonsog committed Mar 12, 2014
1 parent 4819c18 commit f18e8d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
27 changes: 22 additions & 5 deletions erizo_controller/erizoController/erizoController.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,17 @@ var listen = function () {
socket.room.sockets.splice(index, 1);
}

if (socket.room.webRtcController) {
socket.room.webRtcController.removeSubscriptions(socket.id);
}

for (i in socket.streams) {
if (socket.streams.hasOwnProperty(i)) {
id = socket.streams[i];

if (socket.room.streams[id].hasAudio() || socket.room.streams[id].hasVideo() || socket.room.streams[id].hasScreen()) {
if (!socket.room.p2p) {
socket.room.webRtcController.removeClient(socket.id, id);
socket.room.webRtcController.removePublisher(id);
}

}
Expand Down Expand Up @@ -526,7 +530,9 @@ exports.getUsersInRoom = function (room, callback) {
exports.deleteRoom = function (room, callback) {
"use strict";

var sockets, id;
var sockets, streams, id, j;

logger.info('Deleting room ', room);

if (rooms[room] === undefined) {
callback('Success');
Expand All @@ -536,13 +542,24 @@ exports.deleteRoom = function (room, callback) {

for (id in sockets) {
if (sockets.hasOwnProperty(id)) {
rooms[room].webRtcController.removeClient(sockets[id]);
rooms[room].webRtcController.removeSubscriptions(sockets[id]);
}
}

streams = rooms[room].streams;

for (j in streams) {
if (streams[j].hasAudio() || streams[j].hasVideo() || streams[j].hasScreen()) {
if (!room.p2p) {
rooms[room].webRtcController.removePublisher(j);
}

}
}
logger.info('Deleting room ', room, rooms);

delete rooms[room];
updateMyState();
logger.info('1 Deleting room ', room, rooms);
logger.info('Deleted room ', room, rooms);
callback('Success');
};

Expand Down
13 changes: 3 additions & 10 deletions erizo_controller/erizoController/webRtcController.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,13 @@ exports.WebRtcController = function () {
};

/*
* Removes a client from the session. This removes the publisher and all the subscribers related.
* Removes all the subscribers related with a client.
*/
that.removeClient = function (from, streamId) {
that.removeSubscriptions = function (from) {

var key, index;

logger.info('Removing client ', from);
logger.info('Removing subscriptions of ', from);
for (key in subscribers) {
if (subscribers.hasOwnProperty(key)) {
index = subscribers[key].indexOf(from);
Expand All @@ -273,13 +273,6 @@ exports.WebRtcController = function () {
}
}
}

if (subscribers[streamId] !== undefined && publishers[streamId] !== undefined) {
logger.info('Removing muxer', streamId);
publishers[streamId].close();
delete subscribers[streamId];
delete publishers[streamId];
}
};

return that;
Expand Down

0 comments on commit f18e8d3

Please sign in to comment.