diff --git a/server.js b/server.js index 25741cf..f6073be 100755 --- a/server.js +++ b/server.js @@ -55,12 +55,18 @@ server.listen(port, function() { }); +function minifyRoomHash(hash) { + let text = hash.replace(new RegExp('[^A-Z^a-z^0-9]', 'g'), ''); + text += 'roomID'; + return text.slice(0, 6); +} + /* * Rooms related methods */ function getRoom(socket) { - var room = socket.room ? socket.room.slice(0, 6) : socket.room; + var room = socket.room ? minifyRoomHash(socket.room) : socket.room; if (rooms[room] === undefined) { createRoom(room); } @@ -165,7 +171,7 @@ io.on('connection', function(socket) { }); socket.on('subscribeToStream', function (data){ - joinRoom(socket, data ? data.slice(0, 6) : data); + joinRoom(socket, data ? minifyRoomHash(data) : data); var room = getRoom(socket); if (room.presenter) { socket.emit('streamStarted'); @@ -177,7 +183,7 @@ io.on('connection', function(socket) { }); socket.on('joinRoom', function (data) { - joinRoom(socket, data ? data.slice(0, 6) : data) + joinRoom(socket, data ? minifyRoomHash(data) : data) });