Add GameController with SignalR functionality for joining games
This commit is contained in:
@@ -11,4 +11,10 @@
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Models\" />
|
||||
<Folder Include="Repository\" />
|
||||
<Folder Include="Services\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace API.Controllers;
|
||||
|
||||
public class GameController : Hub
|
||||
{
|
||||
public async Task JoinGame(string gameId, string playerName)
|
||||
{
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId, gameId);
|
||||
await Clients.Group(gameId).SendAsync("PlayerJoined", new
|
||||
{
|
||||
ConnectionId = Context.ConnectionId,
|
||||
PlayerName = playerName
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user