SHARE
TWEET

Untitled

a guest Jul 17th, 2017 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (require '[reagent.core :as reagent])
  2. (require '[goog.object :as gobject])
  3.  
  4. (def socket (js/WebSocket. "wss://echo.websocket.org"))
  5.  
  6. (gobject/set socket "onopen" #(prn "Socket Open"))
  7. (gobject/set socket "onmessage" #(prn "New Message" (.-data %)))
  8.  
  9. (defn send-message [msg]
  10.   (.send socket msg))
  11.  
  12. (defn id->value [id]
  13.   (.-value (js/document.getElementById id)))
  14.  
  15. (defn websocket []
  16.   [:div
  17.    [:input {:type "text" :placeholder "Write your message"
  18.             :id "textinput"}]
  19.    [:button {:onClick #(send-message (id->value "textinput"))}
  20.       "Send"]])
  21.  
  22. (reagent/render [websocket] js/klipse-container)
RAW Paste Data
Top