|
|
@ -1,4 +1,4 @@
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Microsoft.AspNet.SignalR;
|
|
|
|
using Microsoft.AspNet.SignalR;
|
|
|
|
using Microsoft.AspNet.SignalR.Infrastructure;
|
|
|
|
using Microsoft.AspNet.SignalR.Infrastructure;
|
|
|
@ -12,6 +12,7 @@ namespace NzbDrone.SignalR
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public interface IBroadcastSignalRMessage
|
|
|
|
public interface IBroadcastSignalRMessage
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
bool IsConnected { get; }
|
|
|
|
void BroadcastMessage(SignalRMessage message);
|
|
|
|
void BroadcastMessage(SignalRMessage message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -21,6 +22,7 @@ namespace NzbDrone.SignalR
|
|
|
|
|
|
|
|
|
|
|
|
private static string API_KEY;
|
|
|
|
private static string API_KEY;
|
|
|
|
private readonly Dictionary<string, string> _messageHistory;
|
|
|
|
private readonly Dictionary<string, string> _messageHistory;
|
|
|
|
|
|
|
|
private HashSet<string> _connections = new HashSet<string>();
|
|
|
|
|
|
|
|
|
|
|
|
public NzbDronePersistentConnection(IConfigFileProvider configFileProvider)
|
|
|
|
public NzbDronePersistentConnection(IConfigFileProvider configFileProvider)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -28,6 +30,16 @@ namespace NzbDrone.SignalR
|
|
|
|
_messageHistory = new Dictionary<string, string>();
|
|
|
|
_messageHistory = new Dictionary<string, string>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsConnected
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
get
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_connections)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return _connections.Count != 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void BroadcastMessage(SignalRMessage message)
|
|
|
|
public void BroadcastMessage(SignalRMessage message)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -59,14 +71,34 @@ namespace NzbDrone.SignalR
|
|
|
|
|
|
|
|
|
|
|
|
protected override Task OnConnected(IRequest request, string connectionId)
|
|
|
|
protected override Task OnConnected(IRequest request, string connectionId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_connections)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_connections.Add(connectionId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return SendVersion(connectionId);
|
|
|
|
return SendVersion(connectionId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override Task OnReconnected(IRequest request, string connectionId)
|
|
|
|
protected override Task OnReconnected(IRequest request, string connectionId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_connections)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_connections.Add(connectionId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return SendVersion(connectionId);
|
|
|
|
return SendVersion(connectionId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected override Task OnDisconnected(IRequest request, string connectionId, bool stopCalled)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lock (_connections)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_connections.Remove(connectionId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return base.OnDisconnected(request, connectionId, stopCalled);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Task SendVersion(string connectionId)
|
|
|
|
private Task SendVersion(string connectionId)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Context.Connection.Send(connectionId, new SignalRMessage
|
|
|
|
return Context.Connection.Send(connectionId, new SignalRMessage
|
|
|
|