Skip to content

Commit

Permalink
Merge pull request #147 from Code-Sharp/v1.2.3.18-beta
Browse files Browse the repository at this point in the history
Added an option to specify WebSocketListenerOptions
  • Loading branch information
darkl authored Sep 26, 2016
2 parents f9f24a1 + 4aa0313 commit ffc40ea
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
using System.Net;
using System.Security.Cryptography.X509Certificates;
using vtortola.WebSockets;
using WampSharp.V2.Authentication;

namespace WampSharp.Vtortola
{
public class VtortolaAuthenticatedWebSocketTransport : VtortolaWebSocketTransport
{
public VtortolaAuthenticatedWebSocketTransport
(IPEndPoint endpoint,
bool perMessageDeflate,
ICookieAuthenticatorFactory authenticatorFactory,
X509Certificate2 certificate = null)
: base(endpoint, perMessageDeflate, authenticatorFactory, certificate)
(IPEndPoint endpoint, bool perMessageDeflate, ICookieAuthenticatorFactory authenticatorFactory, WebSocketListenerOptions options)
: this(endpoint, perMessageDeflate, authenticatorFactory, null, options)
{
}

public VtortolaAuthenticatedWebSocketTransport
(IPEndPoint endpoint, bool perMessageDeflate, ICookieAuthenticatorFactory authenticatorFactory, X509Certificate2 certificate = null, WebSocketListenerOptions options = null)
: base(endpoint, perMessageDeflate, authenticatorFactory, certificate, options)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class VtortolaWebSocketTransport : WebSocketTransport<WebSocket>
private WebSocketListener mListener;
private readonly bool mPerMessageDeflate;
private readonly X509Certificate2 mCertificate;
private readonly WebSocketListenerOptions mOptions;

/// <summary>
/// Creates a new instance of <see cref="VtortolaWebSocketTransport"/>
Expand All @@ -31,8 +32,20 @@ public class VtortolaWebSocketTransport : WebSocketTransport<WebSocket>
/// <param name="endpoint"></param>
/// <param name="perMessageDeflate">A value indicating whether to support permessage-deflate
/// compression extension or not.</param>
public VtortolaWebSocketTransport(IPEndPoint endpoint, bool perMessageDeflate, X509Certificate2 certificate = null)
: this(endpoint, perMessageDeflate, null, certificate)
public VtortolaWebSocketTransport(IPEndPoint endpoint, bool perMessageDeflate, WebSocketListenerOptions options)
: this(endpoint, perMessageDeflate, null, options)
{
}

/// <summary>
/// Creates a new instance of <see cref="VtortolaWebSocketTransport"/>
/// given the endpoint to run at.
/// </summary>
/// <param name="endpoint"></param>
/// <param name="perMessageDeflate">A value indicating whether to support permessage-deflate
/// compression extension or not.</param>
public VtortolaWebSocketTransport(IPEndPoint endpoint, bool perMessageDeflate, X509Certificate2 certificate = null, WebSocketListenerOptions options = null)
: this(endpoint, perMessageDeflate, null, certificate, options)
{
}

Expand All @@ -45,13 +58,15 @@ public VtortolaWebSocketTransport(IPEndPoint endpoint, bool perMessageDeflate, X
/// compression extension or not.</param>
/// <param name="authenticatorFactory"></param>
/// <param name="certificate"></param>
/// <param name="options"></param>
protected VtortolaWebSocketTransport
(IPEndPoint endpoint, bool perMessageDeflate, ICookieAuthenticatorFactory authenticatorFactory = null, X509Certificate2 certificate = null)
(IPEndPoint endpoint, bool perMessageDeflate, ICookieAuthenticatorFactory authenticatorFactory = null, X509Certificate2 certificate = null, WebSocketListenerOptions options = null)
: base(authenticatorFactory)
{
mEndpoint = endpoint;
mPerMessageDeflate = perMessageDeflate;
mCertificate = certificate;
mOptions = options;
}

public override void Dispose()
Expand All @@ -64,10 +79,11 @@ public override void Open()
{
string[] protocols = SubProtocols;

WebSocketListener listener = new WebSocketListener(mEndpoint, new WebSocketListenerOptions()
{
SubProtocols = protocols
});
WebSocketListenerOptions options = mOptions ?? new WebSocketListenerOptions();

options.SubProtocols = protocols;

WebSocketListener listener = new WebSocketListener(mEndpoint, options);

WebSocketFactoryRfc6455 factory = new WebSocketFactoryRfc6455(listener);

Expand Down

0 comments on commit ffc40ea

Please sign in to comment.