update device discovery

This commit is contained in:
Luke Pulverenti 2016-09-13 13:49:13 -04:00
parent de2aebd673
commit 020ceb97d2
2 changed files with 14 additions and 16 deletions

View file

@ -50,8 +50,6 @@ namespace MediaBrowser.Dlna.Ssdp
// Connect our event handler so we process devices as they are found // Connect our event handler so we process devices as they are found
_DeviceLocator.DeviceAvailable += deviceLocator_DeviceAvailable; _DeviceLocator.DeviceAvailable += deviceLocator_DeviceAvailable;
_DeviceLocator.DeviceUnavailable += _DeviceLocator_DeviceUnavailable; _DeviceLocator.DeviceUnavailable += _DeviceLocator_DeviceUnavailable;
// Enable listening for notifications (optional)
_DeviceLocator.StartListeningForNotifications();
// Perform a search so we don't have to wait for devices to broadcast notifications // Perform a search so we don't have to wait for devices to broadcast notifications
// again to get any results right away (notifications are broadcast periodically). // again to get any results right away (notifications are broadcast periodically).
@ -62,23 +60,23 @@ namespace MediaBrowser.Dlna.Ssdp
{ {
Task.Factory.StartNew(async (o) => Task.Factory.StartNew(async (o) =>
{ {
try while (!_tokenSource.IsCancellationRequested)
{ {
while (true) try
{ {
// Enable listening for notifications (optional)
_DeviceLocator.StartListeningForNotifications();
await _DeviceLocator.SearchAsync().ConfigureAwait(false); await _DeviceLocator.SearchAsync().ConfigureAwait(false);
var delay = _config.GetDlnaConfiguration().ClientDiscoveryIntervalSeconds * 1000;
await Task.Delay(delay, _tokenSource.Token).ConfigureAwait(false);
} }
} catch (Exception ex)
catch (OperationCanceledException) {
{ _logger.ErrorException("Error searching for devices", ex);
} }
catch (Exception ex)
{ var delay = _config.GetDlnaConfiguration().ClientDiscoveryIntervalSeconds * 1000;
_logger.ErrorException("Error searching for devices", ex);
await Task.Delay(delay, _tokenSource.Token).ConfigureAwait(false);
} }
}, CancellationToken.None, TaskCreationOptions.LongRunning); }, CancellationToken.None, TaskCreationOptions.LongRunning);

View file

@ -450,7 +450,7 @@ namespace MediaBrowser.Server.Implementations.Connect
if (!string.IsNullOrWhiteSpace(user.ConnectUserId)) if (!string.IsNullOrWhiteSpace(user.ConnectUserId))
{ {
await RemoveConnect(user, connectUser.Id).ConfigureAwait(false); await RemoveConnect(user, user.ConnectUserId).ConfigureAwait(false);
} }
var url = GetConnectUrl("ServerAuthorizations"); var url = GetConnectUrl("ServerAuthorizations");