mirror of
https://github.com/chsakell/aspnet-core-signalr-angular.git
synced 2025-12-22 09:17:47 +00:00
35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.SignalR;
|
|
using LiveGameFeed.Models;
|
|
|
|
namespace LiveGameFeed.Hubs
|
|
{
|
|
public class Broadcaster : Hub<IBroadcaster>
|
|
{
|
|
public override Task OnConnected()
|
|
{
|
|
// Set connection id for just connected client only
|
|
return Clients.Client(Context.ConnectionId).SetConnectionId(Context.ConnectionId);
|
|
}
|
|
|
|
// Server side methods called from client
|
|
public Task Subscribe(int matchId)
|
|
{
|
|
return Groups.Add(Context.ConnectionId, matchId.ToString());
|
|
}
|
|
|
|
public Task Unsubscribe(int matchId)
|
|
{
|
|
return Groups.Remove(Context.ConnectionId, matchId.ToString());
|
|
}
|
|
}
|
|
|
|
// Client side methods to be invoked by Broadcaster Hub
|
|
public interface IBroadcaster
|
|
{
|
|
Task SetConnectionId(string connectionId);
|
|
Task UpdateMatch(MatchViewModel match);
|
|
Task AddFeed(FeedViewModel feed);
|
|
Task AddChatMessage(ChatMessage message);
|
|
}
|
|
} |