import Foundation
public enum WebSocketMessage: Sendable, Equatable {
case text(String)
case data(Data)
}
/// One open WebSocket. `receive` throws `P2PError.closed` once the peer has closed it.
public protocol WebSocketConnection: Sendable {
func send(text: String) async throws
func receive() async throws -> WebSocketMessage
func close(code: Int, reason: String?) async
}
/// Opens WebSockets. The upgrade request carries the `Origin` header when configured;
/// a refused upgrade throws `P2PError.upgradeRejected(status:)`.
public protocol WebSocketTransport: Sendable {
func connect(_ request: URLRequest) async throws -> any WebSocketConnection
}