Last active
July 18, 2017 09:08
-
-
Save ioRekz/177635ea3fad94f0ada2e470d71cfbc6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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