Websocket support for Common Lisp framework weblocks.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
src
t
.gitignore
.travis.yml
ChangeLog.rst
README.rst
TODO.org
tasks.py
version.lisp-expr
weblocks-websocket-test.asd
weblocks-websocket.asd

README.rst

weblocks-websocket

https://travis-ci.org/40ants/weblocks-websocket.svg?branch=master

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 Weblocks (replocks branch) Woo server and websocket-driver ([make-woo-work-from-separate-threads](https://github.com/svetlyak40wt/websocket-driver/tree/make-woo-work-from-separate-threads) branch).

Usage

Define you widget and inherit it from the weblocks.websocket:websocket-widget:

(websocket:defwidget counter-box (weblocks.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.

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

  (weblocks.websocket:in-thread ("Update counter")
    (sleep 3)
    ;; Updating counter
    (incf (counter instance))
    (weblocks:mark-dirty 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.

TODO

  • Make a client-side code to reconnect when connection was broken.
  • Add some queue on the backend to store data during reconnects.