3.2.25.10

This commit is contained in:
Luke Pulverenti 2017-07-20 16:37:13 -04:00
parent 154ddbd963
commit d826b98449
5 changed files with 54 additions and 60 deletions

View File

@ -26,32 +26,34 @@ namespace Emby.Dlna.Eventing
_logger = logger; _logger = logger;
} }
public EventSubscriptionResponse RenewEventSubscription(string subscriptionId, int? timeoutSeconds) public EventSubscriptionResponse RenewEventSubscription(string subscriptionId, string requestedTimeoutString)
{ {
var timeout = timeoutSeconds ?? 300;
var subscription = GetSubscription(subscriptionId, true); var subscription = GetSubscription(subscriptionId, true);
_logger.Debug("Renewing event subscription for {0} with timeout of {1} to {2}", // Remove logging for now because some devices are sending this very frequently
subscription.NotificationType, // TODO re-enable with dlna debug logging setting
timeout, //_logger.Debug("Renewing event subscription for {0} with timeout of {1} to {2}",
subscription.CallbackUrl); // subscription.NotificationType,
// timeout,
// subscription.CallbackUrl);
subscription.TimeoutSeconds = timeout; subscription.TimeoutSeconds = ParseTimeout(requestedTimeoutString) ?? 300;
subscription.SubscriptionTime = DateTime.UtcNow; subscription.SubscriptionTime = DateTime.UtcNow;
return GetEventSubscriptionResponse(subscriptionId, timeout); return GetEventSubscriptionResponse(subscriptionId, requestedTimeoutString, subscription.TimeoutSeconds);
} }
public EventSubscriptionResponse CreateEventSubscription(string notificationType, int? timeoutSeconds, string callbackUrl) public EventSubscriptionResponse CreateEventSubscription(string notificationType, string requestedTimeoutString, string callbackUrl)
{ {
var timeout = timeoutSeconds ?? 300; var timeout = ParseTimeout(requestedTimeoutString) ?? 300;
var id = "uuid:" + Guid.NewGuid().ToString("N"); var id = "uuid:" + Guid.NewGuid().ToString("N");
_logger.Debug("Creating event subscription for {0} with timeout of {1} to {2}", // Remove logging for now because some devices are sending this very frequently
notificationType, // TODO re-enable with dlna debug logging setting
timeout, //_logger.Debug("Creating event subscription for {0} with timeout of {1} to {2}",
callbackUrl); // notificationType,
// timeout,
// callbackUrl);
_subscriptions.TryAdd(id, new EventSubscription _subscriptions.TryAdd(id, new EventSubscription
{ {
@ -61,7 +63,25 @@ namespace Emby.Dlna.Eventing
TimeoutSeconds = timeout TimeoutSeconds = timeout
}); });
return GetEventSubscriptionResponse(id, timeout); return GetEventSubscriptionResponse(id, requestedTimeoutString, timeout);
}
private int? ParseTimeout(string header)
{
if (!string.IsNullOrEmpty(header))
{
// Starts with SECOND-
header = header.Split('-').Last();
int val;
if (int.TryParse(header, NumberStyles.Any, _usCulture, out val))
{
return val;
}
}
return null;
} }
public EventSubscriptionResponse CancelEventSubscription(string subscriptionId) public EventSubscriptionResponse CancelEventSubscription(string subscriptionId)
@ -73,22 +93,22 @@ namespace Emby.Dlna.Eventing
return new EventSubscriptionResponse return new EventSubscriptionResponse
{ {
Content = "\r\n", Content = string.Empty,
ContentType = "text/plain" ContentType = "text/plain"
}; };
} }
private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private EventSubscriptionResponse GetEventSubscriptionResponse(string subscriptionId, int timeoutSeconds) private EventSubscriptionResponse GetEventSubscriptionResponse(string subscriptionId, string requestedTimeoutString, int timeoutSeconds)
{ {
var response = new EventSubscriptionResponse var response = new EventSubscriptionResponse
{ {
Content = "\r\n", Content = string.Empty,
ContentType = "text/plain" ContentType = "text/plain"
}; };
response.Headers["SID"] = subscriptionId; response.Headers["SID"] = subscriptionId;
response.Headers["TIMEOUT"] = "SECOND-" + timeoutSeconds.ToString(_usCulture); response.Headers["TIMEOUT"] = string.IsNullOrWhiteSpace(requestedTimeoutString) ? ("SECOND-" + timeoutSeconds.ToString(_usCulture)) : requestedTimeoutString;
return response; return response;
} }

View File

@ -24,14 +24,14 @@ namespace Emby.Dlna.Service
return EventManager.CancelEventSubscription(subscriptionId); return EventManager.CancelEventSubscription(subscriptionId);
} }
public EventSubscriptionResponse RenewEventSubscription(string subscriptionId, int? timeoutSeconds) public EventSubscriptionResponse RenewEventSubscription(string subscriptionId, string timeoutString)
{ {
return EventManager.RenewEventSubscription(subscriptionId, timeoutSeconds); return EventManager.RenewEventSubscription(subscriptionId, timeoutString);
} }
public EventSubscriptionResponse CreateEventSubscription(string notificationType, int? timeoutSeconds, string callbackUrl) public EventSubscriptionResponse CreateEventSubscription(string notificationType, string timeoutString, string callbackUrl)
{ {
return EventManager.CreateEventSubscription(notificationType, timeoutSeconds, callbackUrl); return EventManager.CreateEventSubscription(notificationType, timeoutString, callbackUrl);
} }
} }
} }

View File

@ -219,20 +219,20 @@ namespace MediaBrowser.Api.Dlna
private object ProcessEventRequest(IEventManager eventManager) private object ProcessEventRequest(IEventManager eventManager)
{ {
var subscriptionId = GetHeader("SID"); var subscriptionId = GetHeader("SID");
var notificationType = GetHeader("NT");
var callback = GetHeader("CALLBACK");
var timeoutString = GetHeader("TIMEOUT");
var timeout = ParseTimeout(timeoutString);
if (string.Equals(Request.Verb, "SUBSCRIBE", StringComparison.OrdinalIgnoreCase)) if (string.Equals(Request.Verb, "SUBSCRIBE", StringComparison.OrdinalIgnoreCase))
{ {
var notificationType = GetHeader("NT");
var callback = GetHeader("CALLBACK");
var timeoutString = GetHeader("TIMEOUT");
if (string.IsNullOrEmpty(notificationType)) if (string.IsNullOrEmpty(notificationType))
{ {
return GetSubscriptionResponse(eventManager.RenewEventSubscription(subscriptionId, timeout)); return GetSubscriptionResponse(eventManager.RenewEventSubscription(subscriptionId, timeoutString));
} }
return GetSubscriptionResponse(eventManager.CreateEventSubscription(notificationType, timeout, callback)); return GetSubscriptionResponse(eventManager.CreateEventSubscription(notificationType, timeoutString, callback));
} }
return GetSubscriptionResponse(eventManager.CancelEventSubscription(subscriptionId)); return GetSubscriptionResponse(eventManager.CancelEventSubscription(subscriptionId));
@ -242,24 +242,5 @@ namespace MediaBrowser.Api.Dlna
{ {
return ResultFactory.GetResult(response.Content, response.ContentType, response.Headers); return ResultFactory.GetResult(response.Content, response.ContentType, response.Headers);
} }
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private int? ParseTimeout(string header)
{
if (!string.IsNullOrEmpty(header))
{
// Starts with SECOND-
header = header.Split('-').Last();
int val;
if (int.TryParse(header, NumberStyles.Any, _usCulture, out val))
{
return val;
}
}
return null;
}
} }
} }

View File

@ -12,18 +12,11 @@ namespace MediaBrowser.Controller.Dlna
/// <summary> /// <summary>
/// Renews the event subscription. /// Renews the event subscription.
/// </summary> /// </summary>
/// <param name="subscriptionId">The subscription identifier.</param> EventSubscriptionResponse RenewEventSubscription(string subscriptionId, string requestedTimeoutString);
/// <param name="timeoutSeconds">The timeout seconds.</param>
/// <returns>EventSubscriptionResponse.</returns>
EventSubscriptionResponse RenewEventSubscription(string subscriptionId, int? timeoutSeconds);
/// <summary> /// <summary>
/// Creates the event subscription. /// Creates the event subscription.
/// </summary> /// </summary>
/// <param name="notificationType">Type of the notification.</param> EventSubscriptionResponse CreateEventSubscription(string notificationType, string requestedTimeoutString, string callbackUrl);
/// <param name="timeoutSeconds">The timeout seconds.</param>
/// <param name="callbackUrl">The callback URL.</param>
/// <returns>EventSubscriptionResponse.</returns>
EventSubscriptionResponse CreateEventSubscription(string notificationType, int? timeoutSeconds, string callbackUrl);
} }
} }

View File

@ -1,3 +1,3 @@
using System.Reflection; using System.Reflection;
[assembly: AssemblyVersion("3.2.25.9")] [assembly: AssemblyVersion("3.2.25.10")]