Liking cljdoc? Tell your friends :D

hyperfiddle.electric-ring-adapter3

Provide a wrap-electric-websocket Ring middleware, starting and managing an Electric Server. This is a Ring 1.11+ compliant, generic implementation. It is compatible with ring-jetty out of the box, and can be extended to other servers. See hyperfiddle.electric-httpkit-adapter for an example of an extension.

Provide a `wrap-electric-websocket` Ring middleware, starting and managing an Electric Server.
This is a Ring 1.11+ compliant, generic implementation. It is compatible with
ring-jetty out of the box, and can be extended to other servers. See
`hyperfiddle.electric-httpkit-adapter` for an example of an extension.
raw docstring

ELECTRIC-CONNECTION-TIMEOUTclj

Time after which the server will close the socket if it hasn't seen any websocket activity from the client.

Time after which the server will close the socket if it hasn't seen any websocket activity from the client.
sourceraw docstring

ELECTRIC-HEARTBEAT-INTERVALclj

Delay between two server-send ping-emulating messages. Used to keep the connection up.

Delay between two server-send ping-emulating messages. Used to keep the connection up.
sourceraw docstring

electric-ws-handlerclj

(electric-ws-handler ring-req boot-fn)

Return a map of generic ring-compliant handlers, describing how to start and manage an Electric server process hooked onto a websocket. Extensions (e.g. hyperfiddle.electric-httpkit-adapter) can extend the handler map as needed.

Return a map of generic ring-compliant handlers, describing how to start and manage an Electric server process hooked onto a websocket.
Extensions (e.g. `hyperfiddle.electric-httpkit-adapter`) can extend the handler map as needed.
sourceraw docstring

failureclj

(failure socket e)

Called on reactor termination, connection timeout, or reactor crash. A connection timeout or reactor crash will close the socket.

Called on reactor termination, connection timeout, or reactor crash. A
connection timeout or reactor crash will close the socket. 
sourceraw docstring

GENERIC-WS-CLOSE-MESSAGESclj

https://www.rfc-editor.org/rfc/rfc6455.html#section-7.4.1
sourceraw docstring

handle-close-status-codecljmultimethod

Perform an action on socket close, dispatching on status code. List of status code and their meaning: https://www.rfc-editor.org/rfc/rfc6455.html#section-7.4.1

Perform an action on socket close, dispatching on status code. List of status
code and their meaning:
https://www.rfc-editor.org/rfc/rfc6455.html#section-7.4.1
sourceraw docstring

Pingablecljprotocol

pingclj

(ping this)
(ping this value)

pongclj

(pong this)
(pong this value)
source

reject-websocket-handlerclj

(reject-websocket-handler code reason)

Will accept socket connection upgrade and immediately close the socket on connection, with given code and reason. Use this to cleanly reject a websocket connection.

Will accept socket connection upgrade and immediately close the socket on
connection, with given `code` and `reason`. Use this to cleanly reject a
websocket connection.
sourceraw docstring

ring-ws-handlerclj

(ring-ws-handler ring-req boot-fn)

Return a Ring 1.11+ websocket listener starting and managing an Electric Server process.

Return a Ring 1.11+ websocket listener starting and managing an Electric Server process.
sourceraw docstring

send-hf-heartbeatclj

(send-hf-heartbeat delay ping!)
source

Socketcljprotocol

An abstraction over various Socket impl. E.g. Ring-websocket Socket or HTTPKit AsyncChannel

An abstraction over various Socket impl. E.g. Ring-websocket Socket or HTTPKit
AsyncChannel

closeclj

(close this code)
(close this code reason)

open?clj

(open? this)

sendclj

(send this value)
(send this value success-cb failure-cb)
sourceraw docstring

timeoutclj

(timeout mailbox time)

Throw if mailbox haven't got any message after given time ms

Throw if `mailbox` haven't got any message after given `time` ms
sourceraw docstring

wrap-electric-websocketclj

(wrap-electric-websocket next-handler entrypoint)

A ring middleware starting an Electric server program defined by electric-boot-fn on websocket connection. E.g.:

(-> ring-handler
    (wrap-electric-websocket (fn [ring-req] (e/boot-server {} my-ns/MyElectricDefn ring-req)))
    (wrap-cookies)
    (wrap-params)
    ...
  )
A ring middleware starting an Electric server program defined by `electric-boot-fn` on websocket connection.
E.g.:
```
(-> ring-handler
    (wrap-electric-websocket (fn [ring-req] (e/boot-server {} my-ns/MyElectricDefn ring-req)))
    (wrap-cookies)
    (wrap-params)
    ...
  )
```
sourceraw docstring

wrap-reject-stale-clientclj

(wrap-reject-stale-client next-handler config)
(wrap-reject-stale-client next-handler
                          {:keys [:hyperfiddle.electric/user-version]}
                          on-missmatch)

A Ring 1.11+ compatible middleware intercepting websocket UPGRADE request and checking if Electric client and Electric server versions matches. An Electric client is allowed to connect if:

  • its version matches the server's version,
  • the server does not have a defined version (dev mode). Otherwise, the websocket connection is gracefully rejected and the client is instructed to reload the page so to get new javascript assets.

The rejection action can be redefined by providing an on-mismatch callback argument taking:

  • ring upgrade request,
  • client-version,
  • server-version, and returning the ring handler to be applied.

e.g. With ring-jetty 1.11+

(wrap-reject-stale-client handler {:hyperfiddle.electric/user-version nil})     ; will accept any client
(wrap-reject-stale-client handler {:hyperfiddle.electric/user-version "12345"}) ; will only accept clients of version 12345

With http-kit, which is not fully ring 1.11+ compliant as of Jan 9 2024

(wrap-reject-stale-client handler {:hyperfiddle.electric/user-version "12345"}
  (fn on-mismatch [ring-request client-version server-version]
    (log/info 'wrap-reject-stale-client ": Electric client connection was rejected because client version doesn't match the server version. Client was instructed to perform a page reload so to get new javascript assets."
      {:client-version (pr-str client-version)
       :server-version (pr-str server-version)})
    (httpkit/as-channel ring-request ; this is HTTPkit specific
      (electric-httpkit/reject-websocket-handler 1008 "stale client") ; Websocket close code 1008 instructs the Electric client of the version mismatch
    )))
A Ring 1.11+ compatible middleware intercepting websocket UPGRADE request and
checking if Electric client and Electric server versions matches.
An Electric client is allowed to connect if:
- its version matches the server's version,
- the server does not have a defined version (dev mode).
Otherwise, the websocket connection is gracefully rejected and the client is
instructed to reload the page so to get new javascript assets.

The rejection action can be redefined by providing an `on-mismatch` callback
argument taking:
- ring upgrade request,
- client-version,
- server-version,
and returning the ring handler to be applied.

e.g.
With ring-jetty 1.11+
```
(wrap-reject-stale-client handler {:hyperfiddle.electric/user-version nil})     ; will accept any client
(wrap-reject-stale-client handler {:hyperfiddle.electric/user-version "12345"}) ; will only accept clients of version 12345
```

With http-kit, which is not fully ring 1.11+ compliant as of Jan 9 2024
```
(wrap-reject-stale-client handler {:hyperfiddle.electric/user-version "12345"}
  (fn on-mismatch [ring-request client-version server-version]
    (log/info 'wrap-reject-stale-client ": Electric client connection was rejected because client version doesn't match the server version. Client was instructed to perform a page reload so to get new javascript assets."
      {:client-version (pr-str client-version)
       :server-version (pr-str server-version)})
    (httpkit/as-channel ring-request ; this is HTTPkit specific
      (electric-httpkit/reject-websocket-handler 1008 "stale client") ; Websocket close code 1008 instructs the Electric client of the version mismatch
    )))
```
sourceraw docstring

write-msgclj

(write-msg socket message)

Return a task, writing a message on a websocket when run.

Return a task, writing a message on a websocket when run.
sourceraw docstring

write-msgsclj

(write-msgs socket msgs)

Returns a task writing all messages emitted by flow on websocket.

Returns a task writing all messages emitted by flow on websocket.
sourceraw docstring

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

× close