예제 #1
0
        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);
        }
예제 #3
0
        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));
                    });
                }
            }
        }
예제 #4
0
        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";
        }
예제 #7
0
 public GameBrowser(Player myself) : base()
 {
     this.myself         = myself;
     this.serviceBrowser = new MCNearbyServiceBrowser(this.myself.PeerId, XamarinShotGameService.PlayerService)
     {
         Delegate = this
     };
     this.serviceBrowser.Delegate = this;
 }
예제 #8
0
 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();
     }
 }
예제 #9
0
 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));
         }
     });
 }
예제 #10
0
        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();
        }
예제 #11
0
 public void LostPeer(MCNearbyServiceBrowser browser, MCPeerID peerID)
 {
     // This app doesn't do anything with non-invited peers, so there's nothing to do here.
 }
예제 #12
0
 public void FoundPeer(MCNearbyServiceBrowser browser, MCPeerID peerID, NSDictionary info)
 {
     // Invite the new peer to the session.
     browser.InvitePeer(peerID, this.session, null, 10);
 }
예제 #13
0
 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);
 }
예제 #14
0
 public override void LostPeer(MCNearbyServiceBrowser browser, MCPeerID peerID)
 {
     Console.WriteLine("Lost peer {0}", peerID);
 }
예제 #15
0
 public override void LostPeer(MCNearbyServiceBrowser browser, MCPeerID peerID)
 {
     Debug.WriteLine("### LOST PEER: " + peerID.DisplayName);
 }
예제 #16
0
 public override void DidNotStartBrowsingForPeers(MCNearbyServiceBrowser browser, NSError error)
 {
     Debug.WriteLine("### DID NOT START BROWSING: " + error);
 }