chat for projects we help maintain @ ckc
Project description
django-chit-chat
chat for projects we help maintain @ ckc
installing
pip install django-chit-chat
# settings.py
INSTALLED_APPS = (
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.staticfiles",
# ... add chit_chat
"chit_chat",
)
# routing.py
from channels.auth import AuthMiddlewareStack
from django.core.asgi import get_asgi_application
from channels.routing import ProtocolTypeRouter, URLRouter
import chit_chat.routing
application = ProtocolTypeRouter({
'http': get_asgi_application(),
'websocket': AuthMiddlewareStack(
URLRouter(
chit_chat.routing.websocket_urlpatterns
)
),
})
# urls.py
from rest_framework import routers
from chit_chat.viewsets import RoomViewSet
router = routers.SimpleRouter()
router.register('chatrooms', RoomViewSet)
urlpatterns = router.urls
<!-- chat.html -->
<script>
// Open a connection to django-chit-chat
YourWebsocketThing.open(`wss://${window.location.host}/ws/chatroom/`)
// Write messages to screen as they're sent/received
YourWebsocketThing.onmessage(msg => writeMessageToScreen(JSON.parse(msg.data)))
// You can do a GET to "/api/chatrooms/" for a list of chatrooms + messages
$.get("/api/chat/rooms").success(d => ...)
// Send a message
function send_message(text) {
WSClient.send(JSON.stringify({
message_type: "chat",
room: 1, // ID of chat room
text: text
}))
}
</script>
distributing and releasing
# Update version in setup.cfg
./setup.py sdist
twine upload dist/*
# Commit and push the version update in setup.cfg
# Publish vX.X.X release on GitHub with a description.
tests
$ docker build -t django-chit-chat . && docker run django-chit-chat pytest
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
django-chit-chat-0.0.5.tar.gz
(11.9 kB
view hashes)
Built Distribution
Close
Hashes for django_chit_chat-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7153f8f3dc5fc29f65fef67b823e64de5c15cc5b4bb1edacca4f1d543839e77 |
|
MD5 | 73ab6f9d4d650b30cea3196883a4f8ca |
|
BLAKE2b-256 | abba9dd69f492d38538857477df6a926772f0ba03457b0c5d7494c02e5b8d001 |