diff --git a/GetHip/CurrentlyPlayingViewController.swift b/GetHip/CurrentlyPlayingViewController.swift index cd74d23..1af304f 100644 --- a/GetHip/CurrentlyPlayingViewController.swift +++ b/GetHip/CurrentlyPlayingViewController.swift @@ -23,6 +23,7 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg var nextHost: String! var messageOutputStream: Dictionary! var messageInputStream: Dictionary! + var firstPass = true @IBOutlet var segmentControl: UISegmentedControl! //class variable for responding to peer who has just sent a message @@ -149,6 +150,7 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg override func viewDidLoad() { + super.viewDidLoad() @@ -247,9 +249,16 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg override func viewDidAppear(animated: Bool) { //make this part check which view to display later + if(self.firstPass){ + self.firstPass = !self.firstPass + }else{ + viewDidLoad() + } + } func songDidEnd(notification: NSNotification){ + if(self.party.role == PeerType.Host_Creator){ self.party.role == PeerType.Host_Invited }else if (self.party.role == PeerType.Guest_Creator){ @@ -258,6 +267,8 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg var didAnyoneBecomeHost: Bool = false for peer in self.party.connectedPeers() as! [MCPeerID]{ + self.party.outputStreamers[peer.displayName]?.stop() + if ((self.party.currentHost != nil) && (peer.displayName == self.party.currentHost)){ var dictionary: [String: AnyObject] = ["sender": self.party.myPeerID, "instruction": "start_picking_a_song"] self.party.sendInstruction(dictionary, toPeer: peer) @@ -269,9 +280,9 @@ class CurrentlyPlayingViewController: UIViewController, PartyServiceManagerDeleg } if(didAnyoneBecomeHost){ - self.performSegueWithIdentifier("NextSongSelectionSegue", sender: self) - }else{ self.performSegueWithIdentifier("NextUpSegue", sender: self) + }else{ + self.performSegueWithIdentifier("NextSongSelectionSegue", sender: self) } } @@ -379,8 +390,8 @@ extension CurrentlyPlayingViewController { if(indexPath.row == 0){ cell.friendImage.image = self.usr[0].profileImg.image! } - else if((indexPath.row > 0) && (indexPath.row < self.party.invitedFriends.count)){ - let friend = self.party.invitedFriends[indexPath.row] + else if((indexPath.row > 0) && (indexPath.row <= self.party.invitedFriends.count)){ + let friend = self.party.invitedFriends[indexPath.row - 1] if friend.profileImg == nil { cell.friendImage.backgroundColor = UIColor.lightGrayColor() } @@ -466,6 +477,7 @@ extension CurrentlyPlayingViewController: PartyServiceManagerDelegate { self.party.inputStreamer.resume() }else if(instruction == "want_to_be_host"){ + self.curr_fromPeer = fromPeer let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT dispatch_async(dispatch_get_global_queue(priority, 0)) { @@ -497,6 +509,7 @@ extension CurrentlyPlayingViewController: PartyServiceManagerDelegate { }else{ let alert = UIAlertView() + alert.delegate = self alert.title = "Hosting Rrequest" alert.message = "Would you like to be the next host for the party and pick a song?" diff --git a/GetHip/LoadingPartyViewController.swift b/GetHip/LoadingPartyViewController.swift index e67c250..5aed43a 100644 --- a/GetHip/LoadingPartyViewController.swift +++ b/GetHip/LoadingPartyViewController.swift @@ -192,7 +192,12 @@ class LoadingPartyViewController: UIViewController, UICollectionViewDataSource, cell.friendImage.clipsToBounds = true if(self.party.connectedPeersDictionary[friend.displayName] == nil){ - cell.alpha = 0.5 + dispatch_async(dispatch_get_main_queue()){ + cell.alpha = 0.5 + } + + + } diff --git a/GetHip/NextUpViewController.swift b/GetHip/NextUpViewController.swift index ba85cf8..69ba3d6 100644 --- a/GetHip/NextUpViewController.swift +++ b/GetHip/NextUpViewController.swift @@ -80,7 +80,7 @@ extension NextUpViewController: PartyServiceManagerDelegate { var dictionary: [String: String] = ["sender": self.party.myPeerID.displayName, "instruction": "disconnect"] self.party.sendInstruction(dictionary, toPeer: fromPeer) }else{ - if (instruction == "start"){ + if (instruction == "start_party"){ self.performSegueWithIdentifier("NextSongSegue", sender: self) } } diff --git a/GetHip/PartyServiceManager.swift b/GetHip/PartyServiceManager.swift index 2c3a0e1..9323898 100644 --- a/GetHip/PartyServiceManager.swift +++ b/GetHip/PartyServiceManager.swift @@ -184,7 +184,7 @@ class PartyServiceManager: NSObject, AnyObject { if(instruction == "does_accept"){ - self.currentHost == fromPeer.displayName + self.currentHost = fromPeer.displayName } @@ -395,7 +395,7 @@ extension PartyServiceManager: MCSessionDelegate{ NSLog("%@", "peer \(peerID) didChangeState: \(state.stringValue())") self.disconnectedPeersDictionary[peerID.displayName] = peerID if self.connectedPeersDictionary[peerID.displayName] != nil{ - // self.connectedPeersDictionary[peerID.displayName] = nil + self.connectedPeersDictionary[peerID.displayName] = MCPeerID(displayName: "@nil") } } } diff --git a/GetHip/SongSelectionViewController.swift b/GetHip/SongSelectionViewController.swift index 95ad9b3..521afc0 100644 --- a/GetHip/SongSelectionViewController.swift +++ b/GetHip/SongSelectionViewController.swift @@ -282,7 +282,7 @@ class SongSelectionViewController: UIViewController, UITableViewDelegate, UITabl for i_peer in self.party.invitedFriends{ for peer in self.party.foundPeers { - if (peer.displayName == i_peer.displayName && self.party.myPeerID.hash > peer.hash){ + if (peer.displayName == i_peer.displayName /*&& self.party.myPeerID.hash > peer.hash*/ && (self.party.connectedPeersDictionary[peer.displayName] == nil || self.party.connectedPeersDictionary[peer.displayName]!.displayName == "@nil" )){ self.party.serviceBrowser.invitePeer(peer, toSession: self.party.session, withContext: nil, timeout: 30.0) break