Fix for pull request #113
This commit is contained in:
parent
2461b43145
commit
58a4f02bda
@ -35,7 +35,7 @@ namespace Example
|
|||||||
nf.Notify (
|
nf.Notify (
|
||||||
new NotificationMessage {
|
new NotificationMessage {
|
||||||
Summary = "WebSocket Message",
|
Summary = "WebSocket Message",
|
||||||
Body = e.Data,
|
Body = e.Type != Opcode.Ping ? e.Data : "Received a Ping.",
|
||||||
Icon = "notification-message-im"
|
Icon = "notification-message-im"
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -61,6 +61,9 @@ namespace Example
|
|||||||
|
|
||||||
// To change the wait time for the response to the Ping or Close.
|
// To change the wait time for the response to the Ping or Close.
|
||||||
ws.WaitTime = TimeSpan.FromSeconds (10);
|
ws.WaitTime = TimeSpan.FromSeconds (10);
|
||||||
|
|
||||||
|
// To emit a WebSocket.OnMessage event when receives a Ping.
|
||||||
|
ws.EmitOnPing = true;
|
||||||
#endif
|
#endif
|
||||||
// To enable the Per-message Compression extension.
|
// To enable the Per-message Compression extension.
|
||||||
//ws.Compression = CompressionMethod.Deflate;
|
//ws.Compression = CompressionMethod.Deflate;
|
||||||
|
@ -37,11 +37,12 @@ namespace WebSocketSharp
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// <para>
|
/// <para>
|
||||||
/// A <see cref="WebSocket.OnMessage"/> event occurs when the <see cref="WebSocket"/> receives
|
/// 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>
|
||||||
/// <para>
|
/// <para>
|
||||||
/// If you would like to get the message data, you should access
|
/// If you would like to get the message data, you should access the <see cref="Data"/> or
|
||||||
/// the <see cref="MessageEventArgs.Data"/> or <see cref="MessageEventArgs.RawData"/> property.
|
/// <see cref="RawData"/> property.
|
||||||
/// </para>
|
/// </para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class MessageEventArgs : EventArgs
|
public class MessageEventArgs : EventArgs
|
||||||
@ -113,7 +114,7 @@ namespace WebSocketSharp
|
|||||||
/// Gets the type of the message.
|
/// Gets the type of the message.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>
|
/// <value>
|
||||||
/// <see cref="Opcode.Text"/> or <see cref="Opcode.Binary"/>.
|
/// <see cref="Opcode.Text"/>, <see cref="Opcode.Binary"/>, or <see cref="Opcode.Ping"/>.
|
||||||
/// </value>
|
/// </value>
|
||||||
public Opcode Type {
|
public Opcode Type {
|
||||||
get {
|
get {
|
||||||
|
@ -76,6 +76,7 @@ namespace WebSocketSharp
|
|||||||
private WebSocketContext _context;
|
private WebSocketContext _context;
|
||||||
private CookieCollection _cookies;
|
private CookieCollection _cookies;
|
||||||
private NetworkCredential _credentials;
|
private NetworkCredential _credentials;
|
||||||
|
private bool _emitOnPing;
|
||||||
private bool _enableRedirection;
|
private bool _enableRedirection;
|
||||||
private string _extensions;
|
private string _extensions;
|
||||||
private AutoResetEvent _exitReceiving;
|
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>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether the <see cref="WebSocket"/> redirects to
|
/// Gets or sets a value indicating whether the <see cref="WebSocket"/> redirects to
|
||||||
/// the new URL located in the handshake response.
|
/// the new URL located in the handshake response.
|
||||||
@ -1001,6 +1020,9 @@ namespace WebSocketSharp
|
|||||||
if (send (new WebSocketFrame (Opcode.Pong, frame.PayloadData, _client).ToByteArray ()))
|
if (send (new WebSocketFrame (Opcode.Pong, frame.PayloadData, _client).ToByteArray ()))
|
||||||
_logger.Trace ("Returned a Pong.");
|
_logger.Trace ("Returned a Pong.");
|
||||||
|
|
||||||
|
if (_emitOnPing)
|
||||||
|
enqueueToMessageEventQueue (new MessageEventArgs (frame));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1399,7 +1421,7 @@ namespace WebSocketSharp
|
|||||||
if (processReceivedFrame (frame) && _readyState != WebSocketState.Closed) {
|
if (processReceivedFrame (frame) && _readyState != WebSocketState.Closed) {
|
||||||
receive ();
|
receive ();
|
||||||
|
|
||||||
if (frame.IsControl || !frame.IsFinal)
|
if ((frame.IsControl && !(frame.IsPing && _emitOnPing)) || !frame.IsFinal)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
lock (_forEvent) {
|
lock (_forEvent) {
|
||||||
|
Loading…
Reference in New Issue
Block a user