Skip to content

Commit 254d062

Browse files
committed
work on websocket, username
1 parent 7acb126 commit 254d062

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

app/src/components/top/NavBarButtons.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,14 +327,6 @@ function navbarDropDown(props) {
327327
<path d="M6.5 1h3a.5.5 0 0 1 .5.5v1H6v-1a.5.5 0 0 1 .5-.5ZM11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3A1.5 1.5 0 0 0 5 1.5v1H2.506a.58.58 0 0 0-.01 0H1.5a.5.5 0 0 0 0 1h.538l.853 10.66A2 2 0 0 0 4.885 16h6.23a2 2 0 0 0 1.994-1.84l.853-10.66h.538a.5.5 0 0 0 0-1h-.995a.59.59 0 0 0-.01 0H11Zm1.958 1-.846 10.58a1 1 0 0 1-.997.92h-6.23a1 1 0 0 1-.997-.92L3.042 3.5h9.916Zm-7.487 1a.5.5 0 0 1 .528.47l.5 8.5a.5.5 0 0 1-.998.06L5 5.03a.5.5 0 0 1 .47-.53Zm5.058 0a.5.5 0 0 1 .47.53l-.5 8.5a.5.5 0 1 1-.998-.06l.5-8.5a.5.5 0 0 1 .528-.47ZM8 4.5a.5.5 0 0 1 .5.5v8.5a.5.5 0 0 1-1 0V5a.5.5 0 0 1 .5-.5Z" />
328328
</svg>
329329
</button>
330-
<<<<<<< HEAD
331-
{/* {<ExportButton />} */}
332-
{/*
333-
<button onClick={handleDarkModeToggle}>
334-
{isDarkMode ? 'Light' : 'Dark'} Mode {switchDark}
335-
</button> */}
336-
=======
337-
>>>>>>> dev
338330
{state.isLoggedIn && (
339331
<button onClick={handleClick}>
340332
Manage Project

server/controllers/userController.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ const randomPassword = () => {
2525
};
2626

2727
const userController: UserController = {
28+
//get username for join-room display
29+
getUsername: async (req, res, next) => {
30+
try{
31+
const { username } = req.body;
32+
const user = await Users.findOne({username})
33+
return next()
34+
} catch(err) {
35+
return next({
36+
log: 'error cuaght in getUsername middleware',
37+
status: 400,
38+
message: {err: 'cannot get username'}
39+
})
40+
}
41+
},
2842
createUser: (req, res, next) => {
2943
let email, username, password;
3044
// use this condition for Oauth login
@@ -127,6 +141,8 @@ const userController: UserController = {
127141
}
128142
});
129143
}
130-
};
144+
145+
146+
};
131147

132148
export default userController;

server/interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export interface newUserError extends NativeError {
4646
}
4747

4848
export interface UserController {
49+
getUsername: RequestHandler;
4950
createUser: RequestHandler;
5051
verifyUser: RequestHandler;
5152
}

server/server.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,20 @@ const io = new Server(httpServer, {
9595
}
9696
});
9797

98+
const usersInRoom = [];
99+
98100
io.on('connection', (socket) => {
101+
99102
console.log('Socket ID: -----', socket.id);
100-
socket.on('custom-event', (string, redux_store, room) => {
101-
console.log('Room Code', room);
103+
socket.on('set-username', (username) => {
104+
console.log('username set:', username)
105+
});
106+
socket.on('custom-event', ( string, redux_store, room, username) => {
107+
console.log('Room Code: ', room );
102108
if (room) {
103-
socket.to(room).emit('receive message', redux_store);
109+
socket.to(room).emit('receive message', redux_store, 'username: ', username);
104110
} else {
105-
socket.broadcast.emit('receive message', redux_store);
111+
socket.broadcast.emit('receive message', redux_store, 'username: ', username);
106112
}
107113
});
108114
socket.on('room-code', (roomCode) => {
@@ -111,6 +117,13 @@ io.on('connection', (socket) => {
111117
});
112118
});
113119

120+
121+
app.get('/', userController.getUsername, (req, res) =>{
122+
const username = req.body.username
123+
console.log(username)
124+
usersInRoom.push(username)
125+
return res.status(200).json({username: username})
126+
});
114127
/*
115128
GraphQl Router
116129
*/
@@ -170,7 +183,7 @@ app.post(
170183
cookieController.setSSIDCookie,
171184
sessionController.startSession,
172185
(req, res) => res.status(200).json({ sessionId: res.locals.ssid })
173-
);
186+
);
174187

175188
//confirming whether user is logged in for index.tsx rendering
176189
app.get('/loggedIn', sessionController.isLoggedIn, (req, res) =>

0 commit comments

Comments
 (0)