MultipeerReplicator

public class MultipeerReplicator

A multipeer replicator that manages peer discovery, connection, and replication in multipeer mesh network. Peer discovery uses DNS-SD (Bonjour) over Wi-Fi, requiring peers to be on the same network to find and connect to each other.

  • The configuration.

    Declaration

    Swift

    public let config: MultipeerReplicatorConfiguration
  • The peer identifier represents this multipeer replicator instance.

    Declaration

    Swift

    public var peerID: PeerID { get }
  • A list of currently visible peer identifiers.

    Declaration

    Swift

    public var neighborPeers: [PeerID] { get }
  • Initializes the multipeer replicator with the given configuration.

    Throws

    An error if initialization fails.

    Declaration

    Swift

    public init(config: MultipeerReplicatorConfiguration) throws

    Parameters

    config

    The replicator configuration.

  • Starts peer discovery and replication with connected peers. Note: Once stopped, restarting is not currently supported.

    Declaration

    Swift

    public func start()
  • Stops peer discovery and all active replicators. Note: Once stopped, restarting is not currently supported.

    Declaration

    Swift

    public func stop()
  • Returns information about a peer.

    Declaration

    Swift

    public func peerInfo(for peerID: PeerID) -> PeerInfo?

    Parameters

    peerID

    The identifier of the peer.

    Return Value

    A PeerInfo instance if the peer is known, or nil if unknown.

  • Adds a listener for changes to the multipeer replicator’s status.

    Declaration

    Swift

    @discardableResult
    public func addStatusListener(
        on queue: DispatchQueue? = .main,
        listener: @escaping (MultipeerReplicatorStatus) -> Void) -> ListenerToken

    Parameters

    queue

    The dispatch queue for invoking the listener. Defaults to the main queue.

    listener

    A closure that receives status updates.

    Return Value

    A token for removing the listener.

  • Adds a listener for updates to the peer discovery status.

    Declaration

    Swift

    @discardableResult
    public func addPeerDiscoveryStatusListener(
        on queue: DispatchQueue? = .main,
        listener: @escaping (PeerDiscoveryStatus) -> Void) -> ListenerToken

    Parameters

    queue

    The dispatch queue for invoking the listener. Defaults to the main queue.

    listener

    A closure that receives peer discovery status updates.

    Return Value

    A token for removing the listener.

  • Adds a listener for replicator status updates from each connected peer.

    Declaration

    Swift

    @discardableResult
    public func addPeerReplicatorStatusListener(
        on queue: DispatchQueue? = .main,
        listener: @escaping (PeerReplicatorStatus) -> Void) -> ListenerToken

    Parameters

    queue

    The dispatch queue used to invoke the listener. Defaults to the main queue.

    listener

    A closure that receives updates about the replicator status of each connected peer.

    Return Value

    A ListenerToken for removing the listener.

  • Adds a listener for document replication updates from each connected peer.

    Declaration

    Swift

    @discardableResult
    public func addPeerDocumentReplicationListener(
        on queue: DispatchQueue? = .main,
        listener: @escaping (PeerDocumentReplication) -> Void) -> ListenerToken

    Parameters

    queue

    The dispatch queue on which to invoke the listener. Defaults to the main queue.

    listener

    A closure to receive per-peer document replication updates.

    Return Value

    A token for removing the listener.

  • Returns a Combine publisher that emits updates to multipeer replicator’s status.

    Declaration

    Swift

    public func statusPublisher(
        on queue: DispatchQueue = .main
    ) -> AnyPublisher<MultipeerReplicatorStatus, Never>

    Parameters

    queue

    The dispatch queue on which events are delivered. Defaults to the main queue.

    Return Value

    An AnyPublisher that emits MultipeerReplicatorStatus values. /// - Note: The underlying listener is automatically removed when the subscription is cancelled.

  • Returns a Combine publisher that emits updates to the peer discovery status.

    Note

    The underlying listener is automatically removed when the subscription is cancelled.

    Declaration

    Swift

    public func peerDiscoveryStatusPublisher(
        on queue: DispatchQueue = .main
    ) -> AnyPublisher<PeerDiscoveryStatus, Never>

    Parameters

    queue

    The dispatch queue on which events are delivered. Defaults to the main queue.

    Return Value

    An AnyPublisher that emits PeerDiscoveryStatus values.

  • Returns a Combine publisher that emits replicator status updates for each connected peer.

    Note

    The underlying listener is automatically removed when the subscription is cancelled.

    Declaration

    Swift

    public func peerReplicatorStatusPublisher(
        on queue: DispatchQueue = .main
    ) -> AnyPublisher<PeerReplicatorStatus, Never>

    Parameters

    queue

    The dispatch queue used to deliver events. Defaults to the main queue.

    Return Value

    An AnyPublisher that emits PeerReplicatorStatus values.

  • Returns a Combine publisher that emits document replication updates from each connected peer.

    Note

    The underlying listener is automatically removed when the subscription is cancelled.

    Declaration

    Swift

    public func peerDocumentReplicationPublisher(
        on queue: DispatchQueue = .main
    ) -> AnyPublisher<PeerDocumentReplication, Never>

    Parameters

    queue

    The dispatch queue on which events are delivered. Defaults to the main queue.

    Return Value

    An AnyPublisher that emits PeerDocumentReplication values.