Skip to content

ediethelm/weblocks-websocket

 
 

Repository files navigation

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: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.

TODO

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

About

Websocket support for Common Lisp framework weblocks.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Common Lisp 92.4%
  • Python 7.6%