Skip to main content

Websocket server supporting channels/users communication

Project description

Channelstream

Build Status

This is a websocket-based communication server for python applications, your applications communicate with it via simple JSON REST API.

Visit http://channelstream.org for more information.

Installation and Setup

Obtain source from github and do:

python setup.py develop

Basic usage:

YOUR_PYTHON_ENV/bin/channelstream

The server can (and should be) also be configured via ini files (channelstream -i filename), example:

[channelstream]
debug = 0
port = 8000
secret = YOURSECRET
admin_secret = YOURADMINSECRET
allow_posting_from = 127.0.0.1,
                     x.x.x.x,
                     y.y.y.y,

To build frontend files:

cd frontend
yarn
yarn build # build minified bundles
yarn dev   # run watcher process and rebuild on the fly

Demos

This repository provides demonstrative applications on how to connect with the server and send information to clients.

You have a simple notification demo built on flask:

cd demo/notification/
YOUR_PYTHON_ENV/bin/pip install flask
YOUR_PYTHON_ENV/bin/flask run

Now you can open multiple browser windows to http://127.0.0.1:5000/ and test notifications.

There is also more complex chat application demo included, it showcases multiple channel subscriptions, message edits and user state changing.

YOUR_PYTHON_ENV/bin/python demo/chat/app.py

Open your browser and point it to following url:

http://127.0.0.1:6543

To run the demo you will need to have the requests package installed in your environment.

Security and communication model

Channelstream provides API explorer that you can use to interact with various endpoints, it is available by default under http://127.0.0.1:8000/api-explorer.

To send information client interacts only with your normal www application. Your app handled authentication and processing messages from client, then passed them as signed message to channelstream server for broadcast.

websocket client -> webapp (security and transformation happens here) -> REST call to socket server -> broadcast to other clients

This model is easy to implement, secure, easy to scale and allows all kind of languages/apps/work queues to interact with socket server.

All messages need to be signed with a HMAC of destination endpoint ::

import requests
from itsdangerous import TimestampSigner
signer = TimestampSigner(SERVER_SECRET)
sig_for_server = signer.sign('/connect')
secret_headers = {'x-channelstream-secret': sig_for_server,
                  'Content-Type': 'application/json'}
response = requests.post(url, data=json.dumps(payload),
                         headers=secret_headers).json()

Data format and endpoints

Please consult API Explorer (http://127.0.0.1:8000/api-explorer) for in depth information about endpoints.

Some examples:

  • /connect POST connects users to the server
  • /subscribe POST Subscribes connection to new channels
  • /unsubscribe POST Removes connection from channels
  • /user_state POST set the state of specific user
  • /message POST Send message to channels and/or users
  • /message DELETE Delete message from history and emit changes
  • /message PATCH Edit existing message in history and emit changes
  • /channel_config POST Set channel configuration
  • /info POST Returns channel information

Client API

  • /ws GET Handles websocket connections
  • /listen GET Handles long polling connections
  • /disconnect GET Permanently remove connection from server
  • /disconnect POST Permanently remove connection from server

Admin API

  • /admin/admin.json GET Return server information in json format for admin panel purposes
  • /admin/admin.json POST Return server information in json format for admin panel purposes

Responses to js client

Responses to client are in form of list containing objects:

examples:

new message ::

{
"date": "2011-09-15T11:36:18.471862",
"message": MSG_PAYLOAD,
"type": "message",
"user": "NAME_OF_POSTER",
"channel": "CHAN_NAME"
}

presence info ::

{
"date": "2011-09-15T11:43:47.434905",
"message": {"action":"joined/parted"},
"type": "presence",
"user": "NAME_OF_POSTER",
"channel": "CHAN_NAME"
}

Currently following message types are emited: message, message:edit, message:delete, presence, user_state_change.

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

channelstream-0.6.10.tar.gz (356.8 kB view details)

Uploaded Source

Built Distribution

channelstream-0.6.10-py2.py3-none-any.whl (398.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file channelstream-0.6.10.tar.gz.

File metadata

  • Download URL: channelstream-0.6.10.tar.gz
  • Upload date:
  • Size: 356.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for channelstream-0.6.10.tar.gz
Algorithm Hash digest
SHA256 42cf56ea47d65011fad9228da57c8aa396e57610374c115d06abbb4758d24582
MD5 8115261bc59191fb9230b9ed2cd6e2e4
BLAKE2b-256 4c30bfb637a7e261be7045589613e57a0c1f2655f3ce1385f254195eb6166d0c

See more details on using hashes here.

File details

Details for the file channelstream-0.6.10-py2.py3-none-any.whl.

File metadata

  • Download URL: channelstream-0.6.10-py2.py3-none-any.whl
  • Upload date:
  • Size: 398.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for channelstream-0.6.10-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 881459772245d695b8c4bfbbc0e16ab4451ed9cf1a2371a1398c441aad329c25
MD5 8939962e28fa610f70832e7180a40a80
BLAKE2b-256 1bce4a354b3c9162e4e6bfbc8d10572659d25a92a69adc9bc235ac3e7c232bf9

See more details on using hashes here.

Supported by

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