      - parameter socket: <#socket description#>
      - parameter data:   <#data description#>
      */
-    public func websocketDidReceiveData(socket: WebSocket, data: NSData) {
+    internal func websocketDidReceiveData(socket: WebSocket, data: NSData) {
         // print("socket received data")
         Log.sharedLogger.warning("Websocket received binary data")
     }

        audioUploadQueue.name = "Audio upload"
        audioUploadQueue.maxConcurrentOperationCount = 1
        
        audioUploadQueue.suspended = true
        
    }
    
    /**
     <#Description#>
     
     - parameter data: data description
     */
    public func send(data: NSData) {
        
        connectWebsocket()
        

    }
    
    /**
     Fetches a token that is valid for 1 hr.
     
     - parameter username:     Watson generated username
     - parameter password:     Watson generated password
     - parameter oncompletion: completion block for when a token is sent by server
     */
    internal func getToken( username: String, password: String,
        oncompletion: (String?, NSError?) -> Void)
    {
        let authorizationString = username + ":" + password
        let apiKey = "Basic " + (authorizationString.dataUsingEncoding(NSASCIIStringEncoding)?.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.Encoding76CharacterLineLength))!
        
        NetworkUtils.requestAuthToken(tokenURL, serviceURL: serviceURLFull,
            apiKey: apiKey, completionHandler: {
            
            token, error in
            
            Log.sharedLogger.info("Token received was \(token)")
                
            self.token = token
                
            oncompletion(token, error)
        })
        
    }
    
    /**
     Establishes a Websocket connection if one does not exist already.
     */
    internal func connectWebsocket() {
        
        // check to see if a connection has been established.
//        if let socket = socket {
//            
//            if socket.isConnected {
//                return
//            }
//        }
        
        if (username == nil || password == nil)
        {
            Log.sharedLogger.error("API key was not set")
            return
        }
        
        getToken(username!, password: password!, oncompletion: {
            token, error in
            
            Log.sharedLogger.info("Got a response back from the server")
            
            if let token = token {
                
                //let authURL = "\(self.url)?watson-token=\(token)"
                let authURL = self.url
                self.socket = WebSocket(url: NSURL(string: authURL)!)
                
                if let socket = self.socket {
                    
                    socket.delegate = self
                    
                    socket.headers["X-Watson-Authorization-Token"] = token
                    
                    socket.connect()
                    
                } else {
                    Log.sharedLogger.error("Socket could not be created")
                }
                
            }

            
        })
    }
}



// MARK: - <#WebSocketDelegate#>
extension WatsonSocket : WebSocketDelegate {
