Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Sources/MultiPeer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ public class MultiPeer: NSObject {
}
}
}

public func invite(peer: Peer, context: Data? = nil) {
self.serviceBrowser.invitePeer(peer.peerID, to: session, withContext: context, timeout: connectionTimeout)
}

/** Prints only if in debug mode */
fileprivate func printDebug(_ string: String) {
Expand Down Expand Up @@ -213,10 +217,13 @@ extension MultiPeer: MCNearbyServiceBrowserDelegate {
public func browser(_ browser: MCNearbyServiceBrowser, foundPeer peerID: MCPeerID, withDiscoveryInfo info: [String: String]?) {
printDebug("Found peer: \(peerID)")

let peer = Peer(peerID: peerID, state: .notConnected)
// Update the list of available peers
availablePeers.append(Peer(peerID: peerID, state: .notConnected))
availablePeers.append(peer)

browser.invitePeer(peerID, to: session, withContext: nil, timeout: connectionTimeout)
if self.delegate?.multiPeer(shouldInvitePeerDidFound: peerID, browser: browser, withDiscoveryInfo: info) ?? true {
invite(peer: peer)
}
}

/// Lost a peer, update the list of available peers
Expand Down
3 changes: 3 additions & 0 deletions Sources/MultiPeerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import MultipeerConnectivity

/// MultiPeerDelegate
///
Expand All @@ -21,5 +22,7 @@ public protocol MultiPeerDelegate: class {

/// connectedDevicesChanged: delegate runs on connection/disconnection event in session
func multiPeer(connectedDevicesChanged devices: [String])

func multiPeer(shouldInvitePeerDidFound peerID: MCPeerID, browser: MCNearbyServiceBrowser, withDiscoveryInfo info: [String: String]?) -> Bool

}