diff --git a/GetHip.xcodeproj/project.pbxproj b/GetHip.xcodeproj/project.pbxproj index 8f8acc1..ae023dc 100644 --- a/GetHip.xcodeproj/project.pbxproj +++ b/GetHip.xcodeproj/project.pbxproj @@ -49,6 +49,8 @@ 3E4169491C385F1000B193AF /* 1x.png in Resources */ = {isa = PBXBuildFile; fileRef = 3E4169481C385F1000B193AF /* 1x.png */; }; 3E4169551C398A5B00B193AF /* SignUpViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E4169541C398A5B00B193AF /* SignUpViewController.swift */; }; 3E4169571C399C4D00B193AF /* Images-3.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3E4169561C399C4D00B193AF /* Images-3.xcassets */; }; + 3E41D74C1C8D17E100FFD846 /* icon-120.png in Resources */ = {isa = PBXBuildFile; fileRef = 3E41D74B1C8D17E100FFD846 /* icon-120.png */; }; + 3E41D74E1C8D17F300FFD846 /* Icon-60.png in Resources */ = {isa = PBXBuildFile; fileRef = 3E41D74D1C8D17F300FFD846 /* Icon-60.png */; }; 3E438ADE1C572DFD0055C97A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3E438ADD1C572DFD0055C97A /* Main.storyboard */; }; 3E438AE61C5738EF0055C97A /* Create@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 3E438AE11C5738EF0055C97A /* Create@2x.png */; }; 3E438AE71C5738EF0055C97A /* Friends@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 3E438AE21C5738EF0055C97A /* Friends@2x.png */; }; @@ -196,6 +198,8 @@ 3E4169481C385F1000B193AF /* 1x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = 1x.png; path = "../../../Dropbox/Gethip/Screens/Logo Screen/6 Logo Screen/1x.png"; sourceTree = ""; }; 3E4169541C398A5B00B193AF /* SignUpViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignUpViewController.swift; sourceTree = ""; }; 3E4169561C399C4D00B193AF /* Images-3.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Images-3.xcassets"; sourceTree = ""; }; + 3E41D74B1C8D17E100FFD846 /* icon-120.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon-120.png"; sourceTree = ""; }; + 3E41D74D1C8D17F300FFD846 /* Icon-60.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-60.png"; sourceTree = ""; }; 3E438ADD1C572DFD0055C97A /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; 3E438AE11C5738EF0055C97A /* Create@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Create@2x.png"; path = "../../../Dropbox/Gethip/Screens/iPhone 5 Home/Icon Assets/Create@2x.png"; sourceTree = ""; }; 3E438AE21C5738EF0055C97A /* Friends@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Friends@2x.png"; path = "../../../Dropbox/Gethip/Screens/iPhone 5 Home/Icon Assets/Friends@2x.png"; sourceTree = ""; }; @@ -419,6 +423,8 @@ 3E1BDA4F1C37111D00EE3B84 /* Supporting Files */ = { isa = PBXGroup; children = ( + 3E41D74D1C8D17F300FFD846 /* Icon-60.png */, + 3E41D74B1C8D17E100FFD846 /* icon-120.png */, 3E1BDA501C37111D00EE3B84 /* Info.plist */, ); name = "Supporting Files"; @@ -845,6 +851,7 @@ 3E438AE91C5738EF0055C97A /* Star@2x.png in Resources */, 3E5BD3151C6C45CE00266B16 /* Home Copy@2x.png in Resources */, 3E5952831C39DDA800C88C71 /* Settings@3x.png in Resources */, + 3E41D74C1C8D17E100FFD846 /* icon-120.png in Resources */, 3E7BB8E21C5B4A350005B834 /* Change Song@2x.png in Resources */, 3E59526B1C39DBC900C88C71 /* Star@3x.png in Resources */, 3E59527B1C39DDA800C88C71 /* Create.png in Resources */, @@ -862,6 +869,7 @@ 3E59526F1C39DC1E00C88C71 /* Rectangle 10 + Change Photo + voice_presentation copy + voice_presentation copy 2 + voice_presentation + Music 2 + Music 2.png in Resources */, 3E59527F1C39DDA800C88C71 /* Group@2x.png in Resources */, 3E5952691C39DBC900C88C71 /* Star.png in Resources */, + 3E41D74E1C8D17F300FFD846 /* Icon-60.png in Resources */, 3E59527C1C39DDA800C88C71 /* Create@2x.png in Resources */, 3E7D37D51C75D7EF002E682F /* Raise@2x.png in Resources */, 3E59526A1C39DBC900C88C71 /* Star@2x.png in Resources */, diff --git a/GetHip/FriendData.swift b/GetHip/FriendData.swift index 2fa8166..4d4a6d2 100644 --- a/GetHip/FriendData.swift +++ b/GetHip/FriendData.swift @@ -8,7 +8,7 @@ import Foundation -class FriendData { +class FriendData: NSObject, NSCoding { var displayName: String! var profileImg: UIImageView! var status: String! @@ -17,8 +17,39 @@ class FriendData { self.displayName = display self.profileImg = nil self.status = status + super.init() } + //MARK: NSCoding + required init(coder aDecoder: NSCoder){ + self.displayName = aDecoder.decodeObjectForKey("displayName") as! String + self.profileImg = aDecoder.decodeObjectForKey("profileImg") as! UIImageView! + self.status = aDecoder.decodeObjectForKey("status") as! String + + super.init() + } + + func encodeWithCoder(aCoder: NSCoder){ + aCoder.encodeObject(self.displayName, forKey: "displayName") + aCoder.encodeObject(self.profileImg, forKey: "profileImg") + aCoder.encodeObject(self.status, forKey: "status") + } + + //Mark: NSObject + + override func isEqual(object: AnyObject?) -> Bool{ + if let object = object as? FriendData { + return self.displayName == object.displayName + && self.profileImg == object.profileImg + && self.status == object.status + }else { + return false + } + } + + override var hash: Int { + return self.displayName.hashValue + } } diff --git a/GetHip/HomeScreenViewController.swift b/GetHip/HomeScreenViewController.swift index ed5ad94..f2743b9 100644 --- a/GetHip/HomeScreenViewController.swift +++ b/GetHip/HomeScreenViewController.swift @@ -17,7 +17,7 @@ class HomeScreenViewController: UIViewController, PartyServiceManagerDelegate { var userData: [UserParseData] = [] let partyData = PartyServiceManager() var firstTime: Bool = true - + private var firstTimeBrowsing: Bool = true @IBOutlet weak var CreateAPartyBtn: UIButton! @@ -33,6 +33,15 @@ class HomeScreenViewController: UIViewController, PartyServiceManagerDelegate { self.friendData.append(pendingFriend) } } + + //start browsing for peers + self.partyData.setBrowser() + self.partyData.startBrowser() + + //self.partyData.delegate = self + self.firstTime = false + + } func refreshUserData(notification:NSNotification){ @@ -47,12 +56,13 @@ class HomeScreenViewController: UIViewController, PartyServiceManagerDelegate { self.partyData.setAdvertiser() self.partyData.startListening() + self.frndDataManager = FriendDataSource() //start browsing for peers - self.partyData.setBrowser() - self.partyData.startBrowser() + //self.partyData.setBrowser() + //self.partyData.startBrowser() self.partyData.delegate = self - self.firstTime = false + //self.firstTime = false } } @@ -87,7 +97,6 @@ class HomeScreenViewController: UIViewController, PartyServiceManagerDelegate { self.friendData = [] dispatch_async(dispatch_get_main_queue(), { self.usrDataManager = UserParseDataSource() - self.frndDataManager = FriendDataSource() }) } @@ -141,6 +150,14 @@ class HomeScreenViewController: UIViewController, PartyServiceManagerDelegate { extension HomeScreenViewController: PartyServiceManagerDelegate { func foundPeer() { + if(self.firstTimeBrowsing == true){ + //used for finding nearby friends when starting a party + for i in 0.. UICollectionViewCell { - let friend = self.party.invitedFriends[indexPath.row] - let cell: InvitedCollectionViewCell = self.friendsInParty.dequeueReusableCellWithReuseIdentifier("InvitedCollectionCell", forIndexPath: indexPath) as! InvitedCollectionViewCell + var cell: InvitedCollectionViewCell! - if friend.profileImg == nil { - cell.friendImage.backgroundColor = UIColor.grayColor() - } - else{ - cell.friendImage.image = friend.profileImg.image! + if(self.party.role == PeerType.Host_Creator){ + let friend = self.party.invitedFriends[indexPath.row] + cell = self.friendsInParty.dequeueReusableCellWithReuseIdentifier("InvitedCollectionCell", forIndexPath: indexPath) as! InvitedCollectionViewCell + + if friend.profileImg == nil { + cell.friendImage.backgroundColor = UIColor.grayColor() + } + else{ + cell.friendImage.image = friend.profileImg.image! + } + + //rounds uiimage and configures UIImageView + cell.friendImage.layer.cornerRadius = cell.friendImage.frame.size.width/2 + cell.friendImage.clipsToBounds = true + }else{ + cell = InvitedCollectionViewCell() } - //rounds uiimage and configures UIImageView - cell.friendImage.layer.cornerRadius = cell.friendImage.frame.size.width/2 - cell.friendImage.clipsToBounds = true return cell diff --git a/GetHip/Info.plist b/GetHip/Info.plist index e93260b..39b7897 100644 --- a/GetHip/Info.plist +++ b/GetHip/Info.plist @@ -6,6 +6,11 @@ en CFBundleExecutable $(EXECUTABLE_NAME) + CFBundleIconFiles + + Icon-60.png + icon-120.png + CFBundleIdentifier com.Kroleo.$(PRODUCT_NAME:rfc1034identifier) CFBundleInfoDictionaryVersion @@ -30,7 +35,7 @@ CFBundleVersion - 1 + 2 FacebookAppID 1166375230058840 FacebookDisplayName diff --git a/GetHip/InvitedToPartyViewController.swift b/GetHip/InvitedToPartyViewController.swift index 33c54b1..87385e3 100644 --- a/GetHip/InvitedToPartyViewController.swift +++ b/GetHip/InvitedToPartyViewController.swift @@ -27,6 +27,7 @@ class InvitedToPartyViewController: UIViewController , PartyServiceManagerDelega } @IBAction func acceptInvite(sender: UIButton){ + self.partyData.currentHost = self.fromPeer.displayName self.inviteHandle(true, self.partyData.session) self.performSegueWithIdentifier("JoiningPartySegue", sender: self) } diff --git a/GetHip/JoiningPartyViewController.swift b/GetHip/JoiningPartyViewController.swift index 08d696b..89cc751 100644 --- a/GetHip/JoiningPartyViewController.swift +++ b/GetHip/JoiningPartyViewController.swift @@ -14,6 +14,7 @@ class JoiningPartyViewController: UIViewController ,PartyServiceManagerDelegate{ var request = [] var user: [UserParseData]! var party: PartyServiceManager! + private var isHostConnected = false override func viewDidLoad() { super.viewDidLoad() @@ -64,13 +65,28 @@ extension JoiningPartyViewController: PartyServiceManagerDelegate { } func invitationWasRecieved(peerID: MCPeerID, invitationHandler: ((Bool, MCSession!) -> Void)!) { - + if(self.isHostConnected == true){ + if(self.party.connectedPeersDictionary[ peerID.displayName] == nil){ + invitationHandler(true, self.party.session) + } + } } func connectedWithPeer(peerID: MCPeerID) { println("mark 2") - var dictionary: Dictionary = ["sender": self.party.myPeerID.displayName, "instruction": "joined_party"] - self.party.sendInstruction(dictionary, toPeer: peerID) + + + if(self.isHostConnected == false){ + var dictionary: Dictionary = Dictionary() + dictionary["sender"] = self.party.myPeerID.displayName + dictionary["instruction"] = "joined_party" + self.party.sendInstruction(dictionary, toPeer: peerID) + self.isHostConnected = true + } + + + + } func didRecieveInstruction(dictionary: Dictionary){ @@ -86,6 +102,8 @@ extension JoiningPartyViewController: PartyServiceManagerDelegate { self.dismissViewControllerAnimated(true, completion: nil) } + + if (instruction == "start_party"){ println("mark 4") self.performSegueWithIdentifier("EnteringPartySegue", sender: self) diff --git a/GetHip/LoadingPartyViewController.swift b/GetHip/LoadingPartyViewController.swift index 70179bb..952dac2 100644 --- a/GetHip/LoadingPartyViewController.swift +++ b/GetHip/LoadingPartyViewController.swift @@ -23,8 +23,10 @@ class LoadingPartyViewController: UIViewController, UICollectionViewDataSource, @IBOutlet var invitedFriends: UICollectionView! @IBOutlet var songLabel: UILabel! @IBOutlet var timerLabel: UILabel! + var arePeersReady = Dictionary() + private var firstPass: Bool = true var timer = NSTimer() - var counter = 60 + var counter = 30 @IBAction func cancelInvites(sender: UIButton){ self.dismissViewControllerAnimated(true, completion: nil) @@ -44,14 +46,18 @@ class LoadingPartyViewController: UIViewController, UICollectionViewDataSource, self.invitedFriends.dataSource = self self.invitedFriends.delegate = self - // Do any additional setup after loading the view. - self.songImg.image = self.party.currentSong.valueForProperty(MPMediaItemPropertyArtwork).imageWithSize(songImg.frame.size) - self.songLabel.text = (self.party.currentSong.valueForProperty(MPMediaItemPropertyTitle) as? String!)! + " by " + (self.party.currentSong.valueForProperty(MPMediaItemPropertyArtist) as? String!)! + if(self.firstPass){ + // Do any additional setup after loading the view. + self.songImg.image = self.party.currentSong.valueForProperty(MPMediaItemPropertyArtwork).imageWithSize(songImg.frame.size) + self.songLabel.text = (self.party.currentSong.valueForProperty(MPMediaItemPropertyTitle) as? String!)! + " by " + (self.party.currentSong.valueForProperty(MPMediaItemPropertyArtist) as? String!)! + + //sets up timer label and starts countdown to next screen + //NSNotificationCenter.defaultCenter().addObserver(self, selector: "updateThumbnail:", name: "peerConnected", object: nil) + self.timerLabel.text = String(counter) + self.timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("updateCounter"), userInfo: nil, repeats: true) + self.firstPass = false + } - //sets up timer label and starts countdown to next screen - //NSNotificationCenter.defaultCenter().addObserver(self, selector: "updateThumbnail:", name: "peerConnected", object: nil) - self.timerLabel.text = String(counter) - self.timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("updateCounter"), userInfo: nil, repeats: true) self.party.delegate = self } @@ -60,16 +66,105 @@ class LoadingPartyViewController: UIViewController, UICollectionViewDataSource, // Dispose of any resources that can be recreated. } - func updateThumbnil(notification: NSNotification){ + func updateCounter(){ + self.timerLabel.text = String(counter--) + println(self.timerLabel.text) + if(self.counter == -1){ + self.timer.invalidate() + prepareAndCheckPeers() + //self.timer = NSTimer.scheduledTimerWithTimeInterval(10, target: self, selector: Selector("prepareAndCheckPeers"), userInfo: nil, repeats: false) + //self.performSegueWithIdentifier("CurrentlyPlayingSegue", sender: nil) + } + } + + //selector functions for prepareAndCheckPeers selector function + func checkIfReady(){ + for peer in self.party.session.connectedPeers as! [MCPeerID] { + var dictionary: [String: AnyObject] = ["sender": self.party.myPeerID, "instruction": "are_you_ready", "connectedPeers": (self.party.session.connectedPeers as! [MCPeerID])] + self.party.sendInstruction(dictionary, toPeer: peer) + } + + var delayStart = NSTimer.scheduledTimerWithTimeInterval(15, target: self, selector: Selector("attemptToStart"), userInfo: nil, repeats: false) + } + + func startParty(){ + var dictionary: [String: String] = ["sender": self.party.myPeerID.displayName, "instruction": "start_party"] + + for peer in self.party.session.connectedPeers as! [MCPeerID] { + self.party.sendInstruction(dictionary, toPeer: peer ) + } + + self.performSegueWithIdentifier("CurrentlyPlayingSegue", sender: self) } - func updateCounter(){ - self.timerLabel.text = String(counter--) - if(self.counter == -1){ - self.timer.invalidate() - self.performSegueWithIdentifier("CurrentlyPlayingSegue", sender: nil) + func attemptToStart(){ + + + + for peer in self.party.session.connectedPeers as! [MCPeerID] { + if self.arePeersReady[peer.displayName] == false{ + var dictionary: [String: String] = ["sender": self.party.myPeerID.displayName, "instruction": "disconnect"] + self.party.sendInstruction(dictionary, toPeer: peer) + } } + + var delTimer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: Selector("startParty"), userInfo: nil, repeats: false) + + + } + + + func prepareAndCheckPeers(){ + + for connPeers in self.party.session.connectedPeers as! [MCPeerID] { + self.arePeersReady[connPeers.displayName] = false + } + + + for invited in self.party.invitedFriends { + var joinedPeer: MCPeerID? = self.party.connectedPeersDictionary[invited.displayName] as? MCPeerID + + if joinedPeer == nil { + for aPeer in self.party.foundPeers { + + if aPeer.displayName == invited.displayName { + self.party.session.cancelConnectPeer(aPeer) + self.party.disconnectedPeersDictionary.setValue(aPeer, forKey: aPeer.displayName) + break + } + } + }else{ + //sends array of currently connected peers to every connected peer to set up mesh streaming network + var currentlyConnected : [FriendData]! = [] + for peer in self.party.session.connectedPeers as! [MCPeerID]{ + for friend in self.party.invitedFriends { + if peer.displayName == friend.displayName { + currentlyConnected.append(friend) + } + } + } + var userDat = FriendData(display: self.usr[0].displayName, status: "") + userDat.profileImg = UIImageView(image: self.usr[0].profileImg.image) + currentlyConnected.append(userDat) + + var dictionaryConnected: [String: AnyObject] = ["sender": self.party.myPeerID, "instruction": "connect_to_other_peers", "connectedPeers": self.party.session.connectedPeers as! [MCPeerID], "friendData": currentlyConnected] + self.party.sendInstruction(dictionaryConnected, toPeer: joinedPeer!) + var delayCheck = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: Selector("checkIfReady"), userInfo: nil, repeats: false) + + + //var dictionary: [String: String] = ["sender": self.party.myPeerID.displayName, "instruction": "start_party"] + //self.party.sendInstruction(dictionary, toPeer: joinedPeer! ) + + //start streaming to connected peers + //self.party.outputStreamers[joinedPeer!.displayName]!.start() + + + + } + + } + } func setData(prty:PartyServiceManager, user: [UserParseData], friends: [FriendData], request: [FriendData]){ @@ -94,7 +189,11 @@ class LoadingPartyViewController: UIViewController, UICollectionViewDataSource, //rounds uiimage and configures UIImageView cell.friendImage.layer.cornerRadius = cell.friendImage.frame.size.width/2 cell.friendImage.clipsToBounds = true - cell.alpha = 0.5 + + if(self.party.connectedPeersDictionary[friend.displayName] == nil){ + cell.alpha = 0.5 + } + return cell @@ -113,7 +212,8 @@ class LoadingPartyViewController: UIViewController, UICollectionViewDataSource, // Get the new view controller using segue.destinationViewController. // Pass the selected object to the new view controller. if(segue.identifier == "CurrentlyPlayingSegue"){ - + /* + //PLACE THIS CODE IN A SEPARATE FUNCTION SO YOU CAN CONTROL TIMING BETTER AND MAKE SURE ALL PEERS ARE READY BEFORE MOVING ON //ends invitations with outstanding peers for invited in self.party.invitedFriends { var joinedPeer: MCPeerID? = self.party.connectedPeersDictionary[invited.displayName] as? MCPeerID @@ -128,7 +228,19 @@ class LoadingPartyViewController: UIViewController, UICollectionViewDataSource, } } }else{ - + //sends array of currently connected peers to every connected peer to set up mesh streaming network + var currentlyConnected : [FriendData]! + for peer in self.party.session.connectedPeers as! [MCPeerID]{ + for friend in self.party.invitedFriends { + if peer.displayName == friend.displayName { + currentlyConnected.append(friend) + } + } + } + var dictionaryConnected: [String: AnyObject] = ["sender": self.party.myPeerID, "instruction": "connect_to_other_peers", "connectedPeers": self.party.session.connectedPeers as! [MCPeerID], "friendData": currentlyConnected] + self.party.sendInstruction(dictionaryConnected, toPeer: joinedPeer!) + //END OF NOTE + var dictionary: [String: String] = ["sender": self.party.myPeerID.displayName, "instruction": "start_party"] self.party.sendInstruction(dictionary, toPeer: joinedPeer! ) @@ -148,7 +260,7 @@ class LoadingPartyViewController: UIViewController, UICollectionViewDataSource, println(error?.localizedDescription) return false }*/ - + */ let vc: CurrentlyPlayingViewController = (segue.destinationViewController as? CurrentlyPlayingViewController)! vc.setData(self.party, user: self.usr, friends: self.frnds, request: self.requestData) } @@ -195,11 +307,11 @@ extension LoadingPartyViewController: PartyServiceManagerDelegate { break } } - self.party.connectedPeersDictionary.setValue(fromPeer, forKey: fromPeer.displayName) - //let cell: InvitedCollectionViewCell = self.invitedFriends.dequeueReusableCellWithReuseIdentifier("InvitedCollectionCell", forIndexPath: NSIndexPath(index: i)) as! InvitedCollectionViewCell - //cell.alpha = 1.0 - println(instruction) + + + self.party.connectedPeersDictionary.setValue(fromPeer, forKey: fromPeer.displayName) + self.invitedFriends.reloadData() //prepares party for the guest peers @@ -261,6 +373,12 @@ extension LoadingPartyViewController: PartyServiceManagerDelegate { } + + if(instruction == "ready"){ + self.arePeersReady[fromPeer.displayName] = true + } + + println(instruction) } diff --git a/GetHip/PartyServiceManager.swift b/GetHip/PartyServiceManager.swift index eaa681f..dcb00d3 100644 --- a/GetHip/PartyServiceManager.swift +++ b/GetHip/PartyServiceManager.swift @@ -40,7 +40,7 @@ enum HostSignalType: String { -class PartyServiceManager: NSObject { +class PartyServiceManager: NSObject, AnyObject { let PartyServiceType = "GetHip-Party" var serviceAdvertiser: MCNearbyServiceAdvertiser! = nil @@ -56,6 +56,7 @@ class PartyServiceManager: NSObject { var currentHost: String! var connectedPeersDictionary = NSMutableDictionary() + var connecingPeersDictionary = NSMutableDictionary() var disconnectedPeersDictionary = NSMutableDictionary() //party-creator variables @@ -138,6 +139,37 @@ class PartyServiceManager: NSObject { println(self.currentSongTitle) self.currentSongIMG = UIImage(data: (dataDictionary["songImage"] as! NSData)) } + + if (instruction == "connect_to_other_peers"){ + for peer in dataDictionary["connectedPeers"] as! [MCPeerID] { + if((peer != self.myPeerID) && (peer != dataDictionary["sender"] as! MCPeerID) && (self.connectedPeersDictionary[peer.displayName] == nil)){ + + self.serviceBrowser.invitePeer(peer, toSession: self.session, withContext: nil, timeout: 10) + } + } + + for peer in dataDictionary["friendData"] as! [FriendData] { + println(peer) + } + } + + if (instruction == "are_you_ready"){ + var ready = true + for peer in dataDictionary["connectedPeers"] as! [MCPeerID] { + if (self.connectedPeersDictionary[peer.displayName] == nil) && (peer != self.myPeerID) { + ready = false + break + } + } + + if ready == true { + var dictionary: [String: String] = ["sender": self.myPeerID.displayName, "instruction": "ready"] + self.sendInstruction(dictionary, toPeer: fromPeer) + }else{ + self.session.disconnect() + } + } + return (instruction!, fromPeer) }else{ @@ -308,14 +340,20 @@ extension PartyServiceManager: MCSessionDelegate{ func session(session: MCSession!, peer peerID: MCPeerID!, didChangeState state: MCSessionState) { NSLog("%@", "peer \(peerID) didChangeState: \(state.stringValue())") if(state == MCSessionState.Connected){ + println(self.myPeerID.displayName + " connected to " + peerID.displayName) println("mark 1") + self.connectedPeersDictionary[peerID.displayName] = peerID self.delegate?.connectedWithPeer(peerID) } if(state == MCSessionState.NotConnected){ NSLog("%@", "peer \(peerID) didChangeState: \(state.stringValue())") + self.disconnectedPeersDictionary[peerID.displayName] = peerID + if self.connectedPeersDictionary[peerID.displayName] != nil{ + // self.connectedPeersDictionary[peerID.displayName] = nil + } } } diff --git a/GetHip/TestInviteFriendsController.swift b/GetHip/TestInviteFriendsController.swift index 9d2ec8b..87205eb 100644 --- a/GetHip/TestInviteFriendsController.swift +++ b/GetHip/TestInviteFriendsController.swift @@ -22,8 +22,8 @@ class TestInviteFriendsController: UIViewController, UITableViewDelegate, UITabl @IBAction func cancelInvites(sender: UIBarButtonItem) { //println("Browser service deinitialized and browser deinitialized") - self.partyData.stopBrowsing() - self.partyData.serviceBrowser = nil + //self.partyData.stopBrowsing() + //self.partyData.serviceBrowser = nil self.parentViewController?.dismissViewControllerAnimated(true, completion: nil) } @@ -73,7 +73,7 @@ class TestInviteFriendsController: UIViewController, UITableViewDelegate, UITabl for i in 0..