Skip to content

Commit

Permalink
resolve: resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
June1010 committed Dec 17, 2022
2 parents bab12e4 + 20fb878 commit 7e80b82
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
5 changes: 5 additions & 0 deletions chat-server/src/queue-manager/manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export class ManagerService {
getSocket(name: string): Socket {
return this.socketMap.get(name);
}
// ์˜จ๋ผ์ธ์ธ ์œ ์ € ์ƒํƒœ ๊ด€๋ฆฌ -> ๊ทธ๋ž˜์•ผ send ์ด๋ฒคํŠธ๋ฅผ ๋ฐœ์ƒ์„ ์‹œ์ผœ์„œ ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๋‹ˆ๊น
// ์˜จ๋ผ์ธ์ด๋ฉด -> ๋ฐ”๋กœ ์ „์†ก
// ์˜คํ”„๋ผ์ธ์ด๋ฉด -> ํ์— ๋ˆ„์ 

// ์ง€๊ธˆ Cache Module์—์„œ ์‚ฌ์šฉํ•˜๋Š”๊ฑด, ๋ ˆ๋””์Šค์ธ๋ฐ, Cache Module ๋ฉ”๋ชจ๋ฆฌ์™€ ๋ ˆ๋””์Šค๋ฅผ ํ•จ๊ป˜ ์“ธ ์ˆœ ์—†์„๊นŒ?

setSocket(userId: string, socket: Socket): void {
this.socketMap.set(userId, socket);
Expand Down
1 change: 1 addition & 0 deletions chat-server/src/socket.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class SocketGateway implements OnGatewayDisconnect {
done();
});
} catch (err) {}
console.log(queue);
await queue.resume();
}
// + ์ด์ „ ๋ฉ”์‹œ์ง€๋ฅผ ๋ฆฌ๋ฒ„์Šค ์ธํ”ผ๋‹ˆํŠธ ์Šคํฌ๋กค๋กœ ๋ณด๋‚ด์ฃผ๊ธฐ
Expand Down
5 changes: 3 additions & 2 deletions chat-server/src/socket.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ export class SocketService {
}

async getRecentMessage(recruitId: number, page = 1, unReadCount = 0) {
console.log('unreadCount: ', unReadCount);
const response = await this.chatModel
.find({ recruitId })
.sort({ createdAt: -1 })
.skip((page - 1) * 20 + unReadCount)
.limit(20);
.skip((page - 1) * 10 + unReadCount)
.limit(10);
return response.reverse();
}

Expand Down
53 changes: 53 additions & 0 deletions client/src/pages/ChatTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useRef, useState } from "react";
import { io, Socket } from "socket.io-client";

type Chat = {
id: number;
sender: string; // userId
recruitId: number;
content: string;
createdAt: Date;
};

const ChatTest = () => {
const socket = useRef<Socket | null>(null);

const [recruitId, setRecruitId] = useState("");
const [message, setMessage] = useState("");
const [history, setHistory] = useState<Chat[]>([]);
const [userId, setUserId] = useState("");
const connect = () => {
socket.current = io(`http://localhost:8080/chat`);
socket.current.emit("join", { userId, recruitId });
socket.current.once("server_sent_recent", (message: Chat[]) => setHistory((prev) => [...prev, ...message]));
socket.current.on("server_sent", (message: Chat) => setHistory((prev) => [...prev, message]));
};

const onClickSend = () => {
if (!socket.current) return;
socket.current.emit("client_sent", { content: message });
};

return (
<div>
<div>
<input placeholder="userId" onChange={(e) => setUserId(e.target.value)} />
<input placeholder="recruitId" onChange={(e) => setRecruitId(e.target.value)} />
<button onClick={connect}>์†Œ์ผ“์—ฐ๊ฒฐ</button>
</div>
<input placeholder="message" onChange={(e) => setMessage(e.target.value)}></input>
<button onClick={onClickSend}>์ „์†ก</button>
{history.map((msg) => {
return (
<>
<div>sender : {msg.sender}</div>
<div>content : {msg.content}</div>
<br />
</>
);
})}
</div>
);
};

export default ChatTest;

0 comments on commit 7e80b82

Please sign in to comment.