Firefox не может установить соединение с сервером по адресу ws://127.0.0.1:port
Я создал чат-приложение, в котором пользователи смогут звонить, отправлять друг другу тексты и картинки. Когда я нажимаю на кнопку вызова, я должен видеть свой поток и второго пользователя, которому я звоню. Я просто вижу свою камеру и не вижу своего контакта. Если другой пользователь попытается позвонить мне, все повторится снова. Как решить эту проблему?
ошибка на консоли:
**Firefox can’t establish a connection to the server at ws://127.0.0.1:8000/ws/call/username/**
`# chat/consumers.py
from channels.generic.websocket import AsyncWebsocketConsumer
import json
class ChatConsumer(AsyncWebsocketConsumer):
async def connect(self):
self.room_name = self.scope\['url_route'\]\['kwargs'\]\['username'\]
self.room_group_name = f'chat\_{self.room_name}'
# Join room group
await self.channel_layer.group_add(
self.room_group_name,
self.channel_name
)
await self.accept()
async def disconnect(self, close_code):
# Leave room group
await self.channel_layer.group_discard(
self.room_group_name,
self.channel_name
)
async def receive(self, text_data):
# Handle incoming WebSocket messages
text_data_json = json.loads(text_data)
message = text_data_json['message']
# Broadcast message to room group
await self.channel_layer.group_send(
self.room_group_name,
{
'type': 'chat_message',
'message': message
}
)
async def chat_message(self, event):
# Send message to WebSocket
message = event['message']
# Send message to WebSocket
await self.send(text_data=json.dumps({
'message': message
}))
`
decorators.py
`from functools import wraps
from django.shortcuts import redirect
from django.urls import reverse
from authentication.models import BasicUserProfile
def basic_user_login_required(view_func):
@wraps(view_func)
def _wrapped_view(request, *args, **kwargs):
if not request.user.is_authenticated:
return redirect(reverse('login'))
# Check if the authenticated user has a BasicUserProfile
if not BasicUserProfile.objects.filter(user=request.user).exists():
return redirect(reverse('login'))
return view_func(request, *args, **kwargs)
return _wrapped_view
`
routing.py:
`# chat/routing.py
from django.urls import re_path
from . import consumers
websocket_urlpatterns = [
re_path(r'call/<str:username>/', consumers.ChatConsumer.as_asgi()),
# Define other WebSocket URL patterns as needed
]
`
urls.py:
path('call/<str:username>/', views.call_view, name='call'),
views.py:
`def call_view(request, username):
return render(request, 'chat/call.html', {'username': username})`
templates/ call.html:
`const roomName = "{{ username }}";
const callSocket = new WebSocket(`ws://${window.location.host}/ws/call/${roomName}/`);`
Я пытался исправить маршрутизацию и потребителей, а также некоторые элементы на стороне front-end, но безуспешно.