Skip to content

Commit 44a6a50

Browse files
committed
people join and leave rooms
1 parent 299921b commit 44a6a50

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

lib/app.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ C("app", "require exports module ChatView smallSurface auth createRooms localVid
261261
app.globalChat.removeParticipant(profile.username);
262262
}
263263
});
264+
socket.on('presence_room', function(presence) {
265+
if (rooms[presence.room_id]) {
266+
rooms[presence.room_id].room.chat.addParticipant(presence.profile);
267+
}
268+
});
269+
socket.on('vacated_room', function(presence) {
270+
if (rooms[presence.room_id]) {
271+
rooms[presence.room_id].room.chat.removeParticipant(presence.profile.username);
272+
}
273+
});
264274

265275
socket.on('users_count', function(count) {
266276
app.stats.activePeople = count;
@@ -305,12 +315,12 @@ C("app", "require exports module ChatView smallSurface auth createRooms localVid
305315
// random position for now
306316
var top = Math.floor((Math.random() * ($target.height() - 100)) + 1);
307317
//var left = Math.floor((Math.random() * ($target.width() - 100)) + 1);
308-
var left = Math.floor((Math.random() * (468 - 100)) + 1);
318+
var right = Math.floor((Math.random() * (468 - 100)) + 1);
309319
v.setParent($target);
310320
$target.append(v.$container);
311321
v.$container.css({
312322
top: top + 'px',
313-
left: left + 'px'
323+
right: right + 'px'
314324
});
315325
}
316326

serve-development/js/junto.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -30397,6 +30397,16 @@ C("app", "require exports module ChatView smallSurface auth createRooms localVid
3039730397
app.globalChat.removeParticipant(profile.username);
3039830398
}
3039930399
});
30400+
socket.on('presence_room', function(presence) {
30401+
if (rooms[presence.room_id]) {
30402+
rooms[presence.room_id].room.chat.addParticipant(presence.profile);
30403+
}
30404+
});
30405+
socket.on('vacated_room', function(presence) {
30406+
if (rooms[presence.room_id]) {
30407+
rooms[presence.room_id].room.chat.removeParticipant(presence.profile.username);
30408+
}
30409+
});
3040030410

3040130411
socket.on('users_count', function(count) {
3040230412
app.stats.activePeople = count;
@@ -30441,12 +30451,12 @@ C("app", "require exports module ChatView smallSurface auth createRooms localVid
3044130451
// random position for now
3044230452
var top = Math.floor((Math.random() * ($target.height() - 100)) + 1);
3044330453
//var left = Math.floor((Math.random() * ($target.width() - 100)) + 1);
30444-
var left = Math.floor((Math.random() * (468 - 100)) + 1);
30454+
var right = Math.floor((Math.random() * (468 - 100)) + 1);
3044530455
v.setParent($target);
3044630456
$target.append(v.$container);
3044730457
v.$container.css({
3044830458
top: top + 'px',
30449-
left: left + 'px'
30459+
right: right + 'px'
3045030460
});
3045130461
}
3045230462

serve-production/js/junto.js

-1
Original file line numberDiff line numberDiff line change
@@ -30488,7 +30488,6 @@ C("app", "require exports module ChatView smallSurface auth createRooms localVid
3048830488
});
3048930489
app.globalChat = new ChatView(app.globalMessages, mapper, 'global');
3049030490
var cHeight = jQuery('body').height() - 98 - 50 - 50 - 166 - 16; // input : header : header : participants : padding
30491-
console.log(cHeight);
3049230491
app.globalChat.$messages.height(cHeight);
3049330492
jQuery('body').append(app.globalChat.$container);
3049430493
app.globalChat.close();

server/rtcSignalServer.js

+20
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ module.exports = function(io, stunservers) {
8989
room_id: client.room,
9090
count: io.sockets.clients(client.room).length
9191
});
92+
if (client.profile) {
93+
client.broadcast.emit('vacated_room', {
94+
room_id: client.room,
95+
profile: client.profile
96+
});
97+
}
9298
if (io.sockets.clients(client.room).length == 0) {
9399
delete activeRooms[client.room];
94100
io.sockets.emit('rooms_count', Object.keys(activeRooms).length);
@@ -110,6 +116,20 @@ module.exports = function(io, stunservers) {
110116
room_id: name,
111117
count: io.sockets.clients(name).length
112118
});
119+
if (client.profile) {
120+
client.broadcast.emit('presence_room', {
121+
room_id: name,
122+
profile: client.profile
123+
});
124+
}
125+
io.sockets.clients(name).forEach(function (s) {
126+
if (s.profile) {
127+
client.emit('presence_room', {
128+
room_id: name,
129+
profile: s.profile
130+
});
131+
}
132+
});
113133
client.room = name;
114134
activeRooms[name] = true;
115135
io.sockets.emit('rooms_count', Object.keys(activeRooms).length);

0 commit comments

Comments
 (0)