diff --git a/erizo_controller/erizoController/erizoController.js b/erizo_controller/erizoController/erizoController.js index d0d1df03d4..039a949546 100644 --- a/erizo_controller/erizoController/erizoController.js +++ b/erizo_controller/erizoController/erizoController.js @@ -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); } } @@ -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'); @@ -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'); }; diff --git a/erizo_controller/erizoController/webRtcController.js b/erizo_controller/erizoController/webRtcController.js index 974c6c0555..14a63d7911 100644 --- a/erizo_controller/erizoController/webRtcController.js +++ b/erizo_controller/erizoController/webRtcController.js @@ -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); @@ -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;