Liking cljdoc? Tell your friends :D

bortexz.resocket


-Sendablecljprotocol

Implementation detail. Protocol for sending different message types.

Implementation detail. Protocol for sending different message types.

-sendclj

(-send data ws)
sourceraw docstring

connectionclj

(connection url)
(connection url
            {:keys [ping-interval ping-timeout ping-payload http-client
                    connect-timeout headers subprotocols input-buf output-buf
                    input-parser output-parser close-timeout ex-handler]
             :as opts})

creates a websocket connection given url and (optional) opts.

If successful, returns a map of:

  • ws wrapped jdk11 websocket.
  • input chan of received messages. Closed when the connection closes.
  • output chan to send messages, and close the connection (closing the chan). Closed when connection is closed.
  • closed promise-chan that will be delivered once the connection is closed with a map of:
    • close-type either #{:on-close :on-error :abort}. :abort is used when aborting connection through heartbeat-timeout or close-timeout elapsed (see opts below).
    • (when close-type :on-close) status and description
    • (when close-type :on-error) error

If an exception happens when opening a connection, returns a map of:

  • error the exception that was thrown

Available opts:

  • ping-interval milliseconds interval to send ping frames to the server. Defaults 30000 (30 secs).
  • ping-timeout if ellapsed milliseconds without receiving a pong, aborts the connection. Defaults 10000 (10 secs).
  • ping-payload ping frame byte-array. Defaults to empty byte-array.
  • http-client java.http.HttpClient instance to use, it will create a default one if not specified.
  • connect-timeout timeout in milliseconds to wait for establish a connection. Defaults to 30000 (30 secs)
  • headers map string->string with headers to use in http-client
  • subprotocols coll of string subprotocols to use
  • input-buf int/buffer to use on input chan. Unbuffered by default.
  • output-buf int/buffer to use on output chan. Unbuffered by default.
  • input-parser unary fn that will be called with complete messages received (either byte-array or string) and parses it before putting it into input chan. Defaults to identity.
  • output-parser unary fn that will be called with output messages before sending them through the websocket. Must return a String (for sending text) or a byte-array (for sending binary). Defaults to identity.
  • close-timeout (optional) millisecond to wait before aborting the connection after closing the output. Defaults to 10000 (10 secs).
  • ex-handler (optional) unary fn called with errors happening on internal calls to the jdk11 websocket. Defaults to use uncaught exception handler. Errors are wrapped in an ExceptionInfo that contains :val, :port and :error on its data.
creates a websocket connection given `url` and (optional) `opts`.

If successful, returns a map of:
- `ws` wrapped jdk11 websocket.
- `input` chan of received messages. Closed when the connection closes.
- `output` chan to send messages, and close the connection (closing the chan). Closed when connection is closed.
- `closed` promise-chan that will be delivered once the connection is closed with a map of:
  - `close-type` either `#{:on-close :on-error :abort}`. `:abort` is used when aborting connection through
    heartbeat-timeout or close-timeout elapsed (see `opts` below).
  - (when close-type :on-close) `status` and `description`
  - (when close-type :on-error) `error`

If an exception happens when opening a connection, returns a map of:
- `error` the exception that was thrown

Available opts:
- `ping-interval` milliseconds interval to send ping frames to the server. Defaults 30000 (30 secs).
- `ping-timeout` if ellapsed milliseconds without receiving a pong, aborts the connection. Defaults 10000 (10 secs).
- `ping-payload` ping frame byte-array. Defaults to empty byte-array.
- `http-client` java.http.HttpClient instance to use, it will create a default one if not specified.
- `connect-timeout` timeout in milliseconds to wait for establish a connection. Defaults to 30000 (30 secs)
- `headers` map string->string with headers to use in http-client
- `subprotocols` coll of string subprotocols to use
- `input-buf` int/buffer to use on input chan. Unbuffered by default.
- `output-buf` int/buffer to use on output chan. Unbuffered by default.
- `input-parser` unary fn that will be called with complete messages received (either byte-array or string) and 
  parses it before putting it into input chan. Defaults to identity.
- `output-parser` unary fn that will be called with output messages before sending them through the websocket. Must
  return a String (for sending text) or a byte-array (for sending binary). Defaults to identity.
- `close-timeout` (optional) millisecond to wait before aborting the connection after closing the output. Defaults to
  10000 (10 secs).
- `ex-handler` (optional) unary fn called with errors happening on internal calls to the jdk11 websocket. Defaults to
  use uncaught exception handler. Errors are wrapped in an ExceptionInfo that contains :val, :port and :error on its
  data.
sourceraw docstring

reconnectorclj

(reconnector {:keys [retry-ms-fn on-error-retry-fn? get-url get-opts]
              :or {retry-ms-fn (constantly 5000)
                   on-error-retry-fn?
                     (fn [err] (instance? ConnectException (ex-cause err)))
                   get-opts (constantly nil)}})

Creates a reconnector process that will create a new connection when the previous one has been closed. If creating a new connection fails, then function on-error-retry-fn? will be called with the error, and if it does not return true, the reconnector will be closed. If it returns true, then retry-ms-fn is called with the current attempt, and must return an integer or nil. If returns integer, reconnector will wait that amount of milliseconds to retry a new connection. If it returns nil, the reconnector will be closed.

Returns map of:

  • connections unbuffered chan of new connections. Will be closed when the reconnector is closed.
  • close promise-chan that will close the reconnector when delivered or closed. It will close currently active connection if there's one.

Available opts:

  • retry-ms-fn unary fn called with the current attempt at reconnecting, starting at 1. It must return a numer of milliseconds to wait before retrying a new connection, or nil to close the reconnector. Defaults to 5000 (5 secs).
  • on-error-retry-fn? unary fn called with error when creating a new connection. Must return true to start a retry timeout to retry, otherwise the reconnector will be closed. Note: It is called with the original Exception unwrapped, which will probably be an ExecutionException from the CompletableFuture returned by creating a new Websocket in JDK11. You might want to get the wrapped exception for more details (ex-cause <error>). Defaults to returning true when the wrapped exception is a java.net.ConnectException, false otherwise.
Creates a reconnector process that will create a new connection when the previous one has been closed. If creating
a new connection fails, then function `on-error-retry-fn?` will be called with the error, and if it does not return
true, the reconnector will be closed. If it returns true, then `retry-ms-fn` is called with the current attempt,
and must return an integer or nil. If returns integer, reconnector will wait that amount of milliseconds to retry a 
new connection. If it returns nil, the reconnector will be closed.

Returns map of:
- `connections` unbuffered chan of new connections. Will be closed when the reconnector is closed.
- `close` promise-chan that will close the reconnector when delivered or closed. It will close currently active 
  connection if there's one.

Available opts:
- `retry-ms-fn` unary fn called with the current attempt at reconnecting, starting at 1. It must return a numer of 
  milliseconds to wait before retrying a new connection, or nil to close the reconnector. Defaults to 5000 (5 secs).
- `on-error-retry-fn?` unary fn called with error when creating a new connection. Must return true to start a retry
  timeout to retry, otherwise the reconnector will be closed. Note: It is called with the original Exception unwrapped,
  which will probably be an ExecutionException from the CompletableFuture returned by creating a new Websocket in JDK11.
  You might want to get the wrapped exception for more details `(ex-cause <error>)`. Defaults to returning true 
  when the wrapped exception is a java.net.ConnectException, false otherwise.
sourceraw docstring

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

× close