Skip to content

uhttpd: implement ubus event listener via Server-Sent Event protocol

Username: Nicolás Pace

Origin: https://bugs.openwrt.org/index.php?do=details&task_id=2248

Usecase:

As a web developer I would benefit from having the possibility to send events from the server to the browser so the browser can react to it dynamically.

The proposed implementation is the leanest possible.

A SSE (

Server-Sent Event

) is a simple protocol on top of basic http polling to send messages from the http server to the browser for the purpose of instant notifications.

It comes implemented in all major browsers, including

mobile

.

If paired with ubus listen or ubus monitor, a seamless integration with the ubus pipeline could be implemented.

We tried to implement it by adding an option in

this line of code

but got stuck in our lack of corutine mechanisms and how uhttpd works.

The difference with the call and list options is that this one should be long-lived and progressive, preventing the dreaded polling from the web (also, better us of resources, more elegant implementation, etc).

As an example, a very basic implementation of a SSE server in php: