1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-09 00:46:19 +00:00
2018-11-22 12:45:36 +01:00

40 lines
983 B
C#

using CryptoExchange.Net.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
namespace CryptoExchange.Net.Sockets
{
public class SocketSubscription
{
public event Action ConnectionLost;
public event Action ConnectionRestored;
public IWebsocket Socket { get; set; }
public object Request { get; set; }
private bool lostTriggered;
public SocketSubscription(IWebsocket socket)
{
Socket = socket;
Socket.OnClose += () =>
{
if (lostTriggered)
return;
lostTriggered = true;
if (Socket.ShouldReconnect)
ConnectionLost?.Invoke();
};
Socket.OnOpen += () =>
{
lostTriggered = false;
if (Socket.DisconnectTime != null)
ConnectionRestored?.Invoke();
};
}
}
}