Fix for pull request #113
This commit is contained in:
@@ -37,11 +37,12 @@ namespace WebSocketSharp
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// A <see cref="WebSocket.OnMessage"/> event occurs when the <see cref="WebSocket"/> receives
|
||||
/// a text or binary message.
|
||||
/// a text or binary message, or a Ping if the <see cref="WebSocket.EmitOnPing"/> property is
|
||||
/// set to <c>true</c>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If you would like to get the message data, you should access
|
||||
/// the <see cref="MessageEventArgs.Data"/> or <see cref="MessageEventArgs.RawData"/> property.
|
||||
/// If you would like to get the message data, you should access the <see cref="Data"/> or
|
||||
/// <see cref="RawData"/> property.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public class MessageEventArgs : EventArgs
|
||||
@@ -113,7 +114,7 @@ namespace WebSocketSharp
|
||||
/// Gets the type of the message.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <see cref="Opcode.Text"/> or <see cref="Opcode.Binary"/>.
|
||||
/// <see cref="Opcode.Text"/>, <see cref="Opcode.Binary"/>, or <see cref="Opcode.Ping"/>.
|
||||
/// </value>
|
||||
public Opcode Type {
|
||||
get {
|
||||
|
@@ -76,6 +76,7 @@ namespace WebSocketSharp
|
||||
private WebSocketContext _context;
|
||||
private CookieCollection _cookies;
|
||||
private NetworkCredential _credentials;
|
||||
private bool _emitOnPing;
|
||||
private bool _enableRedirection;
|
||||
private string _extensions;
|
||||
private AutoResetEvent _exitReceiving;
|
||||
@@ -308,6 +309,24 @@ namespace WebSocketSharp
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the <see cref="WebSocket"/> emits
|
||||
/// a <see cref="OnMessage"/> event when receives a Ping.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the <see cref="WebSocket"/> emits a <see cref="OnMessage"/> event
|
||||
/// when receives a Ping; otherwise, <c>false</c>. The default value is <c>false</c>.
|
||||
/// </value>
|
||||
public bool EmitOnPing {
|
||||
get {
|
||||
return _emitOnPing;
|
||||
}
|
||||
|
||||
set {
|
||||
_emitOnPing = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the <see cref="WebSocket"/> redirects to
|
||||
/// the new URL located in the handshake response.
|
||||
@@ -1001,6 +1020,9 @@ namespace WebSocketSharp
|
||||
if (send (new WebSocketFrame (Opcode.Pong, frame.PayloadData, _client).ToByteArray ()))
|
||||
_logger.Trace ("Returned a Pong.");
|
||||
|
||||
if (_emitOnPing)
|
||||
enqueueToMessageEventQueue (new MessageEventArgs (frame));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1399,7 +1421,7 @@ namespace WebSocketSharp
|
||||
if (processReceivedFrame (frame) && _readyState != WebSocketState.Closed) {
|
||||
receive ();
|
||||
|
||||
if (frame.IsControl || !frame.IsFinal)
|
||||
if ((frame.IsControl && !(frame.IsPing && _emitOnPing)) || !frame.IsFinal)
|
||||
return;
|
||||
|
||||
lock (_forEvent) {
|
||||
|
Reference in New Issue
Block a user