|
7 | 7 |
|
8 | 8 | import MultipeerConnectivity |
9 | 9 |
|
| 10 | +/// Delegate for some useful multipeer connectivity methods |
10 | 11 | @objc public protocol MultipeerHelperDelegate: AnyObject { |
11 | 12 | /// Data that has been recieved from another peer |
12 | 13 | /// - Parameters: |
13 | | - /// - data: The data which has been recieved |
14 | | - /// - peer: The peer that sent the data |
15 | | - @objc optional func receivedData(_ data: Data, _ peer: MCPeerID) |
| 14 | + /// - peerHelper: The ``MultipeerHelper`` session that manages the multipeer connectivity |
| 15 | + /// - data: The data which has been recieved |
| 16 | + /// - peer: The peer that sent the data |
| 17 | + @objc optional func receivedData(peerHelper: MultipeerHelper, _ data: Data, _ peer: MCPeerID) |
16 | 18 |
|
17 | 19 | /// Callback for when a peer joins the network |
18 | | - /// - Parameter peer: the `MCPeerID` of the newly joined peer |
19 | | - @objc optional func peerJoined(_ peer: MCPeerID) |
| 20 | + /// - Parameters: |
| 21 | + /// - peerHelper: The ``MultipeerHelper`` session that manages the multipeer connectivity |
| 22 | + /// - peer: the `MCPeerID` of the newly joined peer |
| 23 | + @objc optional func peerJoined(peerHelper: MultipeerHelper, _ peer: MCPeerID) |
20 | 24 |
|
21 | 25 | /// Callback for when a peer leaves the network |
22 | | - /// - Parameter peer: the `MCPeerID` of the peer that left |
23 | | - @objc optional func peerLeft(_ peer: MCPeerID) |
| 26 | + /// - Parameters: |
| 27 | + /// - peerHelper: The ``MultipeerHelper`` session that manages the multipeer connectivity |
| 28 | + /// - peer: the `MCPeerID` of the peer that left |
| 29 | + @objc optional func peerLeft(peerHelper: MultipeerHelper, _ peer: MCPeerID) |
24 | 30 |
|
25 | 31 | /// Callback for when a new peer has been found. will default to accept all peers |
26 | | - /// - Parameter peer: the `MCPeerID` of the peer who wants to join the network |
27 | | - /// - Parameter discoveryInfo: The info dictionary advertised by the discovered peer. For more information on the contents of this dictionary, see the documentation for |
| 32 | + /// - Parameters: |
| 33 | + /// - peerHelper: The ``MultipeerHelper`` session that manages the multipeer connectivity |
| 34 | + /// - peer: the `MCPeerID` of the peer who wants to join the network |
| 35 | + /// - discoveryInfo: The info dictionary advertised by the discovered peer. For more information on the contents of this dictionary, see the documentation for |
28 | 36 | /// [init(peer:discoveryInfo:serviceType:)](apple-reference-documentation://ls%2Fdocumentation%2Fmultipeerconnectivity%2Fmcnearbyserviceadvertiser%2F1407102-init) in [MCNearbyServiceAdvertiser](apple-reference-documentation://ls%2Fdocumentation%2Fmultipeerconnectivity%2Fmcnearbyserviceadvertiser). |
29 | 37 | /// - Returns: Bool if the peer request to join the network or not |
30 | | - @objc optional func shouldSendJoinRequest(_ peer: MCPeerID, with discoveryInfo: [String: String]?) -> Bool |
| 38 | + @objc optional func shouldSendJoinRequest(peerHelper: MultipeerHelper, _ peer: MCPeerID, with discoveryInfo: [String: String]?) -> Bool |
31 | 39 |
|
32 | 40 | /// Handle when a peer has requested to join the network |
33 | 41 | /// - Parameters: |
| 42 | + /// - peerHelper: The ``MultipeerHelper`` session that manages the multipeer connectivity |
34 | 43 | /// - peerID: Peer requesting to join |
35 | 44 | /// - context: Any data the requesting peer may have sent with their request |
36 | 45 | /// - Returns: Bool if the peer's join request should be accepted |
37 | | - @objc optional func shouldAcceptJoinRequest(peerID: MCPeerID, context: Data?) -> Bool |
| 46 | + @objc optional func shouldAcceptJoinRequest(peerHelper: MultipeerHelper, peerID: MCPeerID, context: Data?) -> Bool |
38 | 47 |
|
39 | 48 | /// This will be set as the base for the discoveryInfo, which is sent out by the advertiser (host). |
40 | 49 | /// The key "MultipeerHelper.compTokenKey" is in use by MultipeerHelper, for checking the |
41 | 50 | /// compatibility of RealityKit versions. |
| 51 | + /// - Returns: Discovery Info |
42 | 52 | @objc optional func setDiscoveryInfo() -> [String: String] |
43 | 53 |
|
44 | 54 | /// Peer can no longer be found on the network, and thus cannot receive data |
45 | | - /// - Parameter peer: If a peer has left the network in a non typical way |
46 | | - @objc optional func peerLost(_ peer: MCPeerID) |
47 | | - @objc optional func receivedStream(_ stream: InputStream, _ streamName: String, _ peer: MCPeerID) |
48 | | - @objc optional func receivingResource(_ resourceName: String, _ peer: MCPeerID, _ progress: Progress) |
49 | | - @objc optional func receivedResource(_ resourceName: String, _ peer: MCPeerID, _ url: URL?, _ error: Error?) |
50 | | - @objc optional func receivedCertificate(certificate: [Any]?, fromPeer peerID: MCPeerID) -> Bool |
| 55 | + /// - Parameters: |
| 56 | + /// - peerHelper: The ``MultipeerHelper`` session that manages the nearby peer whose state changed |
| 57 | + /// - peer: If a peer has left the network in a non typical way |
| 58 | + @objc optional func peerLost( |
| 59 | + peerHelper: MultipeerHelper, _ peer: MCPeerID |
| 60 | + ) |
| 61 | + |
| 62 | + /// Received a byte stream from remote peer. |
| 63 | + /// - Parameters: |
| 64 | + /// - peerHelper: The ``MultipeerHelper`` session through which the byte stream was opened |
| 65 | + /// - stream: An NSInputStream object that represents the local endpoint for the byte stream. |
| 66 | + /// - streamName: The name of the stream, as provided by the originator. |
| 67 | + /// - peerID: The peer ID of the originator of the stream. |
| 68 | + @objc optional func receivedStream( |
| 69 | + peerHelper: MultipeerHelper, _ stream: InputStream, _ streamName: String, _ peer: MCPeerID |
| 70 | + ) |
| 71 | + /// Start receiving a resource from remote peer. |
| 72 | + /// - Parameters: |
| 73 | + /// - peerHelper: The ``MultipeerHelper`` session that started receiving the resource |
| 74 | + /// - resourceName: name of the resource, as provided by the sender. |
| 75 | + /// - peerID: sender’s peer ID. |
| 76 | + /// - progress: NSProgress object that can be used to cancel the transfer or queried to determine how far the transfer has progressed. |
| 77 | + @objc optional func receivingResource( |
| 78 | + peerHelper: MultipeerHelper, _ resourceName: String, _ peer: MCPeerID, _ progress: Progress |
| 79 | + ) |
| 80 | + /// Received a resource from remote peer. |
| 81 | + /// - Parameters: |
| 82 | + /// - peerHelper: The ``MultipeerHelper`` session through which the data were received |
| 83 | + /// - resourceName: The name of the resource, as provided by the sender. |
| 84 | + /// - peerID: The peer ID of the sender. |
| 85 | + /// - localURL: An NSURL object that provides the location of a temporary file containing the received data. |
| 86 | + /// - error: An error object indicating what went wrong if the file was not received successfully, or nil. |
| 87 | + @objc optional func receivedResource( |
| 88 | + peerHelper: MultipeerHelper, _ resourceName: String, _ peerID: MCPeerID, _ localUrl: URL?, _ error: Error? |
| 89 | + ) |
| 90 | + /// Made first contact with peer and have identity information about the |
| 91 | + /// remote peer (certificate may be nil). |
| 92 | + /// - Parameters: |
| 93 | + /// - peerHelper: The ``MultipeerHelper`` session that manages the nearby peer whose state changed |
| 94 | + /// - certificate: A certificate chain, presented as an array of SecCertificateRef certificate objects. The first certificate in this chain is the peer’s certificate, which is derived from the identity that the peer provided when it called the `initWithPeer:securityIdentity:encryptionPreference:` method. The other certificates are the (optional) additional chain certificates provided in that same array. |
| 95 | + /// If the nearby peer did not provide a security identity, then this parameter’s value is nil. |
| 96 | + /// - peerID: The peer ID of the sender. |
| 97 | + @objc optional func receivedCertificate( |
| 98 | + peerHelper: MultipeerHelper, certificate: [Any]?, fromPeer peerID: MCPeerID) -> Bool |
51 | 99 | } |
52 | 100 |
|
53 | 101 | #if canImport(RealityKit) |
|
0 commit comments