Compare commits
No commits in common. "9947ea37e2069b2297beecb6c1814f127b244e5b" and "7e34f883aa4a8a008577b109c5fc6f3815c77f55" have entirely different histories.
9947ea37e2
...
7e34f883aa
@ -1,3 +0,0 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
@ -1,6 +0,0 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ChatConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'chat'
|
@ -1,3 +0,0 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
@ -1,3 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
@ -1,3 +0,0 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
@ -31,6 +31,6 @@ class ChatConsumer(WebsocketConsumer):
|
||||
|
||||
self.send(text_data=json.dumps({
|
||||
'type':'chat',
|
||||
'username':self.scope["user"].username,
|
||||
'message':message
|
||||
}))
|
||||
|
@ -12,8 +12,6 @@ import { Client } from "./api/client.js";
|
||||
|
||||
let client = new Client(location.protocol + "//" + location.host)
|
||||
|
||||
let lastView = undefined
|
||||
|
||||
const pathToRegex = path => new RegExp("^" + path.replace(/\//g, "\\/").replace(/:\w+/g, "(.+)") + "$");
|
||||
|
||||
const getParams = match => {
|
||||
@ -59,12 +57,7 @@ const router = async (uri = "") => {
|
||||
result: [uri]
|
||||
};
|
||||
}
|
||||
|
||||
if (lastView !== undefined)
|
||||
await lastView.leavePage();
|
||||
|
||||
const view = new match.route.view(getParams(match));
|
||||
lastView = view;
|
||||
|
||||
let content = await view.getHtml();
|
||||
if (content == null)
|
||||
@ -88,4 +81,4 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
router(location.pathname);
|
||||
});
|
||||
|
||||
export { client, navigateTo }
|
||||
export { client, navigateTo }
|
||||
|
@ -6,9 +6,6 @@ export default class {
|
||||
async postInit() {
|
||||
}
|
||||
|
||||
async leavePage() {
|
||||
}
|
||||
|
||||
setTitle(title) {
|
||||
document.title = title;
|
||||
}
|
||||
|
@ -14,9 +14,8 @@ export default class extends AbstractView {
|
||||
if (data.type === 'chat') {
|
||||
let messages = document.getElementById('messages')
|
||||
|
||||
let username = data.username === null || data.username.length <= 0 ? "NoName" : data.username;
|
||||
messages.insertAdjacentHTML('beforeend', `
|
||||
<div><p>${username}: ${data.message}</p></div>
|
||||
<div><p>${data.message}</p></div>
|
||||
`)
|
||||
}
|
||||
|
||||
@ -33,11 +32,6 @@ export default class extends AbstractView {
|
||||
}))
|
||||
form.reset()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
async leavePage() {
|
||||
this.chatSocket.close();
|
||||
}
|
||||
|
||||
async getHtml() {
|
||||
|
@ -6,5 +6,4 @@ djangorestframework==3.14.0
|
||||
install==1.3.5
|
||||
pytz==2023.3.post1
|
||||
sqlparse==0.4.4
|
||||
channels==4.0.0
|
||||
daphne
|
||||
channels==3.0.5
|
||||
|
@ -8,20 +8,9 @@ https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
|
||||
"""
|
||||
|
||||
import os
|
||||
from channels.routing import ProtocolTypeRouter, URLRouter
|
||||
from channels.auth import AuthMiddlewareStack
|
||||
import chat.routing
|
||||
|
||||
from django.core.asgi import get_asgi_application
|
||||
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'trancendence.settings')
|
||||
|
||||
application = ProtocolTypeRouter({
|
||||
'http':get_asgi_application(),
|
||||
'websocket':AuthMiddlewareStack(
|
||||
URLRouter(
|
||||
chat.routing.websocket_urlpatterns
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
application = get_asgi_application()
|
||||
|
@ -38,9 +38,6 @@ CORS_ORIGIN_WHITELIST = (
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'channels',
|
||||
'daphne',
|
||||
|
||||
'accounts.apps.AccountsConfig',
|
||||
'profiles.apps.ProfilesConfig',
|
||||
'frontend.apps.FrontendConfig',
|
||||
@ -55,14 +52,6 @@ INSTALLED_APPS = [
|
||||
'django.contrib.staticfiles',
|
||||
]
|
||||
|
||||
ASGI_APPLICATION = 'trancendence.asgi.application'
|
||||
|
||||
CHANNEL_LAYERS = {
|
||||
'default' :{
|
||||
'BACKEND':'channels.layers.InMemoryChannelLayer'
|
||||
}
|
||||
}
|
||||
|
||||
MIDDLEWARE = [
|
||||
'corsheaders.middleware.CorsMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
|
Loading…
Reference in New Issue
Block a user