wssup
head over to django/channels and use my promo code 🚨 🎟️ ♨️ 3HTTP5ME
♨️ 🎟️ 🚨
This project was developed to learn and prototype websocket streaming/consumption in django.
setup
Requirements:
- python >=
3.5
- django >=
1.11
- docker
used to install and run Redis
Run migrations (needed for Django's session framework):
# wssup/
$ ./manage.py migrate
Configure allowed hosts as needed:
# wssup/wssup/settings.py
ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'www.domain.com', '.domain.com']
usage
Start a Redis server on a local {port}
via Docker.
$ docker run -p {port}:6379 -d redis:5.0
Run the django ASGI server.
# wssup/
$ ./manage.py runserver # 0:{port} for external access
Clients access {host}/chat/
and input a chatroom name to join. All messages from all clients in that room appear to each other.
optional - testing via selenium
Install Google Chrome web browser.
Obtain chromedriver and place it in a preferred path. Selenium controls Chrome through chromedriver
.
This package provides
chromedriver
for for Chrome 77; Choose appropriately for your Chrome version.
Set wssup.settings.CHROMEDRIVER_PATH
to the chromedriver path.
By default, this package points to
./wssup/chromedriver
. An empty value will use$PATH
.
Ensure that chromedriver
is executable.
# {chromedriver dir}/
$ chmod +x chromedriver
Run the tests.
# wssup/
$ ./manage.py test chat.tests
troubleshooting
- test that a channel layer can communicate with Redis
- test that chromedriver is correctly accessed path-wise
# wssup/
$ ./manage.py shell
test that a channel layer can communicate with Redis
>>> import channels.layers
>>> cl = channels.layers.get_channel_layer()
>>>
>>> from asgiref.sync import async_to_sync as a2s
>>> a2s(cl.send)('test', {'type': 'hi'})
>>>
>>> a2s(cl.receive)('test')
{'type': 'hi'}
test that chromedriver is correctly accessed path-wise
>>> from chat.tests import ChatTests
>>> ChatTests().setUpClass()