mirror of
https://github.com/chsakell/aspnet-core-signalr-angular.git
synced 2025-12-22 17:27:48 +00:00
add Hub client interface
This commit is contained in:
@@ -44,7 +44,7 @@ namespace LiveGameFeed.Controllers
|
|||||||
|
|
||||||
FeedViewModel _feedVM = Mapper.Map<Feed, FeedViewModel>(_matchFeed);
|
FeedViewModel _feedVM = Mapper.Map<Feed, FeedViewModel>(_matchFeed);
|
||||||
|
|
||||||
await Clients.Group(feed.MatchId.ToString()).addFeed(_feedVM);
|
await Clients.Group(feed.MatchId.ToString()).AddFeed(_feedVM);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace LiveGameFeed.Controllers
|
|||||||
_matchRepository.Commit();
|
_matchRepository.Commit();
|
||||||
|
|
||||||
MatchViewModel _matchVM = Mapper.Map<Match, MatchViewModel>(_match);
|
MatchViewModel _matchVM = Mapper.Map<Match, MatchViewModel>(_match);
|
||||||
await Clients.All.updateMatch(_matchVM);
|
await Clients.All.UpdateMatch(_matchVM);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace LiveGameFeed.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void Post([FromBody]ChatMessage message)
|
public void Post([FromBody]ChatMessage message)
|
||||||
{
|
{
|
||||||
this.Clients.Group(message.MatchId.ToString()).addChatMessage(message);
|
this.Clients.Group(message.MatchId.ToString()).AddChatMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
|
using LiveGameFeed.Models;
|
||||||
|
|
||||||
namespace LiveGameFeed.Hubs
|
namespace LiveGameFeed.Hubs
|
||||||
{
|
{
|
||||||
public class Broadcaster : Hub
|
public class Broadcaster : Hub<IBroadcaster>
|
||||||
{
|
{
|
||||||
public override Task OnConnected()
|
public override Task OnConnected()
|
||||||
{
|
{
|
||||||
// Set connection id for just connected client only
|
// Set connection id for just connected client only
|
||||||
return Clients.Client(Context.ConnectionId).setConnectionId(Context.ConnectionId);
|
return Clients.Client(Context.ConnectionId).SetConnectionId(Context.ConnectionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Server side methods called from client
|
// Server side methods called from client
|
||||||
@@ -22,4 +23,12 @@ namespace LiveGameFeed.Hubs
|
|||||||
return Groups.Remove(Context.ConnectionId, matchId.ToString());
|
return Groups.Remove(Context.ConnectionId, matchId.ToString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface IBroadcaster
|
||||||
|
{
|
||||||
|
Task SetConnectionId(string connectionId);
|
||||||
|
Task UpdateMatch(MatchViewModel match);
|
||||||
|
Task AddFeed(FeedViewModel feed);
|
||||||
|
Task AddChatMessage(ChatMessage message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user