I need a django template to refresh when an asynchronous event is detected on the server. I implemented this successfully using django-channels on my development server.
However, the server I need to deploy to (pythonanywhere.com) doesn't support ASGI applications, so I can't use django-channels there.
I tried to build a very simple server sent event using django-eventsteam using the advice in https://github.com/fanout/django-eventstream#setup-without-channels.
I uninstalled channels and channels-redis from my virtual env, then installed django-eventstream (this reinstalled channels)
I've tried using pushpin and fanout as message brokers, but I still get the same problem.
The server sent message appears to be sent correctly:
send_event('test', 'message', {'text': 'hello world'})
but does not appear to be detected by the client.
var es = new ReconnectingEventSource('evdja/?channel=test');
es.addEventListener('message', function (e) {
console.log(e.data);
location.reload(true);
}, false);
I just want the page to refresh when the server sent event is detected, but the listener is not triggered, no message appears on the console and no refresh takes place.
Otherwise the connection seems ok, and I get this message repeating every 3 seconds on the server side console:
[13/Aug/2018 11:35:25] "GET /kbfb/event/evdja/?channel=test HTTP/1.1" 200 2077
In the chrome browser I added some tracing messages to the reconnecting-eventsource.js and get this sequence of messages repeating on the client console:
ReconnectingEventSource.prototype._onopen
ReconnectingEventSource.prototype.onopen:open
ReconnectingEventSource.prototype._onerror
ReconnectingEventSource.prototype.onerror:error
This sequence is not changed when a server sent event is dispatched, and there is no evidence that the message is received at the client.
The event listener doesn't appear to be registered on the client, and the debug message inside the listener doesn't appear in the console trace, so I assume it not called.
Any tips on what I'm doing wrong, or how to debug this would be much appreciated.