django-mease: Websocket integration made easy for Django
Project description
Work in progress. See a full working example here.
RTD INCOMING SHORTLY
Websocket integration made easy for Django using Tornado, Redis PUB/SUB and easy to use callback registry mechanism.
Installation
Dependencies (Debian & Ubuntu)
Mease comes with Redis PUB/SUB backend by default. If you want to use it, install these dependencies :
sudo apt-get install redis-server python-dev pip install redis toredis-mease
Install django-mease
pip install django-mease
Add mease to your INSTALLED_APPS
INSTALLED_APPS = (
# List of your installed apps
'djmease',
)
Usage
Start websocket server
python manage.py run_websocket_server
Register callbacks
Create mease_registry.py files to register your callbacks (the file must be located in an installed app):
from djmease import mease
@mease.receiver
def receive_websocket_message(client, message, clients_list):
for c in clients_list:
c.write_message(message)
@mease.sender(routing=['websocket'])
def send_websocket_message(channel, message, clients_list):
for c in clients_list:
c.write_message(message)
Receiver functions are called when a message is sent from the client.
mease.receiver functions must take 3 parameters:
the client (tornado WebSocketHandler instance)
the message content
a list of all connected clients (list of tornado WebSocketHandler instances)
Sender functions are called when a message is sent from the server.
mease.sender functions must take 3 parameters:
a list of all connected clients (list of tornado WebSocketHandler instances)
the target routing
the message content
A sender function can be registered for a list of routings, otherwise it is registered globally.
Publish
Use mease.publish to publish from anywhere in your code :
from djmease import mease
mease.publish('websocket', "Hello world !")
This will call all sender functions registered on the ‘websocket’ routing.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-mease-0.1.8.tar.gz
.
File metadata
- Download URL: django-mease-0.1.8.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4f8eefa8d4af692b048f5b21e67138bfaaf8250276e804e4eee8df8cac54787 |
|
MD5 | 83155e88f30817dbeda8c419d2a2fac5 |
|
BLAKE2b-256 | 37d51f756e8c43791d2f2b5dada6f28c26606082a0585b58e1cc5f9f2d138259 |