using System.Net.Sockets;
namespace NetCoreServer
{
///
/// WebSocket interface
///
public interface IWebSocket
{
///
/// Handle WebSocket client connecting notification
///
/// Notification is called when WebSocket client is connecting to the server. You can handle the connection and change WebSocket upgrade HTTP request by providing your own headers.
/// WebSocket upgrade HTTP request
void OnWsConnecting(HttpRequest request) {}
///
/// Handle WebSocket client connected notification
///
/// WebSocket upgrade HTTP response
void OnWsConnected(HttpResponse response) {}
///
/// Handle WebSocket server session validating notification
///
/// Notification is called when WebSocket client is connecting to the server. You can handle the connection and validate WebSocket upgrade HTTP request.
/// WebSocket upgrade HTTP request
/// WebSocket upgrade HTTP response
/// return 'true' if the WebSocket update request is valid, 'false' if the WebSocket update request is not valid
bool OnWsConnecting(HttpRequest request, HttpResponse response) { return true; }
///
/// Handle WebSocket server session connected notification
///
/// WebSocket upgrade HTTP request
void OnWsConnected(HttpRequest request) {}
///
/// Handle WebSocket client disconnecting notification
///
void OnWsDisconnecting() {}
///
/// Handle WebSocket client disconnected notification
///
void OnWsDisconnected() {}
///
/// Handle WebSocket received notification
///
/// Received buffer
/// Received buffer offset
/// Received buffer size
void OnWsReceived(byte[] buffer, long offset, long size) {}
///
/// Handle WebSocket client close notification
///
/// Received buffer
/// Received buffer offset
/// Received buffer size
/// WebSocket close status (default is 1000)
void OnWsClose(byte[] buffer, long offset, long size, int status = 1000) {}
///
/// Handle WebSocket ping notification
///
/// Received buffer
/// Received buffer offset
/// Received buffer size
void OnWsPing(byte[] buffer, long offset, long size) {}
///
/// Handle WebSocket pong notification
///
/// Received buffer
/// Received buffer offset
/// Received buffer size
void OnWsPong(byte[] buffer, long offset, long size) {}
///
/// Handle WebSocket error notification
///
/// Error message
void OnWsError(string error) {}
///
/// Handle socket error notification
///
/// Socket error
void OnWsError(SocketError error) {}
///
/// Send WebSocket server upgrade response
///
/// WebSocket upgrade HTTP response
void SendUpgrade(HttpResponse response) {}
}
}