 import AVFoundation
 import MediaPlayer
 import SocketIO
+
 class ViewController: UIViewController {
     
     @IBOutlet weak var toolbar: UIToolbar!

    
    let socket = SocketIOClient(socketURL: "http://api.overrustle.com", options: ["nsp": "/streams"])
    
    
    @IBAction func strimsPressed(sender: AnyObject) {
        
        
        let rustleActionSheet = UIActionSheet(title: "Select Strim", delegate: nil, cancelButtonTitle: "Cancel", destructiveButtonTitle: nil)
        rustleActionSheet.actionSheetStyle = UIActionSheetStyle.BlackTranslucent
        
        var i : Int
        for i = 0; i<7; i++ {
            var button = UIButton()
            button.addTarget(self, action: "selected:", forControlEvents: UIControlEvents.TouchDown)
            var frame = CGRectMake(0, CGFloat(i*40 + 10), 160, 40)
            button.frame = frame
            button.tag = i
            button.setTitle("Button \(i)", forState: UIControlState.Normal)
            println("Making button \(i)")
            rustleActionSheet.addButtonWithTitle("two")
            
            rustleActionSheet.addSubview(button)
        }
        
        

        rustleActionSheet.bounds = CGRectMake(0, 0, 320, 485)
        rustleActionSheet.showInView(self.view)

    func addHandlers() {
        // Our socket handlers go here
        
        self.socket.onAny {
            println("Got event: \($0.event)")
//            println("with items: \($0.items)")
        }
        self.socket.on("strims") { data, ack in
            println("in strims")
            
            if let new_api_data = data?[0] as? NSDictionary {
                self.api_data = new_api_data
                if let viewers = self.api_data["viewercount"] as? Int {
                    println("Rustlers:", viewers)
                }
                if let stream_list = self.api_data["stream_list"] as? NSArray {
                    println("Stream List", stream_list)
                }
            }
//                // println("Got data: \(data), with ack: \(ack)")
//            }
        }
    }
    
    
