[Libwebsockets] generic sessions and sample app live

Andy Green andy at warmcat.com
Fri Jun 17 15:17:46 CEST 2016


Hi -

It seems to have taken a while but generic-sessions is actually usable 
for real things now.

Here is a demo app of a (very) simple messageboard, with gravatar support.

https://libwebsockets.org/lwsgs

It's interesting because there is no server-side scripting that you 
would expect, there is only a simple ws protocol + POST handler

https://github.com/warmcat/libwebsockets/blob/master/plugins/generic-sessions/protocol_lws_messageboard.c

It's < 400 lines and concerned with accepting messages by POST and 
putting them in a sqlite database, and distributing message updates over 
ws using JSON.

JS on the client side is used as glue to convert JSON-over-ws to HTML 
DOM objects in realtime.

The messageboard plugin uses sessions / login / auth / registration / 
forgot password / delete account from generic-sessions by basically 
subclassing it, any callback / urls he doesn't recognize call through to 
the generic-sessions callback to be handled.  Apart from checking the 
http cookie credentials when opening a ws link, actually the protocol 
using generic-sessions doesn't have to get involved with anything.

The integration of generic-sessions to the html is also very low impact. 
  The html should include lwsgs.js in its head section and provide a div 
with id="lwsgs" to contain the generic UI.  Then it only needs to call 
lwsgs_initial(); when its page loads.

https://github.com/warmcat/libwebsockets/blob/master/plugins/generic-sessions/index.html

generic-sessions also takes care about email registration verification 
(try it...), forgotten password emails + verification links, cookie 
expiry etc, without burdening the actual protocol.

-Andy



More information about the Libwebsockets mailing list