MultipeerReplicator
public class MultipeerReplicator
A multipeer replicator that manages peer discovery, connection, and replication in multipeer mesh network.
-
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.
Warning
This property can block for several seconds in some cases. It is recommended to not access it on the UI thread. This is a known issue we plan to address in a future release.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) throwsParameters
configThe 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.
Warning
This method can block for several seconds in some cases. It is recommended to not call this on the UI thread. This is a known issue we plan to address in a future release.
Parameters
peerIDThe identifier of the peer.
Return Value
A
PeerInfoinstance if the peer is known, ornilif unknown. -
Returns the current status of the given transport.
Warning
This method can block for several seconds in some cases. It is recommended to not call this on the UI thread. This is a known issue we plan to address in a future release.
Declaration
Swift
public func status(for transport: MultipeerTransport) -> MultipeerReplicatorStatus?Parameters
transportThe transport to query for the status.
Return Value
The current status, or
nilif the transport is not enabled. -
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) -> ListenerTokenParameters
queueThe dispatch queue for invoking the listener. Defaults to the main queue.
listenerA 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) -> ListenerTokenParameters
queueThe dispatch queue for invoking the listener. Defaults to the main queue.
listenerA 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) -> ListenerTokenParameters
queueThe dispatch queue used to invoke the listener. Defaults to the main queue.
listenerA closure that receives updates about the replicator status of each connected peer.
Return Value
A
ListenerTokenfor 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) -> ListenerTokenParameters
queueThe dispatch queue on which to invoke the listener. Defaults to the main queue.
listenerA 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
queueThe dispatch queue on which events are delivered. Defaults to the main queue.
Return Value
An
AnyPublisherthat emitsMultipeerReplicatorStatusvalues. /// - 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
queueThe dispatch queue on which events are delivered. Defaults to the main queue.
Return Value
An
AnyPublisherthat emitsPeerDiscoveryStatusvalues. -
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
queueThe dispatch queue used to deliver events. Defaults to the main queue.
Return Value
An
AnyPublisherthat emitsPeerReplicatorStatusvalues. -
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
queueThe dispatch queue on which events are delivered. Defaults to the main queue.
Return Value
An
AnyPublisherthat emitsPeerDocumentReplicationvalues.
MultipeerReplicator Class Reference