From f99112fc2fc47dc094a9461cf03541dfa0734838 Mon Sep 17 00:00:00 2001 From: sta Date: Mon, 27 Jul 2015 16:11:16 +0900 Subject: [PATCH] Fix for pull request #113 --- Example2/Program.cs | 2 ++ Example3/Program.cs | 2 ++ websocket-sharp/Server/WebSocketBehavior.cs | 25 +++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/Example2/Program.cs b/Example2/Program.cs index 9c608ccd..02f003dc 100644 --- a/Example2/Program.cs +++ b/Example2/Program.cs @@ -63,6 +63,8 @@ namespace Example2 "/Chat", () => new Chat ("Anon#") { Protocol = "chat", + // To emit a WebSocket.OnMessage event when receives a Ping. + EmitOnPing = true, // To ignore the Sec-WebSocket-Extensions header. IgnoreExtensions = true, // To validate the Origin header. diff --git a/Example3/Program.cs b/Example3/Program.cs index ea2bf248..68c1657c 100644 --- a/Example3/Program.cs +++ b/Example3/Program.cs @@ -90,6 +90,8 @@ namespace Example3 "/Chat", () => new Chat ("Anon#") { Protocol = "chat", + // To emit a WebSocket.OnMessage event when receives a Ping. + EmitOnPing = true, // To ignore the Sec-WebSocket-Extensions header. IgnoreExtensions = true, // To validate the Origin header. diff --git a/websocket-sharp/Server/WebSocketBehavior.cs b/websocket-sharp/Server/WebSocketBehavior.cs index 2b9b0b64..79120385 100644 --- a/websocket-sharp/Server/WebSocketBehavior.cs +++ b/websocket-sharp/Server/WebSocketBehavior.cs @@ -46,6 +46,7 @@ namespace WebSocketSharp.Server private WebSocketContext _context; private Func _cookiesValidator; + private bool _emitOnPing; private string _id; private bool _ignoreExtensions; private Func _originValidator; @@ -145,6 +146,29 @@ namespace WebSocketSharp.Server } } + /// + /// Gets or sets a value indicating whether the used in a session emits + /// a event when receives a Ping. + /// + /// + /// true if the emits a event + /// when receives a Ping; otherwise, false. The default value is false. + /// + public bool EmitOnPing { + get { + return _websocket != null ? _websocket.EmitOnPing : _emitOnPing; + } + + set { + if (_websocket != null) { + _websocket.EmitOnPing = value; + return; + } + + _emitOnPing = value; + } + } + /// /// Gets the unique ID of a session. /// @@ -329,6 +353,7 @@ namespace WebSocketSharp.Server _websocket = context.WebSocket; _websocket.CustomHandshakeRequestChecker = checkIfValidConnectionRequest; + _websocket.EmitOnPing = _emitOnPing; _websocket.IgnoreExtensions = _ignoreExtensions; _websocket.Protocol = _protocol;