   }
 
   internal func websocketDidDisconnect(socket: WebSocket, error: NSError?) {
-    if(error == nil){
+    if error == nil {
       self.delegate?.didDisconnect(NSError(error: .LostConnection))
-    }else{
+    } else {
       self.delegate?.didFailConnection(error)
     }
   }

    self.urlString = url
  }

  func openConnection(){
    self.closeConnection()
    self.webSocket = WebSocket(url: NSURL(string:self.urlString!)!)
    self.webSocket!.delegate = self;
    self.webSocket!.connect()
  }

  func closeConnection(){
    if(self.webSocket != nil){
      self.webSocket!.delegate = nil
      self.webSocket!.disconnect()
      self.webSocket = nil;
    }
  }

  func writeString(aString:String){
    self.webSocket?.writeString(aString)
  }

  func isConnected() -> (Bool){
    return self.webSocket!.isConnected
  }


  // "clientId": "Un1q31d3nt1f13r",
  // "subscription": "/foo/**"
  // }
  func unsubscribe(channel:String) {
    if let clientId = self.fayeClientId {
      let dict:[String:AnyObject] = ["channel": BayeuxChannel.UNSUBSCRIBE_CHANNEL.rawValue, "clientId": clientId, "subscription": channel]
      if let string = JSON(dict).rawString() {
        self.transport?.writeString(string)
      }
