streaming working; will work on repeating the song selection cycle so party can continue. Will complete that as well as any residual work in rest of views and displaying who is in current party

This commit is contained in:
Okechi 2016-03-07 21:12:53 -05:00
parent 2d0ee54191
commit 0c4881f5cb
32 changed files with 313 additions and 55 deletions

View File

@ -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 = "<group>"; };
3E4169541C398A5B00B193AF /* SignUpViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignUpViewController.swift; sourceTree = "<group>"; };
3E4169561C399C4D00B193AF /* Images-3.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Images-3.xcassets"; sourceTree = "<group>"; };
3E41D74B1C8D17E100FFD846 /* icon-120.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon-120.png"; sourceTree = "<group>"; };
3E41D74D1C8D17F300FFD846 /* Icon-60.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Icon-60.png"; sourceTree = "<group>"; };
3E438ADD1C572DFD0055C97A /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
@ -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 */,

View File

@ -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
}
}

View File

@ -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..<self.friendData.count{
self.partyData.isInvitable.append(false)
}
self.firstTimeBrowsing = false
}
for foundPeer in self.partyData.foundPeers {
for friend in self.friendData {
if foundPeer.displayName == friend.displayName {

BIN
GetHip/Icon-60.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -69,54 +69,62 @@
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Icon-Spotlight-40.png",
"filename" : "Icon-40.png",
"scale" : "1x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Icon-Spotlight-40@2x-1.png",
"filename" : "Icon-40@2x-1.png",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "50x50",
"idiom" : "ipad",
"filename" : "Icon-Small-50.png",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "50x50",
"idiom" : "ipad",
"filename" : "Icon-Small-50@2x.png",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "72x72",
"idiom" : "ipad",
"filename" : "Icon-72.png",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "72x72",
"idiom" : "ipad",
"filename" : "Icon-72@2x.png",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Icon-76.png",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Icon-76@2x.png",
"scale" : "2x"
},
{
"idiom" : "car",
"size" : "120x120",
"idiom" : "car",
"filename" : "Icon-Spotlight-40@3x-1.png",
"scale" : "1x"
},
{
"size" : "24x24",
"idiom" : "watch",
"scale" : "2x",
"filename" : "Icon-24@2x.png",
"role" : "notificationCenter",
"subtype" : "38mm"
},
@ -124,18 +132,21 @@
"size" : "27.5x27.5",
"idiom" : "watch",
"scale" : "2x",
"filename" : "Icon-27.5@2x.png",
"role" : "notificationCenter",
"subtype" : "42mm"
},
{
"size" : "29x29",
"idiom" : "watch",
"filename" : "Icon-29@2x.png",
"role" : "companionSettings",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "watch",
"filename" : "Icon-29@3x.png",
"role" : "companionSettings",
"scale" : "3x"
},
@ -143,6 +154,7 @@
"size" : "40x40",
"idiom" : "watch",
"scale" : "2x",
"filename" : "Icon-40@2x.png",
"role" : "appLauncher",
"subtype" : "38mm"
},
@ -150,6 +162,7 @@
"size" : "44x44",
"idiom" : "watch",
"scale" : "2x",
"filename" : "Icon-44@2x.png",
"role" : "longLook",
"subtype" : "42mm"
},
@ -157,6 +170,7 @@
"size" : "86x86",
"idiom" : "watch",
"scale" : "2x",
"filename" : "Icon-86@2x.png",
"role" : "quickLook",
"subtype" : "38mm"
},
@ -164,6 +178,7 @@
"size" : "98x98",
"idiom" : "watch",
"scale" : "2x",
"filename" : "Icon-98@2x.png",
"role" : "quickLook",
"subtype" : "42mm"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

@ -49,19 +49,26 @@ class InPartyViewController: UIViewController, UICollectionViewDataSource, UICol
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> 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

View File

@ -6,6 +6,11 @@
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIconFiles</key>
<array>
<string>Icon-60.png</string>
<string>icon-120.png</string>
</array>
<key>CFBundleIdentifier</key>
<string>com.Kroleo.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
@ -30,7 +35,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<string>2</string>
<key>FacebookAppID</key>
<string>1166375230058840</string>
<key>FacebookDisplayName</key>

View File

@ -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)
}

View File

@ -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<String,String> = ["sender": self.party.myPeerID.displayName, "instruction": "joined_party"]
self.party.sendInstruction(dictionary, toPeer: peerID)
if(self.isHostConnected == false){
var dictionary: Dictionary<String,AnyObject> = Dictionary<String,AnyObject>()
dictionary["sender"] = self.party.myPeerID.displayName
dictionary["instruction"] = "joined_party"
self.party.sendInstruction(dictionary, toPeer: peerID)
self.isHostConnected = true
}
}
func didRecieveInstruction(dictionary: Dictionary<String, AnyObject>){
@ -86,6 +102,8 @@ extension JoiningPartyViewController: PartyServiceManagerDelegate {
self.dismissViewControllerAnimated(true, completion: nil)
}
if (instruction == "start_party"){
println("mark 4")
self.performSegueWithIdentifier("EnteringPartySegue", sender: self)

View File

@ -23,8 +23,10 @@ class LoadingPartyViewController: UIViewController, UICollectionViewDataSource,
@IBOutlet var invitedFriends: UICollectionView!
@IBOutlet var songLabel: UILabel!
@IBOutlet var timerLabel: UILabel!
var arePeersReady = Dictionary<String, Bool>()
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,6 +228,18 @@ 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
@ -262,6 +374,12 @@ extension LoadingPartyViewController: PartyServiceManagerDelegate {
}
if(instruction == "ready"){
self.arePeersReady[fromPeer.displayName] = true
}
println(instruction)
}

View File

@ -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
}
}
}

View File

@ -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..<self.frnds.count{
self.isFriendSelected.append(false)
self.partyData.isInvitable.append(false)
//self.partyData.isInvitable.append(false)
}
}

BIN
GetHip/icon-120.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB