mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-09 00:46:19 +00:00
40 lines
983 B
C#
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();
|
|
};
|
|
}
|
|
}
|
|
}
|