Skip to main content

Sockjs-tornado multi room system

Project description

python-sockjsroom
=================

Add multi-room and multi-message type support for sockjs-tornado.


Installation
------------

The most easy way to install sockjsroom is to use Pypi:
```
pip install sockjsroom
```
It will also auto-include tornado and sockjs-tornado

The alternative method is to clone this repository:
```
git clone https://github.com/Deisss/python-sockjsroom.git
```
And run setup:
```
python setup.py install
```



Usage
-----

The most basic usage can be a Ping system:

```python
from sockjsroom import SockJSDefaultHandler


class PingSocketHandler(SockJSDefaultHandler):
""" Ping system """
def on_open(self, info):
pass

def on_message(self):
pass

def on_close(self):
pass
```

This example does only create an empty handler, without any room support.

Here a more complete example using room support:

```python
from sockjsroom import SockJSRoomHandler

class MySocketHandler(SockJSRoomHandler):
def initialize(self):
self.roomId = "0"

# SOCKJS DEFAULT FUNCTION

def on_open(self, info):
pass

def on_close(self):
self.on_leave()

# SOCKJS CUSTOM FUNCTION

def on_join(self, data):
""" Join timer system """
# data => roomId
self.initialize()

self.roomId = str(data.roomId)

def on_chat(self, data):
""" Start timer for everybody """
# data => message
self.publishToRoom(self.roomId, "chat", {"message" : data.message})

def on_leave(self):
""" Quit timer system """
if self.roomId != "0":
self.leave(self.roomId)

self.initialize()
```
Now you can have not only **on_open**, **on_message** and **on_close**,
but almost what you want (except on_message already used internally).

The system will do the json convertion for you directly, and helps you
threw publishing process by providing:

* **publishToRoom** send message to everybody
* **publishToMyself** send message to yourself
* **publishToOther** send message to everybody else

With those, it may become simple to publish data to subset of people with ease.



Furthermore
-----------

You can found an exaustive presentation of code, and possibilities [here](http://simplapi.wordpress.com/2013/09/22/sockjs-on-steroids/)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sockjsroom-0.0.3.zip (9.4 kB view details)

Uploaded Source

File details

Details for the file sockjsroom-0.0.3.zip.

File metadata

  • Download URL: sockjsroom-0.0.3.zip
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sockjsroom-0.0.3.zip
Algorithm Hash digest
SHA256 d4d663a2aad45a6445365faf05887d274acd02950279e01e0ff9df3a6138a6d9
MD5 163a40628e4ec5365515301c8a0b29cb
BLAKE2b-256 077025600e34406a78324fb5e91287a6c28528274b9172015917c774bf98c654

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page