view mod_pubsub_eventsource/README.markdown @ 3609:0d4598dacc87

mod_statistics_statsman: Map 'cpu.clock' from mod_measure_cpu to 'cpu_total' of mod_statistics_cputotal
author Kim Alvefur <>
date Tue, 28 May 2019 21:26:13 +0200
parents 4d73a1a6ba68
line wrap: on
line source

labels: 'Stage-Beta'
summary: Subscribe to pubsub nodes using the HTML5 EventSource API


[Server-Sent Events](
is a simple HTTP/line-based protocol supported in HTML5, making it easy
to receive a stream of "events" in realtime using the Javascript

EventSource is supported in [most modern
browsers](, and for the remainder
there are 'polyfill' compatibility layers such as
and [jquery.eventsource](


Subscribing to a node from Javascript is easy:

    var source = new EventSource('');
    source.onmessage = function (event) {
      console.log(; // Do whatever you want with the data here

### Cross-domain issues

The same cross-domain restrictions apply to EventSource that apply to
BOSH, and support for CORS is not clearly standardized yet. You may want
to proxy connections through your web server for this reason. See [BOSH:
issues]( for
more information.


There is no special configuration for this module. Simply load it onto a
pubsub component like so:

    Component "" "pubsub"
      modules_enabled = { "pubsub_eventsource" }

As it uses HTTP to serve the event streams, you can use Prosody's
standard [HTTP configuration options]( to
control how/where the streams are served.

**Note about URLs:** It is important to get the event streams from the
correct hostname (that of the pubsub host). An example stream URL is
``. If you need to
access the streams using another hostname (e.g. ``) you can
use the `http_host` option under the Component, e.g.
`http_host = ""`. For more information see the ['Virtual
Hosts']( section of our HTTP


  ------- --------------
  0.9     Works
  0.8     Doesn't work
  Trunk   Works
  ------- --------------