integrate Web API and SignalR

This commit is contained in:
chsakell
2016-09-25 13:52:43 +03:00
parent 1041e79bb5
commit decb0e5bea
3 changed files with 44 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.AspNetCore.SignalR.Infrastructure;
using Microsoft.AspNetCore.SignalR.Hubs;
namespace LiveGameFeed.Controllers
{
public abstract class ApiHubController<T> : Controller
where T : Hub
{
private readonly IHubContext _hub;
public IHubConnectionContext<dynamic> Clients { get; private set; }
public IGroupManager Groups { get; private set; }
protected ApiHubController(IConnectionManager signalRConnectionManager)
{
var _hub = signalRConnectionManager.GetHubContext<T>();
Clients = _hub.Clients;
Groups = _hub.Groups;
}
}
}

View File

@@ -3,12 +3,17 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR.Infrastructure;
using LiveGameFeed.Hubs;
namespace LiveGameFeed.Controllers
{
[Route("api/[controller]")]
public class ValuesController : Controller
public class ValuesController : ApiHubController<Broadcaster>
{
public ValuesController(IConnectionManager signalRConnectionManager)
: base(signalRConnectionManager) { }
// GET api/values
[HttpGet]
public IEnumerable<string> Get()