Skip to main content

chat for projects we help maintain @ ckc

Project description

django-chit-chat CKC

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


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.6.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

django_chit_chat-0.0.6-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file django-chit-chat-0.0.6.tar.gz.

File metadata

  • Download URL: django-chit-chat-0.0.6.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for django-chit-chat-0.0.6.tar.gz
Algorithm Hash digest
SHA256 8c2248d17e8ed9a28ff1fbb3f7c149bab4ce2d1459e5f970f1faf00a647ce952
MD5 99247e4c1eca4469519428dec5505e2a
BLAKE2b-256 c1745f7d6cfc8c2fa663ee6f467958bc528470a0b70b20b97f0e024cd704dc75

See more details on using hashes here.

File details

Details for the file django_chit_chat-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for django_chit_chat-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 df6ffb0fd535234b5bfe6ab9f78f47cfaf57d787c7bfda1ae8d52f54c0c1a450
MD5 a997969c5fddb47ee8a5acb31defb266
BLAKE2b-256 08ef553ab476f2accc4cd3881f57a75eb493a12e746e6e8475ba817221c606fc

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