Django Presence

Contents:

Install

Dependencies:

Install Django Instant according to this documentation

pip install django-presence

Add "presence", to installed apps

Settings

Centrifugo config: be sure to have presence enabled in config.json (cf django-instant docs):

{
 "secret": "70b651f6-775a-4949-982b-b387b31c1d84",
 "anonymous": true,
 "presence":true
 }

Settings:

# required
SITE_SLUG = "mysite"
# frequency of updates: optional: default is 10
PRESENCE_FREQUENCY = 30

Templates

Add a instant/extra_clients.js template with this content:

{% include "presence/js/client.js" %}

Add a instant/extra_handlers.js template with this content:

{% include "presence/js/handlers.js" %}

Where you want the presence widget to be put:

{% include "presence/widget.html" %}.

You can tweak presence/js/handlers.js to make your own client-side event handlers.

Workers

The presence data is automaticaly updated from the time based worker asking Centrifugo who is on the socket. This data is broadcasted to the clients over the websocket.

Default worker

The default worker for presence updates is a go module. Install with the command python manage.py installpres: it will generate two files in your main project directory:

  • centpres: the executable
  • centpres_config.json: the config file

To run the worker: ./centpres. This will start updating presence info.

Note: you can also compile the go module from the source in presence/go/src/