An open API service indexing awesome lists of open source software.

https://github.com/40ants/reblocks-websocket

Websocket support for Reblocks framework
https://github.com/40ants/reblocks-websocket

common-lisp reblocks webframework websocket

Last synced: 5 months ago
JSON representation

Websocket support for Reblocks framework

Awesome Lists containing this project

README

          

# reblocks-websocket - Reblocks extension adding a bidirectional communication via Websocket.

## REBLOCKS-WEBSOCKET ASDF System Details

* Description: Reblocks extension allowing to add a bidirectional communication via Websocket between a backend and Reblocks widgets.
* Licence: Unlicense
* Author: Alexander Artemenko
* Homepage: [https://40ants.com/reblocks-websocket/][6f15]
* Bug tracker: [https://github.com/40ants/reblocks-websocket/issues][e6f2]
* Source control: [GIT][b1a1]
* Depends on: [alexandria][8236], [bordeaux-threads][3dbf], [jonathan][6dd8], [log4cl-extras][691c], [parenscript][7921], [reblocks][184b], [reblocks-parenscript][c07c], [serapeum][c41d], [websocket-driver][4f50]

[![](https://github-actions.40ants.com/40ants/reblocks-websocket/matrix.svg?only=ci.run-tests)][0497]

![](http://quickdocs.org/badge/reblocks-websocket.svg)

This module allows you to push some information from backend to frontend
and. In this case, updates of widgets's state on the client are
initiated by server. For example, you can have some sort of long running
process on the server and need to show it's status to the user.

## Installation

This library depends on Reblocks (Weblocks fork) and a websocket-driver.
If you will use Woo server then probably you'll need this fork of the websocket-driver
([make-woo-work-from-separate-threads][ef5d] branch).
However, may be the recent version of websocket-driver will work just find, I don't know.

You can install this library from Quicklisp, but you want to receive updates quickly, then install it from Ultralisp.org:

```
(ql-dist:install-dist "http://dist.ultralisp.org/"
:prompt nil)
(ql:quickload :reblocks-websocket)
```

## Usage

Define you widget and inherit it from the
[`reblocks-websocket:websocket-widget`][c36a]:

```lisp
(reblocks:defwidget counter-box (reblocks-websocket:websocket-widget)
((counter :initform 0
:accessor counter)))
```
Define a code which will start some sort of background activity. In this
example we are doing it right when widget was created in the beginning
of the user session, but of cause, you can do it as a reaction on an
action.

```lisp
(defmethod initialize-instance ((instance counter-box) &rest restargs)
(declare (ignorable restargs))
(call-next-method)

(reblocks-websocket:in-thread ("Update counter")
(sleep 3)
;; Updating counter
(incf (counter instance))
(reblocks:update instance)))
```
That is it. Define a render method as usual and use the widget on the
page. Counter will be updated automatically. This works like a magic,
a framework makes all dirty work under the hood.

## API

### REBLOCKS-WEBSOCKET

#### [package](26e8) `reblocks-websocket`

#### Classes

##### NO-ACTIVE-WEBSOCKETS

###### [condition](5a04) `reblocks-websocket:no-active-websockets` (error)

##### WEBSOCKET-WIDGET

###### [class](a3c9) `reblocks-websocket:websocket-widget` (widget)

#### Functions

##### [function](b8ed) `reblocks-websocket:send-command` method-name &rest args

##### [function](f9a4) `reblocks-websocket:send-script` script

Sends `JS` script to frontend via Websocket.

#### Macros

##### [macro](bc0e) `reblocks-websocket:in-thread` (thread-name) &body body

Starts given piece of code in named thread, ensiring that reblocks/session::*session* and
reblocks/request:*request* will be bound during it's execution.

Also, it set reblocks.websocket:*backround* to true, to make `update' method distinguish
between usual request processing and background activity.

#### Variables

##### [variable](2ac2) `reblocks-websocket:*background*` nil

This variable becomes t during background processing.

[6f15]: https://40ants.com/reblocks-websocket/
[c36a]: https://40ants.com/reblocks-websocket/#x-28REBLOCKS-WEBSOCKET-3AWEBSOCKET-WIDGET-20CLASS-29
[b1a1]: https://github.com/40ants/reblocks-websocket
[0497]: https://github.com/40ants/reblocks-websocket/actions
[26e8]: https://github.com/40ants/reblocks-websocket/blob/bde773ad242d5e131780245efa480ec1a5425a6e/src/websocket.lisp#L1
[a3c9]: https://github.com/40ants/reblocks-websocket/blob/bde773ad242d5e131780245efa480ec1a5425a6e/src/websocket.lisp#L227
[2ac2]: https://github.com/40ants/reblocks-websocket/blob/bde773ad242d5e131780245efa480ec1a5425a6e/src/websocket.lisp#L388
[5a04]: https://github.com/40ants/reblocks-websocket/blob/bde773ad242d5e131780245efa480ec1a5425a6e/src/websocket.lisp#L392
[f9a4]: https://github.com/40ants/reblocks-websocket/blob/bde773ad242d5e131780245efa480ec1a5425a6e/src/websocket.lisp#L427
[b8ed]: https://github.com/40ants/reblocks-websocket/blob/bde773ad242d5e131780245efa480ec1a5425a6e/src/websocket.lisp#L447
[bc0e]: https://github.com/40ants/reblocks-websocket/blob/bde773ad242d5e131780245efa480ec1a5425a6e/src/websocket.lisp#L525
[e6f2]: https://github.com/40ants/reblocks-websocket/issues
[ef5d]: https://github.com/svetlyak40wt/websocket-driver/tree/make-woo-work-from-separate-threads
[8236]: https://quickdocs.org/alexandria
[3dbf]: https://quickdocs.org/bordeaux-threads
[6dd8]: https://quickdocs.org/jonathan
[691c]: https://quickdocs.org/log4cl-extras
[7921]: https://quickdocs.org/parenscript
[184b]: https://quickdocs.org/reblocks
[c07c]: https://quickdocs.org/reblocks-parenscript
[c41d]: https://quickdocs.org/serapeum
[4f50]: https://quickdocs.org/websocket-driver

* * *
###### [generated by [40ANTS-DOC](https://40ants.com/doc/)]