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>
tests
$ docker build -t django-chit-chat . && docker run django-chit-chat pytest
Releasing
- Update version number in
setup.cfg
. - Create release using Github's UI.
- Click the
Choose a tag
dropdown and create a new tag with the new version number. - Click the
Generate release notes
button to automatically create release notes. - This will trigger an action to build and push the release to PyPi.
- Click the
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.9.tar.gz
(14.1 kB
view details)
Built Distribution
File details
Details for the file django-chit-chat-0.0.9.tar.gz
.
File metadata
- Download URL: django-chit-chat-0.0.9.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc562895ee287e1f540c53a432ba11a54cd70a3e31e4f4180935e773e6f9158a |
|
MD5 | b4a9dc783a4369b58021d1a077e57808 |
|
BLAKE2b-256 | d9d27e784c90833e4abd471a2e47a685fca439744ccdd5e534402cad06c556f6 |
File details
Details for the file django_chit_chat-0.0.9-py3-none-any.whl
.
File metadata
- Download URL: django_chit_chat-0.0.9-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff8a78a5e555465273730fcfc9c62291264e23fef7c4400f0bd31b7ac56df314 |
|
MD5 | d0cd82ef7f4e1c4f2610ce644d7851cb |
|
BLAKE2b-256 | 53600046be4a61b85b603a562530603d65d0d77de849dd9edf77739cb7472f04 |