new
parent
497faf45a1
commit
4d5b5de4af
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,9 @@
|
||||
from django.urls import path, include
|
||||
from . import views
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
# DETAILS
|
||||
path('get-client-ip/', views.get_client_ip, name='get-client-ip'),
|
||||
|
||||
]
|
@ -1,3 +1,7 @@
|
||||
from django.shortcuts import render
|
||||
from django.http import JsonResponse
|
||||
|
||||
# Create your views here.
|
||||
def get_client_ip(request):
|
||||
client_ip = request.META.get('REMOTE_ADDR', '')
|
||||
return JsonResponse({'ip': client_ip})
|
Binary file not shown.
@ -1,29 +1,42 @@
|
||||
|
||||
const visitors_ws_scheme = window.location.protocol === "https:" ? "wss" : "ws";
|
||||
const my_domain = "osina.ositcom.com";
|
||||
const my_domain = "192.168.1.106:8000";
|
||||
const session_id = document.getElementById('session_id').textContent.trim();
|
||||
const current_url = document.getElementById('current_url').textContent.trim();
|
||||
const referrer = document.referrer;
|
||||
const referrer = document.referrer;
|
||||
const visitorsSocketUrl = `${visitors_ws_scheme}://${my_domain}/ws/osichat/visitors/`;
|
||||
const visitorsSocket = new WebSocket(visitorsSocketUrl);
|
||||
const clientIpUrl = `http://${my_domain}/get-client-ip/`;
|
||||
|
||||
fetch(clientIpUrl)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
const client_ip = data.ip;
|
||||
|
||||
visitorsSocket.onopen = () => {
|
||||
console.log('WebSocket connection to visitors established');
|
||||
const event_message = {
|
||||
'event_type': 'new_visitor',
|
||||
'session_id': session_id,
|
||||
'referrer': referrer,
|
||||
'url': current_url,
|
||||
};
|
||||
visitorsSocket.send(JSON.stringify(event_message));
|
||||
};
|
||||
|
||||
visitorsSocket.onopen = () => {
|
||||
console.log('WebSocket connection to visitors established');
|
||||
const event_message = {
|
||||
'event_type': 'new_visitor',
|
||||
'session_id': session_id,
|
||||
'referrer': referrer,
|
||||
'url': current_url,
|
||||
'client_ip': client_ip,
|
||||
};
|
||||
visitorsSocket.send(JSON.stringify(event_message));
|
||||
};
|
||||
|
||||
visitorsSocket.onclose = () => {
|
||||
console.log('WebSocket connection to visitors closed');
|
||||
};
|
||||
visitorsSocket.onclose = () => {
|
||||
console.log('WebSocket connection to visitors closed');
|
||||
};
|
||||
|
||||
visitorsSocket.onerror = (error) => {
|
||||
console.log('WebSocket error:', error);
|
||||
};
|
||||
visitorsSocket.onerror = (error) => {
|
||||
console.error('WebSocket error:', error);
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching client IP:', error);
|
||||
});
|
||||
|
Loading…
Reference in New Issue