django-eventstream icon indicating copy to clipboard operation
django-eventstream copied to clipboard

get stuck with send_event

Open ikrma47 opened this issue 2 years ago • 4 comments

Hello, I've been stuck with send_event function.

my backend is generating image frames after processing a video, I want to send these frames directly to frontend. but I tried using this library.

whenever I send a get request to /events/ it displayed

event: stream-open data

after that when I use send_event function with type that I specified in the urlpatterns, but unfortunately nothing happens

path('events/', include(django_eventstream.urls), {'channels': 'test'}),
def get(self, request):

       send_event('test', 'message', {"test": "asdsa"})
       return HttpResponse()

whenever I hit this view, I received nothing on the frontend. my frontend is react

useEffect(() => {
    const eventSource = new EventSource("http://localhost:8000/events/");
    eventSource.onopen = (e) => console.log("opened");
    eventSource.onmessage = (e) => console.log(e);
  }, []);

ikrma47 avatar Jun 12 '22 12:06 ikrma47

I notice you're setting a path entry, which is usually part of urls.py and used for WSGI setups. However, Django Channels requires setting up ASGI-based routes. See for example: https://github.com/fanout/django-eventstream/blob/master/examples/chat/server/asgi.py#L30

jkarneges avatar Jun 21 '22 17:06 jkarneges

Got it. Now it's working fine.

Thank you very much. This library makes my FYP easier.

ikrma47 avatar Jun 30 '22 15:06 ikrma47