         fromPeer peerID: MCPeerID, withProgress progress: NSProgress) {
             
     }
+}
+
+extension MCSessionState {
+    func stringValue() -> String {
+        switch(self) {
+        case .NotConnected: return "NotConnected"
+        case .Connecting: return "Connecting"
+        case .Connected: return "Connected"
+        }
+    }
 }
    // Handles MCSessionState changes: NotConnected, Connecting and Connected.
    public func session(session: MCSession, peer peerID: MCPeerID,
        didChangeState state: MCSessionState) {
            delegate?.connectedPeersChanged(session.connectedPeers.map{$0.displayName})
    }
    
    // Handles incomming NSData
    public func session(session: MCSession, didReceiveData data: NSData,
        fromPeer peerID: MCPeerID) {
            
    }
    
    // Handles incoming NSInputStream

        stopPeerSearch()
    }
    
    // MARK: Methods for host
    public func startAdversitingHost() {
        if serviceAdvertiser == nil {
            serviceAdvertiser = MCNearbyServiceAdvertiser(peer: myPeerId,
                discoveryInfo: ["peerType": "host"], serviceType: serviceType)
            serviceAdvertiser?.delegate = self
        }
        serviceAdvertiser?.startAdvertisingPeer()
    }
    
    public func stopAdvertisingHost() {
        if let advertiser = serviceAdvertiser {
            advertiser.stopAdvertisingPeer()
        }
    }
    
    // MARK: Methods for guest
    public func startSearchingForHosts() {
        if serviceBrowser == nil {
            serviceBrowser = MCNearbyServiceBrowser(peer: myPeerId, serviceType: serviceType)
            serviceBrowser?.delegate = self
        }
        foundHosts = []
        serviceBrowser?.startBrowsingForPeers()
    }
    
    public func stopSearchingForHosts() {
        if let browser = serviceBrowser {
            browser.stopBrowsingForPeers()
        }
    }
    
    public func connectToHost(host: MCPeerID, context: NSData? = nil, timeout: NSTimeInterval = defaultTimeout) {
        guard foundHosts.contains(host) else {
            return
        }
        
        guard let browser = serviceBrowser else {
            return
        }
        
        browser.invitePeer(host, toSession: session, withContext: context, timeout: timeout)
    }
    
    public func getFoundHosts() -> [MCPeerID] {
        return foundHosts
    }
    
    // MARK: Methods for session
    public func getConnectedPeers() -> [MCPeerID] {
        return session.connectedPeers
    }
    
    // When deliberately disconnect
    // Disconnect from current session, browse for another host
    public func disconnect() {
        session.disconnect()
        NSLog("%@", "disconnected from \(session.hashValue)")
        startSearchingForHosts()
    }
    
    // This method is async
    public func sendData(data: NSData, mode: MCSessionSendDataMode) -> Bool {
        do {
            NSLog("%@", "send data to host: \(data)")
            try session.sendData(data, toPeers: session.connectedPeers, withMode: mode)
        } catch {
            NSLog("%@", "send data failed: \(data)")
            return false
        }
        
        return true
    }
}

extension SplooshSearch: MCNearbyServiceAdvertiserDelegate {
    // Invitation is received from guest
    public func advertiser(advertiser: MCNearbyServiceAdvertiser,
        didReceiveInvitationFromPeer peerID: MCPeerID,
        withContext context: NSData?, invitationHandler: (Bool, MCSession) -> Void) {
            NSLog("%@", "didReceiveInvitationFromPeer \(peerID)")
            
            let acceptGuest = {
                (accepted: Bool) -> Void in
                invitationHandler(accepted, self.session)
            }
            
            if autoAcceptGuests {
                acceptGuest(true)
            } else {
                delegate?.invitationToConnectReceived(peerID, handleInvitation: acceptGuest)
            }
    }
}
