Display users online use websocket, aws - amazon-web-services

I am doing the function of displaying users who are online using websocket. I follow here: https://github.com/aws-samples/simple-websockets-chat-app I've done successfully. It will create 3 lambda function: onConnect, sendMess, onDisconnect. Receiving and sending messages to all clients is ok. If a user accesses the website, will send that user data(name, avatar..) to the server.
But I currently don't know how to handle connect and disconnect on the server with that data. How to send message from server to all client when a client disconnect. Hope you can teach me. Thank you very much.

Related

How can I make a client server show updated data without send request?

I design a application for a restaurant one of the features is that the user can make an order online and the oreder status is pending until the restaurant cashier or restaurant admin staff convert status by accept or refuse
so i wanna send to client a notification if there is pending orders or something that the admin staff or cashier know that there is an pending order created now without need to update or refresh the client page
so my question is how i make a backend server send to client browser notification without the client need to refresh the page or send request to backend server
i use django rest framework
I hear about websocket and Django channels
Also i hear about SSE
Also i read about client freamwork send requests every n minute to update the page
I need to know what the best approach to implement this and if there is another technology and what is best for server if there is a lot of loading or the application used by millions of users
For example - you can implementig full-state service on nodejs + express + socket.io or asp.net + signalR. Client connecting to your service via websocket if customer open page where there order status. This solution will allow scale only service if connecting many client, also you should think over communication between service and general app on django, for example use rabbit or kafka or other. Also your can use this service for new realtime features

SvelteKit how to handle authenticated WebSocket connections

I have a Django backend that accepts WebSocket connections under a given url. The url takes a JWT token as parameter to authenticate users trying to use a certain websocket.
I'm trying to connect to a WebSocket from my SvelteKit frontend. The problem I'm having is that I can only access the Http-Only cookies containing my access & refresh key from within my +page.server.ts endpoint files. How would I go about authenticating the connection while also establishing a connection from the client side to access messages being sent via the WebSocket?
Currently I've been following this tutorial using a custom vite plugin as well as socket.io but it doesn't seem to be trying to achieve what I'm trying to work towards.
Any help, code samples and ideas on how to handle this problem would be very appreciated!

Qt Authentication users with QTcpServer (with username and password)

I want to write a chat program with login page.
I want to send request from client to server with username and password, then server receives, verifies and then responds to client.
Can anyone please guide me of what QT class should I use or can tell me some ideas of how to access them?
With QTcpServer, you can set up authentication for client with some basic username:password pair at the start. As soon as the connection is established, ask or wait for the username:password to be sent over to the Server. Verify it. In case of invalid data or timeout, close the connection.
As far as the login page is concerned, you need to host that on the Server and you'll be dealing in HTTP protocol instead of TCP. Take a look at QHttp. That'll get you started.
For Qt, there are other options too. You just have to lay down your requirements and find the one that might fulfill those e.g. Wt.

Sending SQL emails using AWS and SES

I hope someone will be able to help me with this since I am new with AWS stuff.
I have a Web App using .NET MVC which will be deployed/hosted in AWS. This is the description of what I would like to achieve:
1- Let's say that the Web App will insert products in a Products Table on SQL Server.
2- When this product is inserted, the system (AWS) will send an email to a Client from a Clients Table on SQL Server.
Is that possible with AWS?
Could I set a trigger in SQL Server and send an email by SES?
Is it better to use SQS?. So the Web App will publish messages in SQS, and then having another app listening and sending those emails, for instance a console app.
I will appreciate any direction or useful link.
Thanks all of you in advance.
The answer to your first question is 'yes'. Yes SQL server can use SES to send emails. Because SQL server can send emails, all you need to do is set it up to use the correct SMTP settings from SES once your account is verified and working with SES.
That said, I would never have my db server send emails, just doesn't seem like the right place to do it; even though you can.
I have developed and support several systems like this, and the usual pattern I use is to have the web application insert a message in an SQS queue that will be used as input to another process to send the email out. When possible I like to include all the details about the email into the SQS message, i.e. from, to, subject and the body - everything the downstream process will need to know to send them out.
In my case I use a windows service running on several EC2 instances in an autoscale group to poll the queue and send the emails out. In most cases, where I was able to store all the emails in the SQS body, the windows service is completely general purpose - it reads an SQS message, composes the email and sends it out. Because all of the details of the email are within the SQS message body, this single SQS queue and the windows service that is processing it, can process emails from a variety of applications because the service doesn't need to contain any business logic specific to the application and has no external dependencies.
As you talk about separation of responsibilities, I can't see anything less indicated to send email than a db server (even if it can do it).Sending emails is a task for your business layer, surely not for the data layer.
Use the web app to trigger the process of sending the emails, than implement it directly into the web app, or separate it with a messaging system (like SNS), with a queue system (like SQS) or whatever else.

implementing stackoverflow's notification system with django

I've seen questions like Notify panel similar to stackoverflow's. It talks about the client side of the implementation.
I'm looking for the information about the server part and the networking part (how client get notified real time)
A user scenario might look like this:
something happens for user-a
server creates a message for user-a in DB (for persistance) : I'm using django-activity-stream for this
server sends (new or last 10) messages to user-a's browser (when user-a logs in or when event happens)
browser displays the message (Notify panel similar to stackoverflow's part)
if user acknowledges the message(clicking the inbox in SO), all the unseen messages are marked as read and recorded in server
I have questions on the following steps.
(3) Not sure but https://github.com/stephenmcd/django-socketio could be used.
(4) The answer to the question says client has the json data received from server.
Does server send messages to user for every request?
Does client check local storage(I'm new-to-web, what's a good local storage for this purpose?) and request the json data if he doesn't have them in the local storage?
(5) How should I implement this seen and unseen? django-activity-stream doesn't have notion of them.
This can easily be implemented by using django-channels.Because you need websockets to have a two way client server communication.
Showing notifications is a two way communication. Server notifies the client that a new notification available. The client shows this notification to the user, and then when a user interacts with the notification, the client notifies the server that notification was read, so the next time user loads a page, only unread notifications are shown.
There are some steps involved.
Your server needs to be able to support websocket communication. django-channel converts the application to ASGI.
Create a websocket consumer that can send and receive messages to a websocket.
When user opens the application, the client creates a websocket connection channel to the server.
Whenever a new notification needs to be sent, the server will send the message to the channel.
On receiving the message, the client renders the notification on the webpage using Javascript. Like showing the new message icon, appending the new message to the list of messages, etc.
Now, one part is done. Your user has been notified. Coming to the second part.
User sees the bell icon or whatever, and click on it, he sees the notification details (this was rendered by the js, when client received a message).
User clicks on the notification/bell icon. At this time, the client will send a notification back to the server, so that server can update what all notifications were read.
I created an app that updates the client when a new message is to be shown. Github link.
You can also refer to a similar question: https://stackoverflow.com/a/55656848/4186008