Django package for socket.io via nodejs
Project description
### What is django-socketio-events?
Simply adds socket.io functionality to Django applications by proxying Django behind a Nodejs/SocketIO server.
Any callback function defined in an `app_folder` is exposed to Socket.IO as the target `my_app.callback_fn`. See examples below.
### Usage
```
python manage.py runserverjs <hostname> <public port> <proxy port> <socket port>
```
In any Django template that you want a Socket IO connection, add this templatetag to your HEAD:
```
{% load nodjango %}
<!doctype html>
<html>
<head>
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.1.min.js"></script>
{% socketio_head_scripts %}
</head>
<body>
<button>Click Me</button>
<script type="text/javascript">
socket.on('my_callback', function(data){
console.log(JSON.stringify(data));
});
$('button').on('click', function(){
socket.emit('django', {
'event': 'my_app.change_color',
'callback': 'my_callback',
'color': 'red'
});
});
</script>
</body>
</html>
```
```
# my_app/socketio.py
def change_color(color):
# change color
# ...
# profit
return {'result': 42}
```
### Installation
```
pip install django-socketio-events
```
And then add `nodjango` to your `INSTALLED_APPS`.
### Under the hood
* [virtual-node](https://github.com/elbaschid/virtual-node) for installing [node.js](http://nodejs.org/) in a Python virtualenv.
* [Django](https://www.djangoproject.com/) web framework
Simply adds socket.io functionality to Django applications by proxying Django behind a Nodejs/SocketIO server.
Any callback function defined in an `app_folder` is exposed to Socket.IO as the target `my_app.callback_fn`. See examples below.
### Usage
```
python manage.py runserverjs <hostname> <public port> <proxy port> <socket port>
```
In any Django template that you want a Socket IO connection, add this templatetag to your HEAD:
```
{% load nodjango %}
<!doctype html>
<html>
<head>
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.1.min.js"></script>
{% socketio_head_scripts %}
</head>
<body>
<button>Click Me</button>
<script type="text/javascript">
socket.on('my_callback', function(data){
console.log(JSON.stringify(data));
});
$('button').on('click', function(){
socket.emit('django', {
'event': 'my_app.change_color',
'callback': 'my_callback',
'color': 'red'
});
});
</script>
</body>
</html>
```
```
# my_app/socketio.py
def change_color(color):
# change color
# ...
# profit
return {'result': 42}
```
### Installation
```
pip install django-socketio-events
```
And then add `nodjango` to your `INSTALLED_APPS`.
### Under the hood
* [virtual-node](https://github.com/elbaschid/virtual-node) for installing [node.js](http://nodejs.org/) in a Python virtualenv.
* [Django](https://www.djangoproject.com/) web framework
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-socketio-events-0.1.2.tar.gz
.
File metadata
- Download URL: django-socketio-events-0.1.2.tar.gz
- Upload date:
- Size: 30.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 788a33b8e8e319f79f00d1bd06d5ca864c8c51393fcb4dcbad43fb460a48f3a5 |
|
MD5 | 7c3df70a78638ba33137f7b672f27d9d |
|
BLAKE2b-256 | 08e9add0b37aaf3910d22ff799db0131238f8a2f1140a2f2194117ad2a79e5cc |