[] SignalR 기능 활용한 채팅 기능 추가 중

This commit is contained in:
김선규 2025-04-09 17:56:02 +09:00
parent 7f9811e1a3
commit 2b37dc2746
2 changed files with 44 additions and 34 deletions

View File

@ -1,15 +1,14 @@
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)
{
Console.WriteLine($"Message received: {user}: {message}");
await Clients.All.SendAsync("ReceiveMessage", user, message);
}
// 특정 사용자에게 메시지를 보냄
@ -33,10 +32,15 @@ namespace Back.Program.Common.Chat
Console.WriteLine("OnDisconnectedAsync");
await base.OnDisconnectedAsync(exception);
}
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);
}
}
/*
*/

View File

@ -0,0 +1,6 @@
namespace Back.Program.Controllers.V1;
public class ChatController
{
}