public void initializeMCServices() { myPeerId = new MCPeerID(UIDevice.CurrentDevice.Name); MyAdvertiserDelegate myAdvertiserDelegate = new MyAdvertiserDelegate(this); MyBrowserDelegate myBrowserDelegate = new MyBrowserDelegate(this); MySessionDelegate mySessionDelegate = new MySessionDelegate(this); var emptyDict = new NSDictionary(); MCNearbyServiceAdvertiser serviceAdvertiser = new MCNearbyServiceAdvertiser(myPeerId, emptyDict, serviceTypeString); serviceAdvertiser.Delegate = myAdvertiserDelegate; serviceAdvertiser.StartAdvertisingPeer(); MCNearbyServiceBrowser serviceBrowser = new MCNearbyServiceBrowser(myPeerId, serviceTypeString); serviceBrowser.Delegate = myBrowserDelegate; serviceBrowser.StartBrowsingForPeers(); session = new MCSession(myPeerId); session.Delegate = mySessionDelegate; sendPeerToPeerData(myPeerId.DisplayName); }
public override void DidNotStartBrowsingForPeers(MCNearbyServiceBrowser browser, NSError error) { System.Console.WriteLine("MCNearbyServiceBrowserDelegate ERROR peer "); //TODO: Error dialog //parent.Status("DidNotStartBrowingForPeers " + error.Description); }
public void FoundPeer(MCNearbyServiceBrowser browser, MCPeerID peerID, NSDictionary info) { if (peerID != this.myself.PeerId) { var appIdentifier = info?[XamarinShotGameAttribute.AppIdentifier]; if (appIdentifier?.ToString() == NSBundle.MainBundle.BundleIdentifier) { DispatchQueue.MainQueue.DispatchAsync(() => { var player = new Player(peerID); var gameName = info?[XamarinShotGameAttribute.Name] as NSString; GameTableLocation location = null; var locationIdString = info?[XamarinShotGameAttribute.Location] as NSString; if (!string.IsNullOrEmpty(locationIdString) && int.TryParse(locationIdString, out int locationId)) { location = GameTableLocation.GetLocation(locationId); } var game = new NetworkGame(player, gameName, location?.Identifier ?? 0); this.games.Add(game); this.Delegate?.SawGames(this, new List <NetworkGame>(this.games)); }); } } }
public Task StartScanning() { var isWifiEnabled = NetworkInterfaces.IsWifiEnabled(); if (!isWifiEnabled) { throw new WiFiTurnedOffException(); } var myPeerId = new MCPeerID(UIDevice.CurrentDevice.Name); _session = new MCSession(myPeerId) { Delegate = new SessionDelegate(this) }; MainThread.BeginInvokeOnMainThread(() => { var browser = new MCNearbyServiceBrowser(myPeerId, BluetoothOperator.CROSSCAM_SERVICE) { Delegate = new NewBrowserDelegate(this) }; browser.StartBrowsingForPeers(); }); Debug.WriteLine("### SCANNING START"); return(Task.FromResult(true)); }
public override void FoundPeer(MCNearbyServiceBrowser browser, MCPeerID peerID, NSDictionary info) { System.Console.WriteLine("MCNearbyServiceBrowserDelegate Found peer " + peerID.DisplayName); // Initialize dual purpose object status and cache object for PeerID if (!AppDelegate.PeerHistoryMonitor.ContainsKey(peerID.DisplayName)) { AppDelegate.PeerHistoryMonitor.Add(peerID.DisplayName, new PeerMonitorStatus() { LastActive = DateTime.UtcNow, PeerID = peerID }); } /* * * // DEBUG ONLY - this IF statement is commented out while only one machine is a browse * .. in the real world, both machines will be Advertiser and browser. * * // commented out while testing on two different machines (one is dedicated browser, other is dedicated advertiser... see NearbyDevicesViewController.cs) * * */ // Connect to server if the hash value is greater //if (browser.MyPeerID.GetNativeHash() > peerID.GetNativeHash()) { System.Console.WriteLine("browser ID" + browser.MyPeerID.GetNativeHash()); System.Console.WriteLine("PeerID " + peerID.GetNativeHash()); browser.InvitePeer(peerID, session, context, 60); } }
public override void LostPeer(MCNearbyServiceBrowser browser, MCPeerID peerID) { System.Console.WriteLine("MCNearbyServiceBrowserDelegate LOST peer " + peerID.DisplayName); // Safe to skip null check in dictionary b/c FoundPeer runs first //AppDelegate. PeerHistoryMonitor[peerID.DisplayName].LastError = DateTime.UtcNow; //AppDelegate. PeerHistoryMonitor[peerID.DisplayName].LastErrorString = "Lost peer"; }
public GameBrowser(Player myself) : base() { this.myself = myself; this.serviceBrowser = new MCNearbyServiceBrowser(this.myself.PeerId, XamarinShotGameService.PlayerService) { Delegate = this }; this.serviceBrowser.Delegate = this; }
public override void FoundPeer(MCNearbyServiceBrowser browser, MCPeerID peerID, NSDictionary info) { if (_platformBluetooth._session != null) { Debug.WriteLine("### FOUND PEER: " + peerID.DisplayName); browser.InvitePeer(peerID, _platformBluetooth._session, null, 30); browser.StopBrowsingForPeers(); } }
public void LostPeer(MCNearbyServiceBrowser browser, MCPeerID peerID) { DispatchQueue.MainQueue.DispatchAsync(() => { var removed = this.games.FirstOrDefault(game => game.Host.PeerId != peerID); if (removed != null) { this.games.Remove(removed); this.Delegate?.SawGames(this, new List <NetworkGame>(this.games)); } }); }
public MultipeerSession(Action <NSData, MCPeerID> receivedDataHandler) : base() { this.receivedDataHandler = receivedDataHandler; this.session = new MCSession(this.myPeerID, null, MCEncryptionPreference.Required); this.session.Delegate = this; this.serviceAdvertiser = new MCNearbyServiceAdvertiser(this.myPeerID, null, ServiceType); this.serviceAdvertiser.Delegate = this; this.serviceAdvertiser.StartAdvertisingPeer(); this.serviceBrowser = new MCNearbyServiceBrowser(this.myPeerID, ServiceType); this.serviceBrowser.Delegate = this; this.serviceBrowser.StartBrowsingForPeers(); }
public void LostPeer(MCNearbyServiceBrowser browser, MCPeerID peerID) { // This app doesn't do anything with non-invited peers, so there's nothing to do here. }
public void FoundPeer(MCNearbyServiceBrowser browser, MCPeerID peerID, NSDictionary info) { // Invite the new peer to the session. browser.InvitePeer(peerID, this.session, null, 10); }
public override void FoundPeer(MCNearbyServiceBrowser browser, MCPeerID peerID, NSDictionary info) { Console.WriteLine("Found peer {0}", peerID); Console.WriteLine("Invite peer {0}", peerID); browser.InvitePeer(peerID, DataTransferServices.session, null, 10.0); }
public override void LostPeer(MCNearbyServiceBrowser browser, MCPeerID peerID) { Console.WriteLine("Lost peer {0}", peerID); }
public override void LostPeer(MCNearbyServiceBrowser browser, MCPeerID peerID) { Debug.WriteLine("### LOST PEER: " + peerID.DisplayName); }
public override void DidNotStartBrowsingForPeers(MCNearbyServiceBrowser browser, NSError error) { Debug.WriteLine("### DID NOT START BROWSING: " + error); }