Skip to content
This repository has been archived by the owner on Jul 25, 2020. It is now read-only.
/ adjacent Public archive

Centrifugo v1 integration with Django framework, for Centrifugo v2 use cent Python client to integrate

Notifications You must be signed in to change notification settings

centrifugal/adjacent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Centrifugo server integration with Django framework.

Installation:

pip install adjacent

Add adjacent into INSTALLED_APPS

Add some settings to your settings.py file:

CENTRIFUGE_ADDRESS = 'http://centrifuge.example.com'
CENTRIFUGE_SECRET = 'your secret key from Centrifugo'
CENTRIFUGE_TIMEOUT = 10

After this you get the follows:

  1. Function to create connection parameters for user:
from adjacent import get_connection_parameters

params = get_connection_parameters(user)
  1. Client wrapper to send messages into Centrifuge
from adjacent import Client

client = Client()

# add some messages to publish
client.publish("channel", {"data": "first"})
client.publish("channel", {"data": "second"})

# actually send request with 2 publish messages added above to Centrifuge
response = client.send()

Client methods:

  • client.publish(channel, data, client=None)
  • client.disconnect(user)
  • client.unsubscribe(user, channel)
  • client.presence(channel)
  • client.history(channel)
  • client.channels()
  • client.stats()

In template

When you passed connection parameters to template you can initialize Centrifuge javascript object in this way:

var centrifuge = new Centrifuge({
    url: '{{ params.sockjs_endpoint }}',
    user: '{{ params.user }}',
    timestamp: '{{ params.timestamp }}',
    info: '{{ params.info|safe }}',
    token: '{{ params.token }}'
});

About

Centrifugo v1 integration with Django framework, for Centrifugo v2 use cent Python client to integrate

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages