Skip to content

Commit 8e67154

Browse files
committed
Add proxy support
1 parent b9cf229 commit 8e67154

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

PusherClient/Connection.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Threading.Tasks;
55
using Newtonsoft.Json;
66
using Newtonsoft.Json.Linq;
7+
using SuperSocket.ClientEngine;
78
//using Nito.AsyncEx;
89
using WebSocket4Net;
910

@@ -16,6 +17,7 @@ internal class Connection
1617
private readonly string _url;
1718
private readonly IPusher _pusher;
1819
private bool _allowReconnect = true;
20+
private Func<IProxyConnector> _proxyFactory;
1921

2022
private int _backOffMillis;
2123

@@ -31,10 +33,11 @@ internal class Connection
3133
private TaskCompletionSource<ConnectionState> _connectionTaskComplete = null;
3234
private TaskCompletionSource<ConnectionState> _disconnectionTaskComplete = null;
3335

34-
public Connection(IPusher pusher, string url)
36+
public Connection(IPusher pusher, string url, Func<IProxyConnector> proxyFactory = null)
3537
{
3638
_pusher = pusher;
3739
_url = url;
40+
_proxyFactory = proxyFactory;
3841
}
3942

4043
internal Task<ConnectionState> Connect()
@@ -57,7 +60,8 @@ internal Task<ConnectionState> Connect()
5760
_websocket = new WebSocket(_url)
5861
{
5962
EnableAutoSendPing = true,
60-
AutoSendPingInterval = 1
63+
AutoSendPingInterval = 1,
64+
Proxy = _proxyFactory?.Invoke(),
6165
};
6266

6367
_websocket.Opened += websocket_Opened;

PusherClient/Pusher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public async Task<ConnectionState> ConnectAsync()
196196

197197
var url = ConstructUrl();
198198

199-
_connection = new Connection(this, url);
199+
_connection = new Connection(this, url, Options.ProxyFactory);
200200
connectionResult = await _connection.Connect();
201201
}
202202
finally

PusherClient/PusherOptions.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace PusherClient
1+
using SuperSocket.ClientEngine;
2+
using System;
3+
4+
namespace PusherClient
25
{
36
/// <summary>
47
/// The Options to set up the connection with <see cref="Pusher"/>
@@ -20,6 +23,12 @@ public class PusherOptions
2023
/// </summary>
2124
public string Cluster { get; set; } = "mt1";
2225

26+
/// <summary>
27+
/// Gets or set a IProxyConnector implementation instance may be one of
28+
/// HttpConnectProxy, Socks4Connector, or Socks5Connector.
29+
/// </summary>
30+
public Func<IProxyConnector> ProxyFactory { get; set; }
31+
2332
internal string Host => $"ws-{Cluster}.pusher.com";
2433
}
2534
}

0 commit comments

Comments
 (0)