sonarr-repo-only/NzbDrone.Host/Owin/MiddleWare/SignalRMiddleWare.cs

35 lines
1.2 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2013-05-05 21:24:33 +00:00
using Microsoft.AspNet.SignalR;
using NzbDrone.Api.SignalR;
2013-05-10 23:53:50 +00:00
using NzbDrone.Common.Composition;
using Owin;
namespace NzbDrone.Host.Owin.MiddleWare
{
public class SignalRMiddleWare : IOwinMiddleWare
{
2013-05-05 21:24:33 +00:00
private readonly IEnumerable<NzbDronePersistentConnection> _persistentConnections;
2013-05-05 21:24:33 +00:00
public int Order { get { return 0; } }
2013-05-10 23:53:50 +00:00
public SignalRMiddleWare(IEnumerable<NzbDronePersistentConnection> persistentConnections, IContainer container)
{
2013-05-05 21:24:33 +00:00
_persistentConnections = persistentConnections;
SignalrDependencyResolver.Register(container);
GlobalHost.Configuration.DisconnectTimeout = TimeSpan.FromSeconds(300000);
}
public void Attach(IAppBuilder appBuilder)
{
2013-05-05 21:24:33 +00:00
foreach (var nzbDronePersistentConnection in _persistentConnections)
{
var url = string.Format("signalr/{0}", nzbDronePersistentConnection.Resource.Trim('/'));
appBuilder.MapConnection(url, nzbDronePersistentConnection.GetType(), new ConnectionConfiguration { EnableCrossDomain = true });
2013-05-05 21:24:33 +00:00
}
}
}
}