aboutsummaryrefslogtreecommitdiff
path: root/RSSDP
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2017-01-24 14:54:18 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2017-01-24 14:54:18 -0500
commitb9f758e14dc4f49a55c7ee61fa722ef48ab24a78 (patch)
treea6679c8b8308b736a5667d2fc8e6744d75dc469e /RSSDP
parent23070fa67ce11a62a07cd0c65b301218265ce264 (diff)
reduce traffic from play to feature
Diffstat (limited to 'RSSDP')
-rw-r--r--RSSDP/DeviceAvailableEventArgs.cs6
-rw-r--r--RSSDP/ResponseReceivedEventArgs.cs6
-rw-r--r--RSSDP/SsdpCommunicationsServer.cs9
-rw-r--r--RSSDP/SsdpDeviceLocatorBase.cs36
4 files changed, 33 insertions, 24 deletions
diff --git a/RSSDP/DeviceAvailableEventArgs.cs b/RSSDP/DeviceAvailableEventArgs.cs
index 39f07e1d7..046c10524 100644
--- a/RSSDP/DeviceAvailableEventArgs.cs
+++ b/RSSDP/DeviceAvailableEventArgs.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using MediaBrowser.Model.Net;
namespace Rssdp
{
@@ -11,10 +12,11 @@ namespace Rssdp
/// </summary>
public sealed class DeviceAvailableEventArgs : EventArgs
{
+ public IpAddressInfo LocalIpAddress { get; set; }
- #region Fields
+ #region Fields
- private readonly DiscoveredSsdpDevice _DiscoveredDevice;
+ private readonly DiscoveredSsdpDevice _DiscoveredDevice;
private readonly bool _IsNewlyDiscovered;
#endregion
diff --git a/RSSDP/ResponseReceivedEventArgs.cs b/RSSDP/ResponseReceivedEventArgs.cs
index f7dc5813d..c983fa204 100644
--- a/RSSDP/ResponseReceivedEventArgs.cs
+++ b/RSSDP/ResponseReceivedEventArgs.cs
@@ -15,9 +15,11 @@ namespace Rssdp.Infrastructure
public sealed class ResponseReceivedEventArgs : EventArgs
{
- #region Fields
+ public IpAddressInfo LocalIpAddress { get; set; }
- private readonly HttpResponseMessage _Message;
+ #region Fields
+
+ private readonly HttpResponseMessage _Message;
private readonly IpEndPointInfo _ReceivedFrom;
#endregion
diff --git a/RSSDP/SsdpCommunicationsServer.cs b/RSSDP/SsdpCommunicationsServer.cs
index 97f5ebbd0..c4959c1f2 100644
--- a/RSSDP/SsdpCommunicationsServer.cs
+++ b/RSSDP/SsdpCommunicationsServer.cs
@@ -454,7 +454,7 @@ namespace Rssdp.Infrastructure
}
if (responseMessage != null)
- OnResponseReceived(responseMessage, endPoint);
+ OnResponseReceived(responseMessage, endPoint, receivedOnLocalIpAddress);
}
else
{
@@ -490,11 +490,14 @@ namespace Rssdp.Infrastructure
handlers(this, new RequestReceivedEventArgs(data, remoteEndPoint, receivedOnLocalIpAddress));
}
- private void OnResponseReceived(HttpResponseMessage data, IpEndPointInfo endPoint)
+ private void OnResponseReceived(HttpResponseMessage data, IpEndPointInfo endPoint, IpAddressInfo localIpAddress)
{
var handlers = this.ResponseReceived;
if (handlers != null)
- handlers(this, new ResponseReceivedEventArgs(data, endPoint));
+ handlers(this, new ResponseReceivedEventArgs(data, endPoint)
+ {
+ LocalIpAddress = localIpAddress
+ });
}
#endregion
diff --git a/RSSDP/SsdpDeviceLocatorBase.cs b/RSSDP/SsdpDeviceLocatorBase.cs
index b6276e499..60a792425 100644
--- a/RSSDP/SsdpDeviceLocatorBase.cs
+++ b/RSSDP/SsdpDeviceLocatorBase.cs
@@ -7,6 +7,7 @@ using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
+using MediaBrowser.Model.Net;
using MediaBrowser.Model.Threading;
using RSSDP;
@@ -163,7 +164,7 @@ namespace Rssdp.Infrastructure
{
foreach (var device in GetUnexpiredDevices().Where(NotificationTypeMatchesFilter))
{
- DeviceFound(device, false);
+ DeviceFound(device, false, null);
}
}
@@ -237,16 +238,17 @@ namespace Rssdp.Infrastructure
/// <summary>
/// Raises the <see cref="DeviceAvailable"/> event.
/// </summary>
- /// <param name="device">A <see cref="DiscoveredSsdpDevice"/> representing the device that is now available.</param>
- /// <param name="isNewDevice">True if the device was not currently in the cahce before this event was raised.</param>
/// <seealso cref="DeviceAvailable"/>
- protected virtual void OnDeviceAvailable(DiscoveredSsdpDevice device, bool isNewDevice)
+ protected virtual void OnDeviceAvailable(DiscoveredSsdpDevice device, bool isNewDevice, IpAddressInfo localIpAddress)
{
if (this.IsDisposed) return;
var handlers = this.DeviceAvailable;
if (handlers != null)
- handlers(this, new DeviceAvailableEventArgs(device, isNewDevice));
+ handlers(this, new DeviceAvailableEventArgs(device, isNewDevice)
+ {
+ LocalIpAddress = localIpAddress
+ });
}
/// <summary>
@@ -335,7 +337,7 @@ namespace Rssdp.Infrastructure
#region Discovery/Device Add
- private void AddOrUpdateDiscoveredDevice(DiscoveredSsdpDevice device)
+ private void AddOrUpdateDiscoveredDevice(DiscoveredSsdpDevice device, IpAddressInfo localIpAddress)
{
bool isNewDevice = false;
lock (_Devices)
@@ -353,10 +355,10 @@ namespace Rssdp.Infrastructure
}
}
- DeviceFound(device, isNewDevice);
+ DeviceFound(device, isNewDevice, localIpAddress);
}
- private void DeviceFound(DiscoveredSsdpDevice device, bool isNewDevice)
+ private void DeviceFound(DiscoveredSsdpDevice device, bool isNewDevice, IpAddressInfo localIpAddress)
{
// Don't raise the event if we've already done it for a cached
// version of this device, and the cached version isn't
@@ -391,7 +393,7 @@ namespace Rssdp.Infrastructure
}
if (raiseEvent)
- OnDeviceAvailable(device, isNewDevice);
+ OnDeviceAvailable(device, isNewDevice, localIpAddress);
}
private bool NotificationTypeMatchesFilter(DiscoveredSsdpDevice device)
@@ -428,7 +430,7 @@ namespace Rssdp.Infrastructure
return _CommunicationsServer.SendMulticastMessage(message);
}
- private void ProcessSearchResponseMessage(HttpResponseMessage message)
+ private void ProcessSearchResponseMessage(HttpResponseMessage message, IpAddressInfo localIpAddress)
{
if (!message.IsSuccessStatusCode) return;
@@ -445,22 +447,22 @@ namespace Rssdp.Infrastructure
ResponseHeaders = message.Headers
};
- AddOrUpdateDiscoveredDevice(device);
+ AddOrUpdateDiscoveredDevice(device, localIpAddress);
}
}
- private void ProcessNotificationMessage(HttpRequestMessage message)
+ private void ProcessNotificationMessage(HttpRequestMessage message, IpAddressInfo localIpAddress)
{
if (String.Compare(message.Method.Method, "Notify", StringComparison.OrdinalIgnoreCase) != 0) return;
var notificationType = GetFirstHeaderStringValue("NTS", message);
if (String.Compare(notificationType, SsdpConstants.SsdpKeepAliveNotification, StringComparison.OrdinalIgnoreCase) == 0)
- ProcessAliveNotification(message);
+ ProcessAliveNotification(message, localIpAddress);
else if (String.Compare(notificationType, SsdpConstants.SsdpByeByeNotification, StringComparison.OrdinalIgnoreCase) == 0)
ProcessByeByeNotification(message);
}
- private void ProcessAliveNotification(HttpRequestMessage message)
+ private void ProcessAliveNotification(HttpRequestMessage message, IpAddressInfo localIpAddress)
{
var location = GetFirstHeaderUriValue("Location", message);
if (location != null)
@@ -475,7 +477,7 @@ namespace Rssdp.Infrastructure
ResponseHeaders = message.Headers
};
- AddOrUpdateDiscoveredDevice(device);
+ AddOrUpdateDiscoveredDevice(device, localIpAddress);
ResetExpireCachedDevicesTimer();
}
@@ -702,12 +704,12 @@ namespace Rssdp.Infrastructure
private void CommsServer_ResponseReceived(object sender, ResponseReceivedEventArgs e)
{
- ProcessSearchResponseMessage(e.Message);
+ ProcessSearchResponseMessage(e.Message, e.LocalIpAddress);
}
private void CommsServer_RequestReceived(object sender, RequestReceivedEventArgs e)
{
- ProcessNotificationMessage(e.Message);
+ ProcessNotificationMessage(e.Message, e.LocalIpAddress);
}
#endregion