Skip to content

Commit

Permalink
Fixed a bug that did't allow simultaneous clients in different rooms (l…
Browse files Browse the repository at this point in the history
Álvaro Alonso authored Aug 4, 2017
1 parent 895c376 commit 1b0d110
Showing 2 changed files with 22 additions and 16 deletions.
33 changes: 21 additions & 12 deletions common/api.js
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@ API.rooms = {};
API.streams = {};
API.users = {};
API.states = {};
API.currentRoom;
API.sessions_active = {};
API.lastUpdated;
// key: socketId, value: socket
@@ -113,16 +112,28 @@ const removeConnection = (socketId) => {
API.sockets.delete(socketId);
};

function getParameterByName(name, url) {
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return '';
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}

const sendEventToClients = function(event, rooms, streams, users, states) {
API.sockets.forEach((currentSocket, currentSocketId) => {
currentSocket.emit('newEvent', {
event: event,
rooms: rooms,
streams: streams,
users: users,
states: states
});
});
var clientCurrentRoom = getParameterByName('room_id', currentSocket.handshake.headers.referer);
if (clientCurrentRoom == event.roomID || clientCurrentRoom == '') {
currentSocket.emit('newEvent', {
event: event,
rooms: rooms,
streams: streams,
users: users,
states: states
});
}
});
};

API.api = {};
@@ -454,9 +465,7 @@ API.api.event = function(theEvent) {
default:
break;
}
if (API.currentRoom == event.roomID || API.currentRoom == "") {
sendEventToClients(event, API.rooms, API.streams, API.users, API.states);
}
sendEventToClients(event, API.rooms, API.streams, API.users, API.states);
if (config.ackuaria.useDB) {
eventsRegistry.addEvent(theEvent, function(saved, error) {
if (error) log.error(error);
5 changes: 1 addition & 4 deletions controllers/ackuaria_controller.js
Original file line number Diff line number Diff line change
@@ -39,7 +39,6 @@ exports.updateRooms = function(req, res, next) {
}

exports.loadRooms = function(req, res) {
API.currentRoom = "";
res.render('rooms', {
view: "rooms",
rooms: API.rooms
@@ -49,7 +48,6 @@ exports.loadRooms = function(req, res) {
exports.loadPublishers = function(req, res) {
var roomID = req.query.room_id;
var fails = req.query.fails;
API.currentRoom = roomID;
var room = API.rooms[roomID];

if (API.rooms[roomID]) var roomName = API.rooms[roomID].roomName;
@@ -88,8 +86,7 @@ exports.loadSubscribers = function(req, res) {
var streamID = req.query.pub_id;
var roomID = req.query.room_id;
var room = API.rooms[roomID];

API.currentRoom = roomID;

if (API.streams[streamID]) var userName = API.streams[streamID].userName;
else var userName = "Publisher not found";

0 comments on commit 1b0d110

Please sign in to comment.