using System;
using System.Net.WebSockets;
using Websocket.Client;
namespace SafeMobileLib.WebsocketClient.Models
{
public class DisconnectionInfo
{
///
public DisconnectionInfo(DisconnectionType type, WebSocketCloseStatus? closeStatus,
string closeStatusDescription, string subProtocol, Exception exception)
{
Type = type;
CloseStatus = closeStatus;
CloseStatusDescription = closeStatusDescription;
SubProtocol = subProtocol;
Exception = exception;
}
///
/// Disconnection reason
///
public DisconnectionType Type { get; }
///
/// Indicates the reason why the remote endpoint initiated the close handshake
///
public WebSocketCloseStatus? CloseStatus { get; }
///
/// Allows the remote endpoint to describe the reason whe the connection was closed
///
public string CloseStatusDescription { get; }
///
/// The subprotocol that was negotiated during the opening handshake
///
public string SubProtocol { get; }
///
/// Exception that cause disconnection, can be null
///
public Exception Exception { get; }
///
/// Set to true if you want to cancel ongoing reconnection
///
public bool CancelReconnection { get; set; }
///
/// Set to true if you want to cancel ongoing connection close (only when Type = ByServer)
///
public bool CancelClosing { get; set; }
///
/// Simple factory method
///
public static DisconnectionInfo Create(DisconnectionType type, WebSocket client, Exception exception)
{
return new DisconnectionInfo(type, client?.CloseStatus, client?.CloseStatusDescription,
client?.SubProtocol, exception);
}
}
}