Skip to content

Commit ffc40ea

Browse files
authored
Merge pull request #147 from Code-Sharp/v1.2.3.18-beta
Added an option to specify WebSocketListenerOptions
2 parents f9f24a1 + 4aa0313 commit ffc40ea

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

src/net45/Extensions/WampSharp.Vtortola/VtortolaAuthenticatedWebSocketTransport.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
using System.Net;
22
using System.Security.Cryptography.X509Certificates;
3+
using vtortola.WebSockets;
34
using WampSharp.V2.Authentication;
45

56
namespace WampSharp.Vtortola
67
{
78
public class VtortolaAuthenticatedWebSocketTransport : VtortolaWebSocketTransport
89
{
910
public VtortolaAuthenticatedWebSocketTransport
10-
(IPEndPoint endpoint,
11-
bool perMessageDeflate,
12-
ICookieAuthenticatorFactory authenticatorFactory,
13-
X509Certificate2 certificate = null)
14-
: base(endpoint, perMessageDeflate, authenticatorFactory, certificate)
11+
(IPEndPoint endpoint, bool perMessageDeflate, ICookieAuthenticatorFactory authenticatorFactory, WebSocketListenerOptions options)
12+
: this(endpoint, perMessageDeflate, authenticatorFactory, null, options)
13+
{
14+
}
15+
16+
public VtortolaAuthenticatedWebSocketTransport
17+
(IPEndPoint endpoint, bool perMessageDeflate, ICookieAuthenticatorFactory authenticatorFactory, X509Certificate2 certificate = null, WebSocketListenerOptions options = null)
18+
: base(endpoint, perMessageDeflate, authenticatorFactory, certificate, options)
1519
{
1620
}
1721
}

src/net45/Extensions/WampSharp.Vtortola/VtortolaWebSocketTransport.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class VtortolaWebSocketTransport : WebSocketTransport<WebSocket>
2323
private WebSocketListener mListener;
2424
private readonly bool mPerMessageDeflate;
2525
private readonly X509Certificate2 mCertificate;
26+
private readonly WebSocketListenerOptions mOptions;
2627

2728
/// <summary>
2829
/// Creates a new instance of <see cref="VtortolaWebSocketTransport"/>
@@ -31,8 +32,20 @@ public class VtortolaWebSocketTransport : WebSocketTransport<WebSocket>
3132
/// <param name="endpoint"></param>
3233
/// <param name="perMessageDeflate">A value indicating whether to support permessage-deflate
3334
/// compression extension or not.</param>
34-
public VtortolaWebSocketTransport(IPEndPoint endpoint, bool perMessageDeflate, X509Certificate2 certificate = null)
35-
: this(endpoint, perMessageDeflate, null, certificate)
35+
public VtortolaWebSocketTransport(IPEndPoint endpoint, bool perMessageDeflate, WebSocketListenerOptions options)
36+
: this(endpoint, perMessageDeflate, null, options)
37+
{
38+
}
39+
40+
/// <summary>
41+
/// Creates a new instance of <see cref="VtortolaWebSocketTransport"/>
42+
/// given the endpoint to run at.
43+
/// </summary>
44+
/// <param name="endpoint"></param>
45+
/// <param name="perMessageDeflate">A value indicating whether to support permessage-deflate
46+
/// compression extension or not.</param>
47+
public VtortolaWebSocketTransport(IPEndPoint endpoint, bool perMessageDeflate, X509Certificate2 certificate = null, WebSocketListenerOptions options = null)
48+
: this(endpoint, perMessageDeflate, null, certificate, options)
3649
{
3750
}
3851

@@ -45,13 +58,15 @@ public VtortolaWebSocketTransport(IPEndPoint endpoint, bool perMessageDeflate, X
4558
/// compression extension or not.</param>
4659
/// <param name="authenticatorFactory"></param>
4760
/// <param name="certificate"></param>
61+
/// <param name="options"></param>
4862
protected VtortolaWebSocketTransport
49-
(IPEndPoint endpoint, bool perMessageDeflate, ICookieAuthenticatorFactory authenticatorFactory = null, X509Certificate2 certificate = null)
63+
(IPEndPoint endpoint, bool perMessageDeflate, ICookieAuthenticatorFactory authenticatorFactory = null, X509Certificate2 certificate = null, WebSocketListenerOptions options = null)
5064
: base(authenticatorFactory)
5165
{
5266
mEndpoint = endpoint;
5367
mPerMessageDeflate = perMessageDeflate;
5468
mCertificate = certificate;
69+
mOptions = options;
5570
}
5671

5772
public override void Dispose()
@@ -64,10 +79,11 @@ public override void Open()
6479
{
6580
string[] protocols = SubProtocols;
6681

67-
WebSocketListener listener = new WebSocketListener(mEndpoint, new WebSocketListenerOptions()
68-
{
69-
SubProtocols = protocols
70-
});
82+
WebSocketListenerOptions options = mOptions ?? new WebSocketListenerOptions();
83+
84+
options.SubProtocols = protocols;
85+
86+
WebSocketListener listener = new WebSocketListener(mEndpoint, options);
7187

7288
WebSocketFactoryRfc6455 factory = new WebSocketFactoryRfc6455(listener);
7389

0 commit comments

Comments
 (0)