mod_muc_eventsource

Introduction

This module and its docs shamelessly forked from mod_pubsub_eventsource.

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

EventSource is supported in most modern browsers, and for the remainder there are ‘polyfill’ compatibility layers such as EventSource.js and jquery.eventsource.

Details

Subscribing to a node from Javascript is easy:

var source = new EventSource('http://muc.example.org:5280/eventsource/myroom');
source.onmessage = function (event) {
  console.log(event.data); // Do whatever you want with the data here
};

Access control

Be warned that this module currently performs no access control. It will expose the messages of ALL rooms on the host it is loaded on. This may be changed in future revisions.

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: Cross-domain issues for more information.

Configuration

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

Component "muc.example.org" "muc"
  modules_enabled = { "muc_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 MUC host). An example stream URL is http://muc.example.org:5280/eventsource/myroom. If you need to access the streams using another hostname (e.g. example.org) you can use the http_host option under the Component, e.g. http_host = "example.org". For more information see the ‘Virtual Hosts’ section of our HTTP documentation.

Compatibility

0.10 ?
0.9 ?
0.8 Doesn’t work
Trunk Works

Installation

With the plugin installer in Prosody 0.12 you can use:

sudo prosodyctl install --server=https://modules.prosody.im/rocks/ mod_muc_eventsource

For earlier versions see the documentation for installing 3rd party modules