I found this excellent example on Chrome Desktop Notification - Chrome desktop notification example?
I am able to create the Desktop Notification by clicking a button.
However, that is pretty front-end.
I would like to find out how to link an event in the web app. For example, the event could be someone posting a job for a freelance work. And user who is logged into the web app but not actively browsing on the web page will be notified via the Chrome Desktop Notification.
Are there any examples of how I can create a Event Handler to listen to data in the backend, and prompt the user via the Desktop Notification?
Many thanks!
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c162fe08-81fa-4a25-aa55-30bd2821ce2b%40googlegroups.com.--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/64rg0i9ChyY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
var myEventSource = new EventSource('/path/to/eventsource/');
myEventSource.onmessage = function(e) {
console.log(e.data)
}
def eventsource(request):
last_id = request.META.get('HTTP_LAST_EVENT_ID')
id, data = get_new_data() # somehow wait for some new data, and timeout after 10-50 seconds.
if not data:
return HttpResponse('', content_type='text/event-stream')
assert '\n\n' not in data, 'two line breaks in a row signifies an end of message'
return HttpResponse('id: %s\ndata: %s' % (id, data), content_type='text/event-stream')