p2p-swift / Sources / IrdP2PSignaling / Transport / WebSocketTransport.swift
82 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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
}

static mirror of HEAD · about · clone: git clone https://ird.cod-sursa.ro/p2p-swift.git