Skip to content
Open

Dev #32

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2b86f1e
Add all socket logic to date (#1)
devon-wolf Jun 10, 2021
786ce75
Fix package.json issues, break down functions into smaller parts, add…
devon-wolf Jun 10, 2021
ccf526c
added socket listen and emit for search input and button click (#3)
KatrinaCloyd Jun 11, 2021
73c31a3
Feature/online users (#4)
devon-wolf Jun 11, 2021
7077e49
Fix/user connect event (#7)
devon-wolf Jun 14, 2021
0af823a
Link hover (#6)
KatrinaCloyd Jun 14, 2021
c2712d7
simple room functionality test (#5)
CameronZimmerman Jun 14, 2021
c154185
fix broken current room (#8)
CameronZimmerman Jun 14, 2021
5b4db2a
Feature/header click socket (#9)
KatrinaCloyd Jun 14, 2021
0716e5f
add socket features for ghost icons (#10)
CameronZimmerman Jun 14, 2021
e5d4a97
fix missing bracket (#11)
CameronZimmerman Jun 15, 2021
4b4bcc1
socket handlers for answers and DUCK (#12)
KatrinaCloyd Jun 15, 2021
8df410b
add socket data for image gallery challenge (#13)
CameronZimmerman Jun 15, 2021
f213ca8
Feature/ghost story (#14)
devon-wolf Jun 15, 2021
eead252
Feature/values hover (#15)
KatrinaCloyd Jun 15, 2021
ec0cf6a
Feature/footer click challenge (#16)
caseywar Jun 15, 2021
d1bdc43
Feature/tranparent hover (#17)
KatrinaCloyd Jun 15, 2021
1f0126a
socket data for five highlights challenge (#18)
CameronZimmerman Jun 15, 2021
4c3f607
added dont click functionality to join us dropdown menu (#19)
juliannevela Jun 16, 2021
7c71496
Feature/ghostie (#21)
KatrinaCloyd Jun 16, 2021
3b97cdd
Feature/close room after game (#20)
CameronZimmerman Jun 16, 2021
fa91c97
Fix/missing bracket glow function (#22)
CameronZimmerman Jun 16, 2021
321a05c
Fix/user cap (#23)
CameronZimmerman Jun 16, 2021
8a7c454
Fix/user cap 2 (#24)
CameronZimmerman Jun 16, 2021
f3b08d8
Dontclick2 (#25)
juliannevela Jun 16, 2021
9b618bd
Dontclick3 (#26)
juliannevela Jun 16, 2021
a69588e
add default user join, fiddle with other cases (#27)
CameronZimmerman Jun 16, 2021
28c6177
call finish on test end (#28)
CameronZimmerman Jun 17, 2021
846e0aa
add image, links, and description to readme (#29)
KatrinaCloyd Jun 17, 2021
9cec43d
server refactor and comments (#31)
CameronZimmerman Jun 18, 2021
645f355
Merge branch 'main' into dev
CameronZimmerman Jun 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# GIM, LLC

## General Industrial Manufacturing, LLC

_"Commited to providing the best industrial supplies for your company"_
Expand Down
22 changes: 15 additions & 7 deletions lib/socket/user-utils.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
const ROOM_THRESHOLD = 3;

// track current room, and number of connected users in the current room
let roomNumber = 0;
let currentUsers = 0;

//step to the next room, and set current users back to 0
const incrementRoom = () => {
roomNumber++;
currentUsers = 0;
};

//called whenever there is a new socket connection
const addUser = (socket, userObj, gamesArr) => {
//keep an ongoing record of how many users are in a given room, and each user globally
currentUsers += 1;
userObj[socket.id] = socket;

//does the current room have an ongoing game? if so join the next room
if (gamesArr.includes(String(roomNumber))) {
roomNumber++;
currentUsers = 0;
incrementRoom();
userObj[socket.id].room = String(roomNumber);
// if there is no ongoing game, but we have exceeded the max room size join the next room
} else if (currentUsers >= ROOM_THRESHOLD) {
roomNumber++;
currentUsers = 0;
incrementRoom();
userObj[socket.id].room = String(roomNumber);
// if there's no ongoing game, and enough spaces in the room join this current room
} else {
userObj[socket.id].room = String(roomNumber);
}
console.log(`new user in room ${userObj[socket.id].room}: ${socket.id}`);
};

// called once a user disconnects, remove their tracked socket and decrement current users in the room
const deleteUser = (socket, userObj) => {
if(currentUsers > 0) currentUsers--;
console.log('user left: ', socket.id);

delete userObj[socket.id];
};

Expand Down
5 changes: 4 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const io = new Server(server, { cors: true });

const PORT = process.env.PORT || 8080;

//global state management for active users and ongoing games
const users = {};
const games = [];

Expand All @@ -19,12 +20,13 @@ const onConnection = (socket) => {
const currentRoom = `${users[socket.id].room}`;
socket.join(currentRoom);
socket.broadcast.to(currentRoom).emit('new user', { [socket.id]: socket.id });
// socket.to(socket.id).emit('current users', Object.keys(users));

// take in cursor movement data and broadcast to other clients
const onMovement = (movementData) => {
movementData.id = socket.id;
socket.broadcast.to(currentRoom).emit('moving', movementData);
};
// once game has started, add to ongoing games state
const onGameStart = () => {
if (!games.includes(currentRoom)) games.push(currentRoom);
};
Expand Down Expand Up @@ -154,6 +156,7 @@ const onConnection = (socket) => {
socket.on('footerTitleClick', onFooterTitleClick);
};

//runs when a client connects
io.sockets.on('connection', onConnection);

server.listen(PORT, () => {
Expand Down