Hopital en PLS
This commit is contained in:
parent
267eeab896
commit
6e624dad34
15
frontend/consumers.py
Normal file
15
frontend/consumers.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import json
|
||||||
|
from channels.generic.websocket import WebsocketConsumer
|
||||||
|
|
||||||
|
class ChatConsumer(WebsocketConsumer):
|
||||||
|
def connect(self):
|
||||||
|
self.accept()
|
||||||
|
|
||||||
|
self.send(text_data=json.dumps({
|
||||||
|
'type':'connection_established',
|
||||||
|
'message':'Your are now connected',
|
||||||
|
}))
|
||||||
|
|
||||||
|
def receive():
|
||||||
|
|
||||||
|
def disconnect():
|
6
frontend/rounting.py
Normal file
6
frontend/rounting.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
from django.urls import re_path
|
||||||
|
from . import consumers
|
||||||
|
|
||||||
|
websocket_urlpatterns = [
|
||||||
|
re_path(r'ws/socket-server/', consumers.ChatConsumer.as_asgi())
|
||||||
|
]
|
@ -1,37 +1,9 @@
|
|||||||
body {
|
body {
|
||||||
--nav-width: 200px;
|
margin: 10;
|
||||||
margin: 0 0 0 var(--nav-width);
|
|
||||||
font-family: 'Quicksand', sans-serif;
|
font-family: 'Quicksand', sans-serif;
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav {
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: var(--nav-width);
|
|
||||||
height: 100vh;
|
|
||||||
background: #222222;
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav__link {
|
|
||||||
display: block;
|
|
||||||
padding: 12px 18px;
|
|
||||||
text-decoration: none;
|
|
||||||
color: #eeeeee;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
.nav__link:hover {
|
|
||||||
background: rgba(255, 255, 255, 0.05);
|
|
||||||
}
|
|
||||||
|
|
||||||
#app {
|
|
||||||
margin: 2em;
|
|
||||||
line-height: 1.5;
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: #009579;
|
color: #009579;
|
||||||
}
|
}
|
BIN
frontend/static/js/.index.js.swp
Normal file
BIN
frontend/static/js/.index.js.swp
Normal file
Binary file not shown.
@ -2,6 +2,7 @@ import Dashboard from "./views/Dashboard.js";
|
|||||||
import Posts from "./views/Posts.js";
|
import Posts from "./views/Posts.js";
|
||||||
import PostView from "./views/PostView.js";
|
import PostView from "./views/PostView.js";
|
||||||
import Settings from "./views/Settings.js";
|
import Settings from "./views/Settings.js";
|
||||||
|
import GeneralChat from "./views/GeneralChat.js";
|
||||||
|
|
||||||
const pathToRegex = path => new RegExp("^" + path.replace(/\//g, "\\/").replace(/:\w+/g, "(.+)") + "$");
|
const pathToRegex = path => new RegExp("^" + path.replace(/\//g, "\\/").replace(/:\w+/g, "(.+)") + "$");
|
||||||
|
|
||||||
@ -24,7 +25,8 @@ const router = async () => {
|
|||||||
{ path: "/", view: Dashboard },
|
{ path: "/", view: Dashboard },
|
||||||
{ path: "/posts", view: Posts },
|
{ path: "/posts", view: Posts },
|
||||||
{ path: "/posts/:id", view: PostView },
|
{ path: "/posts/:id", view: PostView },
|
||||||
{ path: "/settings", view: Settings }
|
{ path: "/settings", view: Settings },
|
||||||
|
{ path: "/generalchat", view: GeneralChat },
|
||||||
];
|
];
|
||||||
|
|
||||||
// Test each route for potential match
|
// Test each route for potential match
|
||||||
|
22
frontend/static/js/views/GeneralChat.js
Normal file
22
frontend/static/js/views/GeneralChat.js
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import AbstractView from "./AbstractView.js";
|
||||||
|
|
||||||
|
export default class extends AbstractView {
|
||||||
|
constructor(params) {
|
||||||
|
super(params);
|
||||||
|
this.setTitle("General Chat");
|
||||||
|
let url = `ws://${window.location.host}/ws/socket-server/`
|
||||||
|
|
||||||
|
const chatSocket = new WebSocket(url)
|
||||||
|
chatSocket.onmessage = function(e) {
|
||||||
|
let data = JSON.parse(e.data)
|
||||||
|
console.log('Data:', data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async getHtml() {
|
||||||
|
return `
|
||||||
|
<h1>General Chat</h1>
|
||||||
|
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@
|
|||||||
<nav class="nav">
|
<nav class="nav">
|
||||||
<a href="/" class="nav__link" data-link>Dashboard</a>
|
<a href="/" class="nav__link" data-link>Dashboard</a>
|
||||||
<a href="/posts" class="nav__link" data-link>Posts</a>
|
<a href="/posts" class="nav__link" data-link>Posts</a>
|
||||||
|
<a href="/generalchat" class="nav__link" data-link>General Chat</a>
|
||||||
<a href="/settings" class="nav__link" data-link>Settings</a>
|
<a href="/settings" class="nav__link" data-link>Settings</a>
|
||||||
</nav>
|
</nav>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
@ -10,7 +10,17 @@ https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from django.core.asgi import get_asgi_application
|
from django.core.asgi import get_asgi_application
|
||||||
|
from channels.routing import ProtocolTypeRouter, URLRouter
|
||||||
|
from channels.auth import AuthMiddlewareStack
|
||||||
|
import chat.routing
|
||||||
|
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'trancendence.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'trancendence.settings')
|
||||||
|
|
||||||
application = get_asgi_application()
|
application = ProtocolTypeRouter({
|
||||||
|
'http':get_asgi_application(),
|
||||||
|
'websocket':AuthMiddlewareStack(
|
||||||
|
URLRouter(
|
||||||
|
chat.routing.websocket_urlpatterns
|
||||||
|
)
|
||||||
|
),
|
||||||
|
})
|
||||||
|
@ -38,6 +38,9 @@ CORS_ORIGIN_WHITELIST = (
|
|||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
|
|
||||||
|
'channels',
|
||||||
|
|
||||||
'accounts.apps.AccountsConfig',
|
'accounts.apps.AccountsConfig',
|
||||||
'profiles.apps.ProfilesConfig',
|
'profiles.apps.ProfilesConfig',
|
||||||
'frontend.apps.FrontendConfig',
|
'frontend.apps.FrontendConfig',
|
||||||
@ -52,6 +55,8 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
ASGI_APPLICATION = 'trancendence.asgi.application'
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
'corsheaders.middleware.CorsMiddleware',
|
'corsheaders.middleware.CorsMiddleware',
|
||||||
'django.middleware.common.CommonMiddleware',
|
'django.middleware.common.CommonMiddleware',
|
||||||
|
Loading…
Reference in New Issue
Block a user