SkillAgentSearch skills...

Adjacent

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

Install / Use

/learn @centrifugal/Adjacent
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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 }}'
});
View on GitHub
GitHub Stars32
CategoryDevelopment
Updated3y ago
Forks5

Languages

Python

Security Score

60/100

Audited on Jan 28, 2023

No findings