[WIP] Live flow

This commit is contained in:
Paul Schneider 2019-02-08 10:22:52 +00:00
commit ae55d9b8d8
16 changed files with 3605 additions and 100 deletions

View file

@ -1,5 +1,11 @@
using System;
using System.Net.WebSockets;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.WebSockets.Server;
namespace Yavsc
{
@ -8,8 +14,31 @@ namespace Yavsc
public void ConfigureWebSocketsApp(IApplicationBuilder app,
SiteSettings siteSettings, IHostingEnvironment env)
{
app.UseWebSockets();
var webSocketOptions = new WebSocketOptions()
{
KeepAliveInterval = TimeSpan.FromSeconds(120),
ReceiveBufferSize = 4 * 1024,
ReplaceFeature = true
};
app.UseWebSockets(webSocketOptions);
app.UseSignalR(Constants.SignalRPath);
}
private async Task Echo(HttpContext context, WebSocket webSocket)
{
var buffer = new byte[1024 * 4];
WebSocketReceiveResult result = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
while (!result.CloseStatus.HasValue)
{
await webSocket.SendAsync(new ArraySegment<byte>(buffer, 0, result.Count), result.MessageType, result.EndOfMessage, CancellationToken.None);
result = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), CancellationToken.None);
}
await webSocket.CloseAsync(result.CloseStatus.Value, result.CloseStatusDescription, CancellationToken.None);
}
}
}