Direct Message to online users in MeteorJS - javascript

In a chat application, I want to be able to send messages to two users directly if there are online. I'm using mizzao:user-status to detect if they are online or not. Let's imagine 2 users Tom and Sam. So both are online and using the application. Now when Tom sends a mesaage to Sam and vice-versa, I want to send the message directly to Sam without first storing it in MongoDB through Web Sockets. Meteor Streams seemed like a viable option, but here's the problem. Let's say 1000 people are using the app all at once. Now some people can send only their friends messages. How do I ensure security so Sam can't edit some source files and read everyone's messages going through the wire.
Thanks.

When I was doing my chat app I didn't use any streams, since Meteor is reactive I just stored all messages in a Collection, and find() was returning data, no packages were needed.
If I wanted to send data to users, I simply fetch() users who are online(with mizzao:user-status aswell), and then sent message to all of them using .forEach

Related

AWS SNS with FMC for SMS

I am developing a React native application where I want to sent an SMS for OTP. I used AWS SNS for publishing messages after subscribing them to a topic, but I found that the price is quite high since the SMS is transactional.
I wanted to use Firebase Messaging Cloud since they do it for free but I don't really know how to proceed with it. Do I have to createPlatformApplication and then do createPlatformEndpoint for every user to send messages? This is a bit confusing for me, so if someone could give me an overview of the initial processes, it would do me wonders.
This is how I am doing it now simply using subscribe and publish:
I understood your question as asking how you could deliver OTP codes using push notifications.
To do that, you would:
Set up a platform application through SNS: https://docs.aws.amazon.com/sns/latest/dg/mobile-push-send-register.html
Create an endpoint for each end device you want to send these notifications to: https://docs.aws.amazon.com/sns/latest/dg/mobile-platform-endpoint.html
Do a direct publish to that endpoint to send the notification only to that person: https://docs.aws.amazon.com/sns/latest/dg/mobile-push-send-directmobile.html
For this use case, you do not need to use topics and subscriptions, since all of your messages will only be targeting one person.

RabbitMQ send messages to users on website

I am trying to use RabbitMQ to send messages to users on a website. While I know how to communicate between different scripts I can't find anything about how I can get a new user to recieve messages.
Let's take chapter 1 of the tutorial as example: https://www.rabbitmq.com/tutorials/tutorial-one-python.html
How would I be able to send "Hello World" to a user on my website and be displayed in the console? Would it even be possible using python?
Try using the RabbitMQ Web-STOMP plugin: https://www.rabbitmq.com/web-stomp.html
You wouldn't use RabbitMQ for that. It's for communication between different services in your back end, not for sending messages between arbitrary users on your front end.

Send message to thin clients trough angularJS

I have a web application developed with angularJS. There is a form where workplace accidents are saved to the database. When a new record is saved I need to send information to all the computers on the network. Most of them are thin clients related to a terminal server. My web application won't be running ot the clients. Only an alert/message should be shown there, like "New accident was recorded.".
I couldn't find which technology should I use. Any suggestions please?
Thank you in advance!
Regards
There has to be server part of the application that takes care of saving data to database. In that function which saves data, at the end you could create a mailing list of target users (or predefined group of receivers) and create a mail that will be sent with message you want em to receive.
Popping message boxes on network computers is far from any practical solution.
So you don't need any special technology, you already have all you need.
Thanks for the answer Mladen!
I already have a function sending mail to some predefined users. But there are a lot of client machines in which can't send/receive mails... So I have to warn them in some other way.
I'm researching now node.js child_process spawn in order to run command prompt. But couldn't figure out yet how to use node.js.
Thank you again!
Edit: For those who search a similar solution:
With the following line I managed to pop up a message on my computer from javaScript:
java.lang.Runtime.getRuntime().exec("cmd /c msg userID msg_text");
But that is not exactly what I need. I will write here again when I find the solution.

Node js redis socket.io pubsub realtime updates

Hi I am building a "Twitter clone" for my school project.
I want to implement a publish subscribe pattern for realtime updates.
Users can "follow" other users
When a user is online, and a "follower" posts a new message, the user should get a realtime notification.
I am using Node.js, Socket.io, Redis and MySql as database provider. Should I use a message queue, and whatfor are people using message queue's?
Thanks for help and answers
Update
The problem is not there when you are small. But when you get big the fanout(forwarding message to all followers is going to be expensive and you want to do this offline using a MQ. Like twitter you store all active tweets in memory. When a tweet is posted you put(set) that tweet in memory #key(unique). You could use something like Twitter's snowflake for that.
Next the fanout process happens. For every user you need to put that unique key(tweet id) in their list so that they can retrieve the tweets from memory. When your site is small I guess you could do this without a message queue, but when you need to distribute a message from a user like for example scoble with 274,776 followers and who tweets a lot this can get pretty expensive.
A lot of users are offline so these tweets do not need to get delivered to the user immediately. You design your system like this because you need to keep everything in memory. I think that is the only way to do this effectively.
You should use a MQ just like twitter does. They have even open-sourced their own MQ: Kestrel. The High Scalability blog has a really interesting article: Scaling Twitter: Making Twitter 10000 Percent Faster. I advice you to study at least hot articles at High Scalability blog to learn how the big players scale their website. Some other links explaining how Twitter scales:
http://highscalability.com/blog/2009/10/13/why-are-facebook-digg-and-twitter-so-hard-to-scale.html
http://highscalability.com/blog/2011/12/19/how-twitter-stores-250-million-tweets-a-day-using-mysql.html
http://highscalability.com/blog/2009/4/20/some-things-about-memcached-from-a-twitter-software-develope.html
I also assume you have read:
http://redis.io/topics/twitter-clone
Also I would have a look at all the projects Twitter has open-sourced:
https://github.com/twitter
I would have a look at the popular MQs like for example:
Redis
Beanstalkd
Gearman.
I recently worked on a similar use case, and I used nodejs, socketio and redis pubsub.
The code is available at https://github.com/roshansingh/realtime-notifications.
Now coming back to your questions:
Users can "follow" other users
When a user is online, and a "follower" posts a new message, the user should get a realtime notification.
You can achieve both by creating rooms using socketio and a channel with same name in redis pubsub.
The flow can be something like this:
You can make user join socketio rooms(say John, Dan etc) as soon as they login for which you will save all their subscribed rooms in database. And that the same time you will subscribe to redis pubsub with these channel names (like John). These updates when received can then be broadcasted to the rooms, and hence to all the online users.
You will have to publish John's activities on the same channel name(John) to redis.
Please read the code on the link pasted above. Let me know if you need any help.

Implementing web chat, how do I get typing status?

Can someone illustrate how I can get typing status of the other party with JavaScript?
UPDATE
Can someone recommend a one-to-one open source chatting application, preferably written in PHP? I only found open source chatting rooms which are for chatting among all onliners, but I just need a one-to-one chatting.
Here are a list of PHP-based open-source instant messaging software.
Some of those might be relevant for you.
For example, if you had an text area #chat then you could use this code to attach the event:
document.getElementById('chat').addEventListener('keydown', FUNCTION HERE, false);
See http streaming and some ready solutions here: http://ajaxpatterns.org/HTTP_Streaming
this is how google talk does it. And there are ready php or c++ solutions
It was quie a discovery for me!
This is an update to reflect the significant change in the OP's question:
Google Chat and Facebook both use XMPP(jabber) servers, as do most companies I know of that have internal instant messaging.
The nice part about XMPP is that you get all of the "is typing" and other presence-based information without having to roll-your-own in javascript (bear in mind, you will still need to use javascript to pass XMPP requests back to the server, but XMPP has most of the features you'd need already built in).
Check out OpenFire. It's a great XMPP server, totally open source, and they have a web-based version of their Spark client that is pretty nice.
Or you could get a PHP library for XMPP (there are a few). But you'd still need to have the XMPP server running in the background for PHP to work with.
Here's a list of XMPP libraries for PHP from XMPP.org:
Eiffel
JAXL
Lightr
Missus
xmpphp
Or, if you want to keep things mostly browser-side, they also have a list of libraries for javascript:
dojox.xmpp
js.io
JSJaC
strophe.js
xmpp4gwt
xmpp4js
I made a small chat application a while ago, and the only way to do it is to frequently check for new entries in the chat database and fetch anything newer than the last displayed message. At the same time as all that, you can check to see if the user's input is empty. If it is, do nothing. If it isn't, enter a status code into the database beside that user's name. If anyone has that status in the database when you're fetching information about new messages and who is online, you should display the 'user is typing' message. I hope that makes sense...let me know if it isn't.
For User1: If you save the chat message on each key-press to the database, with a status: sent=false and update the last updated date.
For User2: you could pole periodically for the presence of a message where sent=false and use the last updated to update user is typing message. if the lastupdated date is more than a say ten seconds you could remove the message as that person may have stopped typing. This will allow User2 to see User1 typing, stopping and continueing again.
Ideally polling for this information will be part of an existing call to the database to reduce additional overhead.

Categories

Resources