diff --git a/Program/Common/Chat/ChatHub.cs b/Program/Common/Chat/ChatHub.cs index 6e8a9c0..28c0e4b 100644 --- a/Program/Common/Chat/ChatHub.cs +++ b/Program/Common/Chat/ChatHub.cs @@ -1,42 +1,46 @@ using Microsoft.AspNetCore.SignalR; -namespace Back.Program.Common.Chat +namespace Back.Program.Common.Chat; + +public class ChatHub : Hub { - public class ChatHub : Hub + // 클라이언트에서 메시지를 보내면 모든 사용자에게 전송 + public async Task SendMessage(string user, string message) { - // 클라이언트에서 메시지를 보내면 모든 사용자에게 전송 - public async Task SendMessage(string user, string message) - { - Console.WriteLine($"Message received: {user}: {message}"); - await Clients.All.SendAsync("ReceiveMessage", user, message); - - } - - // 특정 사용자에게 메시지를 보냄 - public async Task SendMessageToUser(string connectionId, string message) - { - await Clients.Client(connectionId).SendAsync("ReceiveMessage", message); - } - - // 클라이언트가 연결될 때 호출 - public override async Task OnConnectedAsync() - { - await Clients.Caller.SendAsync("ReceiveMessage", "System", $"Welcome! Your ID: {Context.ConnectionId}"); - Console.WriteLine("OnConnectedAsync"); - await base.OnConnectedAsync(); - } - - // 클라이언트가 연결 해제될 때 호출 - public override async Task OnDisconnectedAsync(Exception? exception) - { - await Clients.All.SendAsync("ReceiveMessage", "System", $"{Context.ConnectionId} disconnected"); - Console.WriteLine("OnDisconnectedAsync"); - await base.OnDisconnectedAsync(exception); - } + Console.WriteLine($"Message received: {user}: {message}"); + await Clients.All.SendAsync("ReceiveMessage", user, message); } -} -/* + // 특정 사용자에게 메시지를 보냄 + public async Task SendMessageToUser(string connectionId, string message) + { + await Clients.Client(connectionId).SendAsync("ReceiveMessage", message); + } + + // 클라이언트가 연결될 때 호출 + public override async Task OnConnectedAsync() + { + await Clients.Caller.SendAsync("ReceiveMessage", "System", $"Welcome! Your ID: {Context.ConnectionId}"); + Console.WriteLine("OnConnectedAsync"); + await base.OnConnectedAsync(); + } + + // 클라이언트가 연결 해제될 때 호출 + public override async Task OnDisconnectedAsync(Exception? exception) + { + await Clients.All.SendAsync("ReceiveMessage", "System", $"{Context.ConnectionId} disconnected"); + Console.WriteLine("OnDisconnectedAsync"); + await base.OnDisconnectedAsync(exception); + } -*/ \ No newline at end of file + public async Task JoinRoom(string cid) + { + await Groups.AddToGroupAsync(Context.ConnectionId, cid); + } + + public async Task JoinGroup(string cid, string groupName) + { + await Groups.AddToGroupAsync(Context.ConnectionId, groupName); + } +} \ No newline at end of file diff --git a/Program/Controllers/V1/ChatController.cs b/Program/Controllers/V1/ChatController.cs new file mode 100644 index 0000000..0fcd9ed --- /dev/null +++ b/Program/Controllers/V1/ChatController.cs @@ -0,0 +1,6 @@ +namespace Back.Program.Controllers.V1; + +public class ChatController +{ + +} \ No newline at end of file