             case "reconnected":
                 state = .Connected
                 reconnected?()
+            case "invokeHandler":
+                let hubName = json["hub"] as! String
+                if let hub = hubs[hubName] {
+                    let uuid = json["id"] as! String
+                    let result = json["result"]
+                    let error = json["error"] as? String
+                    if let callback = hub.invokeHandlers[uuid] {
+                        callback(result, error)
+                        hub.invokeHandlers.removeValueForKey(uuid)
+                    }
+                }
             case "error":
                 if let err: AnyObject = json["error"] {
                     error?(err["context"])

        connection.runJavaScript("addHandler('\(name)', '\(method)', \(p))")
    }
    
    public func invoke(method: String, arguments: [AnyObject]?) {
        var jsonArguments = [String]()
        
        if let args = arguments {

public class Hub {
    let name: String
    var handlers: [String: AnyObject? -> ()] = [:]
    var invokeHandlers: [String: (AnyObject?, String?) -> ()] = [:]
    
    public let connection: SignalR!
    
