-
-
Save fitomad/424f428df4823f17f1a00fed4963b724 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CercaViewModel: MCNearbyServiceBrowserDelegate | |
{ | |
... | |
/// 1 | |
func browser(_ browser: MCNearbyServiceBrowser, foundPeer peerID: MCPeerID, withDiscoveryInfo info: [String: String]?) -> Void | |
{ | |
guard let info = info, | |
let identity = info["identity"], | |
let multipeerSession = self.multipeerSession, | |
(identity == self.serviceIdentity && multipeerSession.connectedPeers.count < self.maxPeersInSession) | |
else | |
{ | |
return | |
} | |
browser.invitePeer(peerID, to: multipeerSession, withContext: nil, timeout: 10) | |
} | |
... | |
} | |
extension CercaViewModel: MCSessionDelegate | |
{ | |
... | |
/// 2 | |
func session(_ session: MCSession, peer peerID: MCPeerID, didChange state: MCSessionState) | |
{ | |
DispatchQueue.main.async | |
{ | |
switch state | |
{ | |
case .connected: | |
self.peerName = peerID.displayName | |
self.peer = peerID | |
// 3 | |
self.shareTokenWithAllPeers() | |
self.isConnectionLost = false | |
case .notConnected: | |
self.isConnectionLost = true | |
case .connecting: | |
self.peerName = "Hola ¿Quién eres? 👋" | |
@unknown default: | |
fatalError("Ha aparecido un estado nuevo de la enumeración. Ni idea lo que hacer.") | |
} | |
} | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment