업데이트
This commit is contained in:
parent
85feb2e1e6
commit
011535a450
22
.vscode/settings.json
vendored
Normal file
22
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"workbench.colorCustomizations": {
|
||||||
|
"activityBar.activeBackground": "#ff6433",
|
||||||
|
"activityBar.background": "#ff6433",
|
||||||
|
"activityBar.foreground": "#15202b",
|
||||||
|
"activityBar.inactiveForeground": "#15202b99",
|
||||||
|
"activityBarBadge.background": "#00ff3d",
|
||||||
|
"activityBarBadge.foreground": "#15202b",
|
||||||
|
"commandCenter.border": "#e7e7e799",
|
||||||
|
"sash.hoverBorder": "#ff6433",
|
||||||
|
"statusBar.background": "#ff3d00",
|
||||||
|
"statusBar.foreground": "#e7e7e7",
|
||||||
|
"statusBarItem.hoverBackground": "#ff6433",
|
||||||
|
"statusBarItem.remoteBackground": "#ff3d00",
|
||||||
|
"statusBarItem.remoteForeground": "#e7e7e7",
|
||||||
|
"titleBar.activeBackground": "#ff3d00",
|
||||||
|
"titleBar.activeForeground": "#e7e7e7",
|
||||||
|
"titleBar.inactiveBackground": "#ff3d0099",
|
||||||
|
"titleBar.inactiveForeground": "#e7e7e799"
|
||||||
|
},
|
||||||
|
"peacock.color": "#ff3d00"
|
||||||
|
}
|
37
src/index.js
37
src/index.js
@ -86,42 +86,10 @@ app.use('/v1', compaign);
|
|||||||
app.use('/v1/chat', chatRoutes);
|
app.use('/v1/chat', chatRoutes);
|
||||||
|
|
||||||
|
|
||||||
// io.on('connection', (socket) => {
|
|
||||||
// console.log(`클라이언트 연결됨: ${socket.id}`);
|
|
||||||
|
|
||||||
// // 클라이언트로부터 메시지 수신
|
|
||||||
// socket.on('message', async (data) => {
|
|
||||||
// console.log('받은 메시지:', data);
|
|
||||||
|
|
||||||
// // MongoDB에 메시지 저장
|
|
||||||
// const newMessage = new ChatMessage({
|
|
||||||
// username: data.username,
|
|
||||||
// message: data.message,
|
|
||||||
// });
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// await newMessage.save();
|
|
||||||
// // 연결된 모든 클라이언트에게 메시지 브로드캐스트
|
|
||||||
// io.emit('message', newMessage);
|
|
||||||
// } catch (error) {
|
|
||||||
// console.error('메시지 저장 중 오류:', error);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
|
|
||||||
// // 클라이언트 연결 종료 처리
|
|
||||||
// socket.on('disconnect', () => {
|
|
||||||
// console.log(`클라이언트 연결 해제: ${socket.id}`);
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
io.on('connection', (socket) => {
|
io.on('connection', (socket) => {
|
||||||
console.log(`클라이언트 연결됨: ${socket.id}`);
|
|
||||||
|
|
||||||
// 사용자 방 참여
|
// 사용자 방 참여
|
||||||
socket.on('join', (email) => {
|
socket.on('join', (room) => {
|
||||||
console.log(`${email} joined room: ${email}`);
|
socket.join(room); // 사용자를 이메일 기반으로 방에 참여시킴
|
||||||
socket.join(email); // 사용자를 이메일 기반으로 방에 참여시킴
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 클라이언트로부터 메시지 수신
|
// 클라이언트로부터 메시지 수신
|
||||||
@ -132,6 +100,7 @@ io.on('connection', (socket) => {
|
|||||||
// MongoDB에 메시지 저장
|
// MongoDB에 메시지 저장
|
||||||
const newMessage = new ChatMessage({
|
const newMessage = new ChatMessage({
|
||||||
username,
|
username,
|
||||||
|
to:targetEmail,
|
||||||
message,
|
message,
|
||||||
timestamp: new Date(),
|
timestamp: new Date(),
|
||||||
});
|
});
|
||||||
|
@ -2,6 +2,7 @@ const mongoose = require('mongoose');
|
|||||||
|
|
||||||
const ChatMessageSchema = new mongoose.Schema({
|
const ChatMessageSchema = new mongoose.Schema({
|
||||||
username: { type: String, required: true },
|
username: { type: String, required: true },
|
||||||
|
to: { type: String, required: true },
|
||||||
message: { type: String, required: true },
|
message: { type: String, required: true },
|
||||||
timestamp: { type: Date, default: Date.now },
|
timestamp: { type: Date, default: Date.now },
|
||||||
});
|
});
|
||||||
|
@ -6,6 +6,7 @@ const router = express.Router();
|
|||||||
router.get('/messages', async (req, res) => {
|
router.get('/messages', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { email } = req.query;
|
const { email } = req.query;
|
||||||
|
|
||||||
|
|
||||||
if (!email) {
|
if (!email) {
|
||||||
return res.status(400).json({ success: false, message: 'Email parameter is required.' });
|
return res.status(400).json({ success: false, message: 'Email parameter is required.' });
|
||||||
@ -14,7 +15,6 @@ router.get('/messages', async (req, res) => {
|
|||||||
// 이메일 배열로 필터링
|
// 이메일 배열로 필터링
|
||||||
const emailArray = email.split(',');
|
const emailArray = email.split(',');
|
||||||
const messages = await ChatMessage.find({ username: { $in: emailArray } }).sort({ timestamp: 1 });
|
const messages = await ChatMessage.find({ username: { $in: emailArray } }).sort({ timestamp: 1 });
|
||||||
|
|
||||||
res.json(messages);
|
res.json(messages);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({ success: false, message: error.message });
|
res.status(500).json({ success: false, message: error.message });
|
||||||
|
Loading…
Reference in New Issue
Block a user