Message app with node.js and socket.io - node.js

I am making a chat app with node.js and socket.io and need to save messages sent so anybody who did not see the chat can see it if they log on later. I only want the messages to be saved for 5 hours. Any Ideas

A possible solution is using Redis. Here is a client for node from GitHub.

Related

How could i send notfication app to web in node js i am new to nodejs please if you can

i have to send a notification on web when a event occurs on app
Assuming you are using ReactJS, you need to use WebSockets. Check this tutorial on how to achieve that.
If the event dispatches from server, you can use Socket.IO, but if there is no hurry in getting notifications you can request in AJAX form every (for example) 5 minutes from client side code, to check if there are any notifs or not.

Socket.io handle online/offline status

I've a real time chat application i've implemented it using socket.io, nodejs and angularJS but i'm having issues while handling the online/offline status. I'm not clear on how to know when the user is online or offline. What i thought is hitting a api in every 3 seconds and update the online/offline status in the database but i don't feel it's a good way so is there any better way to handle it?
Thanks in advance!
Here is the link to my backend code.
DesktopChat-Backend
You don't need to hit every 3 seconds , socket.io do this automatically, so you have just to handle it inside on. ('connection') and on.('disconnect'), so you get the user connected or disconnected then you broadcast the information to the clients, and update their status.
Look at this example :
Showing online users using Nodejs and Socket.io and angular js
One-to-One-Chat-using-Node.js-Socket-IO-Library
you can make map, where your userId will be associated with all socket.io client ids for this user. Then you can just look into this map, if specific user has some open connections.

How to implement Laravel, node.js, socket.io and redis for creating realtime chat/notifications with database

I spend already 3 days for reading, watching tutorials about WebSockets, socket.io, node.js and so on.
Basically, I'm a Laravel developer and have just a basic idea about all the rest components.
With regret, after these 3 days I don't have in mind all logic step-by-step of implementing this architecture. I will try to explain what did I understand and you please correct me.
So :
WebSockets - is a bidirectional continuous connection between client and server. It uses another port, and basically it is not a HTTP/S connection.
For making this kind of app like I said, we need one more server, and idk why, but this is Node.js. At this Node.js server we should install socket.io (server-side package) and Redis.
Then, we need to add client-side socket.io (via CDN probably).
At Node.js server we are creating a server.js file where require all modules that we need, like socket.io and Redis. We open a connection for a specific non-used port (as 6001). Then we run this node server.
At front-end we are subscribe-ing to this channel and define method for emitting and listening to the server.
Example :
User1 is connecting to a specific route. User2 as well. User1 type a message for User2, when press Submit, message from User1 is sent to Node.js server, where it is sent in Redis(yes? if yes - Why?), and then Node.js is listening for what to do in this case, and send this message to specific user, or with broadcast to all users except the publisher.
Oh, it's even hard to explain that, too much steps and tehcnologies used.
Can please someone correct my logic? I really want to understand all that process and logic of using this components. Or please, give me some useful articles and videos, may be I didn't saw them. Thanks!
I suggest you read the official docs on how to build chat. Basically what you will have in the end is 2 servers, 1 for your Laravel app and the other for chat (Socket.io) . The key to this is using broadcasters and listening for events on both sides, frontend and backend.
Events are broadcast over "channels", which may be specified as public or private. Any visitor to your application may subscribe to a public channel without any authentication or authorization; however, in order to subscribe to a private channel, a user must be authenticated and authorized to listen on that channel.

Send Notification to dashbord app When New order is created in Database using Nodejs

Commerce web app. i want to send notification to be showed in dashboard when new order is created.how can i achieve this using MEAN stack (mongodb express angular and node). can i do this using socket.io. what is procedure to be followed.
You are correct in looking towards socket.io. Socket.io will allow you to do this very easily.
Frankly, you should be able to read the tutorial linked below and know what you need to do, as notifications are probably the easiest thing you could do with socket.io.
http://socket.io/get-started/chat/
Basically what you'd want to do is have your clients listen for an event from socket. You'll emit the event from socket when a new order is created.

Is it possible to connect Node.js and RED5?

I have the following problem.
I have a chat developed with ActionScript3 (AS3), SharedObjects (SO) and RED5. Well, this works correctly. Now, I'm developing a chat using Node.js, and this works correctly too.
My question/problem is how can I connect these 2 chats. Is it possible to send messages between Node.js and RED5? I want that one user that is chatting using Node.js chat and another user that is chatting using RED5 chat, can chat together.
Someone knows some solution? It's possible?
You need to code some server side servlet in Java to proxy your Node.js messages to and from the red5 chat.
Are you familiar with the Red5 API and have some understanding of the Java Servlet Container ? Cause you will need that to implement a solution.
Red5 is a server side technology that runs in the Tomcat Servlet Container. Propably Node.js could send a message to red5 via a simple servlet, that will then forward the message to all connected clients.
The other way round you could catch all chat messages on Red5 server side and then forward the messages to Node.js (however I don't know what incoming message receiver's you can code in Node.js).
Sebastian

Resources