diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index fb427076..bf1e6ead 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/osichat/__pycache__/consumers.cpython-310.pyc b/osinaweb/osichat/__pycache__/consumers.cpython-310.pyc index 2874f51a..d5c596bc 100644 Binary files a/osinaweb/osichat/__pycache__/consumers.cpython-310.pyc and b/osinaweb/osichat/__pycache__/consumers.cpython-310.pyc differ diff --git a/osinaweb/osichat/consumers.py b/osinaweb/osichat/consumers.py index 4baaf48a..3f121e10 100644 --- a/osinaweb/osichat/consumers.py +++ b/osinaweb/osichat/consumers.py @@ -9,11 +9,6 @@ import requests class OsitcomVisitor(WebsocketConsumer): def connect(self): - session = self.scope["session"] - if not session.session_key: - session.create() - session.save() - self.session_id = session.session_key async_to_sync(self.channel_layer.group_add)( 'ositcom_visitors', self.channel_name @@ -34,7 +29,7 @@ class OsitcomVisitor(WebsocketConsumer): if event_type == 'new_visitor': event = { 'type': 'new_visitor_handler', - 'session_id': self.session_id , + 'session_id': text_data_json.get('session_id'), 'client_ip': text_data_json.get('client_ip'), 'client_country': text_data_json.get('client_country'), 'referrer': text_data_json.get('referrer'), diff --git a/osinaweb/static/js/osichat/visitors.js b/osinaweb/static/js/osichat/visitors.js index 87b122a9..594f8d7c 100644 --- a/osinaweb/static/js/osichat/visitors.js +++ b/osinaweb/static/js/osichat/visitors.js @@ -19,10 +19,20 @@ document.addEventListener('DOMContentLoaded', () => { }); } + function fetchSessionID() { + return fetch('https://ositcom.com/get-client-session/') + .then(response => response.json()) + .then(data => data.session_id) + .catch(error => { + console.error('Error fetching session ID:', error); + return 'Unknown'; + }); + } + function initializeWebSocket() { const referrer = document.referrer; - fetchClientData().then(({ client_ip, client_country }) => { + Promise.all([fetchClientData(), fetchSessionID()]).then(([clientData, session_id]) => { const visitorsSocket = new WebSocket(visitorsSocketUrl); visitorsSocket.onopen = () => { @@ -32,8 +42,9 @@ document.addEventListener('DOMContentLoaded', () => { 'event_type': 'new_visitor', 'referrer': referrer, 'url': window.location.href, - 'client_ip': client_ip, - 'client_country': client_country + 'client_ip': clientData.client_ip, + 'client_country': clientData.client_country, + 'session_id': session_id }; visitorsSocket.send(JSON.stringify(event_message)); };