mirror of
https://github.com/oonyeje/Get-Hip.git
synced 2025-12-25 03:37:40 +00:00
98 lines
2.8 KiB
Swift
98 lines
2.8 KiB
Swift
//
|
|
// JoiningPartyViewController.swift
|
|
// GetHip
|
|
//
|
|
// Created by Okechi on 3/2/16.
|
|
// Copyright (c) 2016 Kroleo. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import MultipeerConnectivity
|
|
|
|
class JoiningPartyViewController: UIViewController ,PartyServiceManagerDelegate{
|
|
var friends = []
|
|
var request = []
|
|
var user: [UserParseData]!
|
|
var party: PartyServiceManager!
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
// Do any additional setup after loading the view.
|
|
self.party.delegate = self
|
|
}
|
|
|
|
override func didReceiveMemoryWarning() {
|
|
super.didReceiveMemoryWarning()
|
|
// Dispose of any resources that can be recreated.
|
|
}
|
|
|
|
func setData(frnds:[FriendData], requst: [FriendData], party: PartyServiceManager, user: [UserParseData]){
|
|
self.friends = frnds
|
|
self.request = requst
|
|
self.party = party
|
|
self.user = user
|
|
}
|
|
|
|
|
|
// MARK: - Navigation
|
|
|
|
// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
|
// Get the new view controller using segue.destinationViewController.
|
|
// Pass the selected object to the new view controller.
|
|
|
|
if segue.identifier == "EnteringPartySegue"{
|
|
|
|
let vc: CurrentlyPlayingViewController = (segue.destinationViewController as? CurrentlyPlayingViewController)!
|
|
|
|
vc.setData(self.party, user: self.user, friends: self.friends as! [FriendData], request: self.request as! [FriendData])
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
extension JoiningPartyViewController: PartyServiceManagerDelegate {
|
|
|
|
func foundPeer() {
|
|
|
|
}
|
|
|
|
func lostPeer() {
|
|
|
|
}
|
|
|
|
func invitationWasRecieved(peerID: MCPeerID, invitationHandler: ((Bool, MCSession!) -> Void)!) {
|
|
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
func didRecieveInstruction(dictionary: Dictionary<String, AnyObject>){
|
|
let (instruction, fromPeer) = self.party.decodeInstruction(dictionary)
|
|
|
|
if (instruction == "disconnect") {
|
|
self.party.session.disconnect()
|
|
|
|
if let vc = self.parentViewController as? InvitedToPartyViewController{
|
|
vc.shouldEndInvite = true
|
|
}
|
|
|
|
self.dismissViewControllerAnimated(true, completion: nil)
|
|
}
|
|
|
|
if (instruction == "start_party"){
|
|
println("mark 4")
|
|
self.performSegueWithIdentifier("EnteringPartySegue", sender: self)
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|