(connect! uri)
(connect! uri {:keys [on-connect on-close on-receive on-error subprotocols]})
implements the IWebSocket interface with supplied options: uri - a URI for establishing the web socket connection on-connect - an optional callback that will be invoked with the IWebSocket when a connection is established on-close - an optional callback that will be invoked with the IWebSocket and {:code {CODE} :reason {REASON}} when a connection is established on-receive - an optional callback that will be invoked with the IWebSocket and the payload when a message is received on-error - an optional callback that will be invoked with the IWebSocket and the error when an error occurs subprotocols - a seq of protocols (strings) to be sent with the handshake request
Example: (ws-client/connect! "ws://example.com/ws" {:on-connect (fn [ws] (ws-client/send! ws "a message")) :on-close (fn [ws event] (println event)) :on-receive (fn [ws msg] (if (= msg "PING") (ws-client/send! ws "PONG") (println msg))) :on-error (fn [ws error] (println error)) :subprotocols ["protocol-1" "protocol-2"]})
implements the IWebSocket interface with supplied options: uri - a URI for establishing the web socket connection on-connect - an optional callback that will be invoked with the IWebSocket when a connection is established on-close - an optional callback that will be invoked with the IWebSocket and {:code {CODE} :reason {REASON}} when a connection is established on-receive - an optional callback that will be invoked with the IWebSocket and the payload when a message is received on-error - an optional callback that will be invoked with the IWebSocket and the error when an error occurs subprotocols - a seq of protocols (strings) to be sent with the handshake request Example: (ws-client/connect! "ws://example.com/ws" {:on-connect (fn [ws] (ws-client/send! ws "a message")) :on-close (fn [ws event] (println event)) :on-receive (fn [ws msg] (if (= msg "PING") (ws-client/send! ws "PONG") (println msg))) :on-error (fn [ws error] (println error)) :subprotocols ["protocol-1" "protocol-2"]})
(close! this)
Closes the web socket connection
Closes the web socket connection
(connecting? this)
Indicates if the web socket in the process of trying to connect
Indicates if the web socket in the process of trying to connect
(open? this)
Indicates if the web socket connection is established and ready to send or receive messages
Indicates if the web socket connection is established and ready to send or receive messages
(send! this msg)
Sends the message across the web socket connection
Sends the message across the web socket connection
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close