Liking cljdoc? Tell your friends :D
All platforms.

com.ben-allred.ws-client-cljc.client


connect!clj/s

(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"]})
sourceraw docstring

IWebSocketclj/sprotocol

close!clj/s

(close! this)

Closes the web socket connection

Closes the web socket connection

connecting?clj/s

(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?clj/s

(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!clj/s

(send! this msg)

Sends the message across the web socket connection

Sends the message across the web socket connection
source

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close