Merge pull request #2763 from MediaBrowser/dev

Dev
This commit is contained in:
Luke 2017-07-20 16:37:48 -04:00 committed by GitHub
commit b43b52c237
5 changed files with 54 additions and 60 deletions

View File

@ -26,32 +26,34 @@ namespace Emby.Dlna.Eventing
_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);
_logger.Debug("Renewing event subscription for {0} with timeout of {1} to {2}",
subscription.NotificationType,
timeout,
subscription.CallbackUrl);
// Remove logging for now because some devices are sending this very frequently
// TODO re-enable with dlna debug logging setting
//_logger.Debug("Renewing event subscription for {0} with timeout of {1} to {2}",
// subscription.NotificationType,
// timeout,
// subscription.CallbackUrl);
subscription.TimeoutSeconds = timeout;
subscription.TimeoutSeconds = ParseTimeout(requestedTimeoutString) ?? 300;
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");
_logger.Debug("Creating event subscription for {0} with timeout of {1} to {2}",
notificationType,
timeout,
callbackUrl);
// Remove logging for now because some devices are sending this very frequently
// TODO re-enable with dlna debug logging setting
//_logger.Debug("Creating event subscription for {0} with timeout of {1} to {2}",
// notificationType,
// timeout,
// callbackUrl);
_subscriptions.TryAdd(id, new EventSubscription
{
@ -61,7 +63,25 @@ namespace Emby.Dlna.Eventing
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)
@ -73,22 +93,22 @@ namespace Emby.Dlna.Eventing
return new EventSubscriptionResponse
{
Content = "\r\n",
Content = string.Empty,
ContentType = "text/plain"
};
}
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
{
Content = "\r\n",
Content = string.Empty,
ContentType = "text/plain"
};
response.Headers["SID"] = subscriptionId;
response.Headers["TIMEOUT"] = "SECOND-" + timeoutSeconds.ToString(_usCulture);
response.Headers["TIMEOUT"] = string.IsNullOrWhiteSpace(requestedTimeoutString) ? ("SECOND-" + timeoutSeconds.ToString(_usCulture)) : requestedTimeoutString;
return response;
}

View File

@ -24,14 +24,14 @@ namespace Emby.Dlna.Service
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)
{
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))
{
var notificationType = GetHeader("NT");
var callback = GetHeader("CALLBACK");
var timeoutString = GetHeader("TIMEOUT");
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));
@ -242,24 +242,5 @@ namespace MediaBrowser.Api.Dlna
{
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>
/// Renews the event subscription.
/// </summary>
/// <param name="subscriptionId">The subscription identifier.</param>
/// <param name="timeoutSeconds">The timeout seconds.</param>
/// <returns>EventSubscriptionResponse.</returns>
EventSubscriptionResponse RenewEventSubscription(string subscriptionId, int? timeoutSeconds);
EventSubscriptionResponse RenewEventSubscription(string subscriptionId, string requestedTimeoutString);
/// <summary>
/// Creates the event subscription.
/// </summary>
/// <param name="notificationType">Type of the notification.</param>
/// <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);
EventSubscriptionResponse CreateEventSubscription(string notificationType, string requestedTimeoutString, string callbackUrl);
}
}

View File

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