Start transport before endpoint
This commit is contained in:
parent
b6f15338eb
commit
a175609bb1
|
|
@ -3,28 +3,14 @@ using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
namespace ChatSample.Controllers
|
namespace ChatSample.Controllers
|
||||||
{
|
{
|
||||||
[Authorize]
|
|
||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
|
[Authorize]
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult About()
|
|
||||||
{
|
|
||||||
ViewData["Message"] = "Your application description page.";
|
|
||||||
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActionResult Contact()
|
|
||||||
{
|
|
||||||
ViewData["Message"] = "Your contact page.";
|
|
||||||
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActionResult Error()
|
public IActionResult Error()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
namespace ChatSample.Hubs
|
namespace ChatSample.Hubs
|
||||||
{
|
{
|
||||||
|
// TODO: Make this work
|
||||||
|
[Authorize]
|
||||||
public class Chat : Hub
|
public class Chat : Hub
|
||||||
{
|
{
|
||||||
public override Task OnConnectedAsync()
|
public override Task OnConnectedAsync()
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,13 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
// Mark the connection as active
|
// Mark the connection as active
|
||||||
state.Active = true;
|
state.Active = true;
|
||||||
|
|
||||||
|
RegisterLongPollingDisconnect(context, state.Connection);
|
||||||
|
|
||||||
|
var longPolling = new LongPolling(state.Connection);
|
||||||
|
|
||||||
|
// Start the transport
|
||||||
|
var transportTask = longPolling.ProcessRequest(context);
|
||||||
|
|
||||||
Task endpointTask = null;
|
Task endpointTask = null;
|
||||||
|
|
||||||
// Raise OnConnected for new connections only since polls happen all the time
|
// Raise OnConnected for new connections only since polls happen all the time
|
||||||
|
|
@ -112,13 +119,6 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
endpointTask = (Task)state.Connection.Metadata["endpoint"];
|
endpointTask = (Task)state.Connection.Metadata["endpoint"];
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisterLongPollingDisconnect(context, state.Connection);
|
|
||||||
|
|
||||||
var longPolling = new LongPolling(state.Connection);
|
|
||||||
|
|
||||||
// Start the transport
|
|
||||||
var transportTask = longPolling.ProcessRequest(context);
|
|
||||||
|
|
||||||
var resultTask = await Task.WhenAny(endpointTask, transportTask);
|
var resultTask = await Task.WhenAny(endpointTask, transportTask);
|
||||||
|
|
||||||
if (resultTask == endpointTask)
|
if (resultTask == endpointTask)
|
||||||
|
|
@ -144,12 +144,12 @@ namespace Microsoft.AspNetCore.Sockets
|
||||||
// Register this transport for disconnect
|
// Register this transport for disconnect
|
||||||
RegisterDisconnect(context, connection);
|
RegisterDisconnect(context, connection);
|
||||||
|
|
||||||
// Call into the end point passing the connection
|
|
||||||
var endpointTask = endpoint.OnConnected(connection);
|
|
||||||
|
|
||||||
// Start the transport
|
// Start the transport
|
||||||
var transportTask = transport.ProcessRequest(context);
|
var transportTask = transport.ProcessRequest(context);
|
||||||
|
|
||||||
|
// Call into the end point passing the connection
|
||||||
|
var endpointTask = endpoint.OnConnected(connection);
|
||||||
|
|
||||||
// Wait for any of them to end
|
// Wait for any of them to end
|
||||||
await Task.WhenAny(endpointTask, transportTask);
|
await Task.WhenAny(endpointTask, transportTask);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue