Skip to content

Instantly share code, notes, and snippets.

@ioRekz
Last active July 18, 2017 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ioRekz/177635ea3fad94f0ada2e470d71cfbc6 to your computer and use it in GitHub Desktop.
Save ioRekz/177635ea3fad94f0ada2e470d71cfbc6 to your computer and use it in GitHub Desktop.
(require '[reagent.core :as reagent])
(require '[goog.object :as gobject])
(def socket (js/WebSocket. "wss://echo.websocket.org"))
(gobject/set socket "onopen" #(prn "Socket Open"))
(gobject/set socket "onmessage" #(prn "New Message Received" (.-data %)))
(defn send-message [msg]
(.send socket msg))
(defn id->value [id]
(.-value (js/document.getElementById id)))
(defn websocket []
[:div
[:input {:type "text" :placeholder "Write your message"
:id "textinput"}]
[:button {:onClick #(send-message (id->value "textinput"))}
"Send"]])
(reagent/render [websocket] js/klipse-container)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment