Can push notifications be done with AngularJS + Flask?

I have a Python / Flask backend and an Angular frontend for my site. There is a process on the backend that checks SQS for messages from time to time, and I want it to send a notification to the client, which can then update the Angular controller. What is the best way to do this in my existing technology?

+6
source share
2 answers

To be able to click on a client, you will have to implement some kind of web socket support. If you want to save it in python / flask, there is this tutorial on how to do this with gevent:

http://www.socketubs.org/2012/10/28/Websocket_with_flask_and_gevent.html

In this article, Jeffrey also mentions a SocketIO-compatible library for python / gevent, which may allow you to use the SocketIO client-side JS library called "gevent-socketio".

This can reduce the amount of work you have to do in terms of cross-browser compatibility, as SocketIO has already done a lot.

Here is a pretty good lesson on how to use SocketIO in AngularJS so that you can notify the AngularJS model when an event comes from SocketIO:

http://www.html5rocks.com/en/tutorials/frameworks/angular-websockets/

If you don't want to host the backend of a web socket, you can look at a hosted service such as PubNub or Pusher, and then integrate them into AngularJS as a service. You can communicate with these services through your Python application (when SQS notification occurs), and they will notify you of all connected clients.

+6
source

I know this is a bit late, but I did pretty much what you ask for (albeit without Angular).

As a result, I had a separate process running a websocket server called Autobahn that listens to redis pub / sub socket, the code here on github

This allows you to send push notifications to your clients from virtually anything that can access redis.

Therefore, when I want to post a message to all my connected clients, I just use redis as follows:

r = redis.Redis() r.publish('broadcasts', "SOME MESSAGE") 

So far, this has worked pretty well. Currently, I cannot send a push notification to a specific client. But if you have an authentication system or something to identify a specific user, you can associate this with open websites, and then you can send messages directly to a specific client :-)

Of course, you can use any websocket server or client (for example, socket.io or sock.js), but this works fine for me :-)

+2
source

Source: https://habr.com/ru/post/945443/


All Articles