p2p-swift / Sources / IrdP2PSignaling / AppEndpoints.swift
183 words
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Foundation

/// The URLs the SDK talks to. Normally resolved from the app hostname and its
/// descriptor; overridable for local development against the node servers on
/// loopback (plain `http://`/`ws://` are then allowed).
public struct AppEndpoints: Sendable, Equatable {
    public var descriptor: URL
    public var ws: URL?
    public var turnCredentials: URL?
    public var mailboxMint: URL?
    public var mailbox: URL?

    public init(descriptor: URL, ws: URL? = nil, turnCredentials: URL? = nil, mailboxMint: URL? = nil, mailbox: URL? = nil) {
        self.descriptor = descriptor
        self.ws = ws
        self.turnCredentials = turnCredentials
        self.mailboxMint = mailboxMint
        self.mailbox = mailbox
    }

    /// The documented paths on an app hostname.
    public static func standard(host: String) -> AppEndpoints {
        AppEndpoints(descriptor: URL(string: "https://\(host)/.well-known/ap2p")!)
    }

    /// Final URLs: explicit overrides win, then the descriptor, then the standard paths.
    public func resolved(with descriptor: AppDescriptor, host: String) -> Resolved {
        Resolved(
            ws: ws ?? descriptor.endpoints.ws,
            turnCredentials: turnCredentials ?? descriptor.endpoints.turnCredentials,
            mailboxMint: mailboxMint ?? descriptor.mailbox?.mintEndpoint,
            mailbox: mailbox ?? descriptor.mailbox?.endpoint
        )
    }

    public struct Resolved: Sendable, Equatable {
        public var ws: URL
        public var turnCredentials: URL
        public var mailboxMint: URL?
        public var mailbox: URL?
    }
}

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