Skip to content

Commit

Permalink
Use proxy disable
Browse files Browse the repository at this point in the history
This commit makes use of the application setting to disable proxy detection. See #12
  • Loading branch information
victor-david committed Mar 8, 2021
1 parent ae85a9a commit 8cbed72
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Camera.App/Core/PluginFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ public static ICameraPlugin Create(CameraRow camera)
throw new InvalidPluginException($"The plugin configured for [{camera.Name}] [{camera.PluginName}, Id: {camera.PluginGuid}] cannot be found");
}

ICameraPlugin plugin = creator.Create(new ConnectionParameters(camera.IpAddress, camera.Port, camera.UserId, camera.Password));
ICameraPlugin plugin = creator.Create(new ConnectionParameters(camera.IpAddress, camera.Port, camera.UserId, camera.Password)
{
ProxyDetectionEnabled = !Config.Instance.IsProxyDetectionDisabled
});

if (plugin is ICameraMotion motion)
{
motion.SetMotionSpeedAsync((int)camera.MotionSpeed);
Expand Down
11 changes: 11 additions & 0 deletions src/Restless.Camera.Contracts/Classes/ConnectionParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ public int RetryWaitTime
set => retryWaitTime = Math.Max(Math.Min(value, MaxRetryWaitTime), MinRetryWaitTime);
}

/// <summary>
/// Gets or sets a value that determines whether proxy detection is enabled.
/// The default is true.
/// </summary>
public bool ProxyDetectionEnabled
{
get;
set;
}

/// <summary>
/// Gets a boolean value that indicates if a user id is present.
/// </summary>
Expand Down Expand Up @@ -147,6 +157,7 @@ public ConnectionParameters(string ipAddress, long port, string userId, string p
Timeout = DefaultTimeout;
ConnectionAttempts = DefaultConnectionAttempts;
RetryWaitTime = DefaultRetryWaitTime;
ProxyDetectionEnabled = true;
}

/// <summary>
Expand Down
5 changes: 4 additions & 1 deletion src/Restless.Plugin.Framework/Base/HttpPluginBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ protected HttpClient Client
/// <param name="parms">The connection parameters</param>
protected HttpPluginBase(ConnectionParameters parms) : base(parms)
{
var clientHandler = new HttpClientHandler();
var clientHandler = new HttpClientHandler()
{
UseProxy = parms.ProxyDetectionEnabled
};

Client = new HttpClient(new HttpTimeoutHandler()
{
Expand Down

0 comments on commit 8cbed72

Please sign in to comment.