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