 import Foundation
 import WebKit
 
-public class SwiftR: NSObject, WKScriptMessageHandler {
+public class SwiftR {
+    public class func connect(url: String, readyHandler: (SignalR) -> ()) -> SignalR {
+        return SignalR(url: url, readyHandler: readyHandler)
+    }
+}
+
+public class SignalR: NSObject, WKScriptMessageHandler {
 
     var webView: WKWebView!
     var url: String!
     
-    var readyHandler: ((SwiftR) -> ())!
+    var readyHandler: ((SignalR) -> ())!
     var hubs = [String: Hub]()
     
-    public class func connect(url: String, readyHandler: (SwiftR) -> ()) -> SwiftR {
-        return SwiftR(url: url, readyHandler: readyHandler)
-    }
-    
-    init(url: String, readyHandler: (SwiftR) -> ()) {
+    init(url: String, readyHandler: (SignalR) -> ()) {
         super.init()
         
         self.url = url

        
        let params = ",".join(jsonParams)
        let js = "\(name).invoke('\(method)', \(params))"
        swiftR.webView.evaluateJavaScript(js, completionHandler: nil)
    }
    
    func ensureHub() {
        let js = "if (typeof \(name) == 'undefined') \(name) = connection.createHubProxy('\(name)')"
        swiftR.webView.evaluateJavaScript(js, completionHandler: nil)
    }
}


    }
    
    public func createHubProxy(name: String) -> Hub {
        let hub = Hub(name: name, signalR: self)
        hubs[name.lowercaseString] = hub
        return hub
    }
