WebsocketResource: Add Property CurrentWebSockets
parent
64d75b8285
commit
009fd85949
|
@ -5,6 +5,7 @@ using ln.logging;
|
|||
using System.IO;
|
||||
using ln.types;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
|
||||
namespace ln.http.resources.websocket
|
||||
{
|
||||
|
@ -12,6 +13,9 @@ namespace ln.http.resources.websocket
|
|||
{
|
||||
public Func<HttpRequest,WebSocket> WebSocketFactory { get; }
|
||||
|
||||
public IEnumerable<WebSocket> CurrentWebSockets { get { lock (this) { return currentWebSockets.ToArray(); }; } }
|
||||
List<WebSocket> currentWebSockets = new List<WebSocket>();
|
||||
|
||||
public WebsocketResource(Resource container,String resourceName, Func<HttpRequest, WebSocket> webSocketFactory)
|
||||
:base(container,resourceName)
|
||||
{
|
||||
|
@ -25,14 +29,24 @@ namespace ln.http.resources.websocket
|
|||
|
||||
public override HttpResponse GetResponse(HttpRequest httpRequest)
|
||||
{
|
||||
WebSocket webSocket = null;
|
||||
try
|
||||
{
|
||||
WebSocketFactory(httpRequest).Run();
|
||||
webSocket = WebSocketFactory(httpRequest);
|
||||
lock (this)
|
||||
currentWebSockets.Add(webSocket);
|
||||
webSocket.Run();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logging.Log(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (webSocket != null)
|
||||
lock (this)
|
||||
currentWebSockets.Remove(webSocket);
|
||||
}
|
||||
|
||||
httpRequest.GetConnectionStream().Close();
|
||||
return null;
|
||||
|
|
Loading…
Reference in New Issue