   clojure.browser.net
   (:require [clojure.browser.event :as event]
             [goog.json :as gjson])
-  (:import (goog.net XhrIo EventType)
-           (goog.net.xpc CfgFields CrossPageChannel)
-           goog.Uri))
+  (:import [goog.net XhrIo EventType WebSocket]
+           [goog.net.xpc CfgFields CrossPageChannel]
+           [goog Uri]))
 
 (def *timeout* 10000)
 

  IConnection
  (connect
    ([this url]
       (connect this url nil))
    ([this url protocol]
       (.open this url protocol)))

  (transmit [this message]
    (.send this message))

  (close [this]
    (.close this ()))

  event/IEventType
  (event-types [this]
    (into {}
      (map
        (fn [[k v]]
          [(keyword (. k (toLowerCase)))
           v])
        (merge
          (js->clj WebSocket.EventType))))))

(defn websocket-connection
  ([]
     (websocket-connection nil nil))
  ([auto-reconnect?]
     (websocket-connection auto-reconnect? nil))
  ([auto-reconnect? next-reconnect-fn]
     (WebSocket. auto-reconnect? next-reconnect-fn)))
