From b637f119c83eb78afe4a345f0c219b8aee60e0c5 Mon Sep 17 00:00:00 2001 From: chsakell Date: Mon, 10 Oct 2016 09:42:43 +0300 Subject: [PATCH] add Hub client interface --- Controllers/FeedsController.cs | 2 +- Controllers/MatchesController.cs | 2 +- Controllers/MessagesController.cs | 2 +- Hubs/Broadcaster.cs | 13 +++++++++++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Controllers/FeedsController.cs b/Controllers/FeedsController.cs index 1b5564a..659cbfc 100644 --- a/Controllers/FeedsController.cs +++ b/Controllers/FeedsController.cs @@ -44,7 +44,7 @@ namespace LiveGameFeed.Controllers FeedViewModel _feedVM = Mapper.Map(_matchFeed); - await Clients.Group(feed.MatchId.ToString()).addFeed(_feedVM); + await Clients.Group(feed.MatchId.ToString()).AddFeed(_feedVM); } } diff --git a/Controllers/MatchesController.cs b/Controllers/MatchesController.cs index 7741a9e..4247f41 100644 --- a/Controllers/MatchesController.cs +++ b/Controllers/MatchesController.cs @@ -43,7 +43,7 @@ namespace LiveGameFeed.Controllers _matchRepository.Commit(); MatchViewModel _matchVM = Mapper.Map(_match); - await Clients.All.updateMatch(_matchVM); + await Clients.All.UpdateMatch(_matchVM); } } } diff --git a/Controllers/MessagesController.cs b/Controllers/MessagesController.cs index 6b14d5c..86efe4f 100644 --- a/Controllers/MessagesController.cs +++ b/Controllers/MessagesController.cs @@ -19,7 +19,7 @@ namespace LiveGameFeed.Controllers [HttpPost] public void Post([FromBody]ChatMessage message) { - this.Clients.Group(message.MatchId.ToString()).addChatMessage(message); + this.Clients.Group(message.MatchId.ToString()).AddChatMessage(message); } } } diff --git a/Hubs/Broadcaster.cs b/Hubs/Broadcaster.cs index 8ab6585..9b44956 100644 --- a/Hubs/Broadcaster.cs +++ b/Hubs/Broadcaster.cs @@ -1,14 +1,15 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.SignalR; +using LiveGameFeed.Models; namespace LiveGameFeed.Hubs { - public class Broadcaster : Hub + public class Broadcaster : Hub { public override Task OnConnected() { // 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 @@ -22,4 +23,12 @@ namespace LiveGameFeed.Hubs 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); + } } \ No newline at end of file