I'm currently working on a project using Node.js and Socket.io and for the sockets, I use Redis as I subscribe to multiple channels.
The application signs a user in (Through an API -- Using OAuth) and what I basically want is to show is a list of people that are signed in (their avatar) but I'm struggling to work out how I would do this using the Redis server. I have tried to do this on connect but this does not work.
Can anyone recommend a way that I can do this effectively? Basically show the avatar of the user (or username) that are currently signed into the system.. It should be real-time so that's why I'm going down the socket direction.
Related
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.
I'm building a simple node app for broadcast messaging using socket.io. It will have 3 users at a time
user 1: Moderator (gets a stream of social media comments from various APIs, picks messages to send to user 2 and user 3)
user 2: Graphics (displays messages pushed from user 1 as graphics in OpenBroadcastSoftware)
user 3: Host (displays messages pushed from user one on an iPad (to field viewer questions)
This is all for realtime use, nothing needs to get saved or logged.
I know all the basics of sending and receiving socket.io messages.
My question is, for portability, I want to host this App on Heroku
If this was a single Free/Hobby dyno app, would I need any sort of backend like Redis? Or would it work as if i was hosting the app on a local server since there is only once instance?
This app is never going to have more than the 3 users described above, so I'm not looking to implement any scaling what-so-ever
Thanks!
No You don't. The websocket can work with just the app, tested it out.
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.
I am new to server-side development. I'm trying to learn by doing so I'm building an application with express on the server, mongodb as my database and angularjs with twitter bootstrap on the client-side.
I dont know if this is the most practical way but when thinking about how to implement messaging between users I thought of a mongodb model called Conversation with an id and an array of the ids of every user in the conversation and another array of strings that correspond to messages. And then add this model to my REST API.
But lets say all/some of the users in the conversation are online, why not benefit from socket.io. So how can i switch from this to real time chat? Does the interaction with mongodb occure exactly as explained and socket.io just notifies every online user that an interaction has occured? If yes, how? Or is it something else?
socket.io can send real time events to connected sockets, you can use a database for storing messages that are failed to deliver and for offline users.
also, you might want to use something like Redis for this as it has channels with subscribe and publish capabilities.
I'm building a web application that will allow team collaboration. That is, a user within a team will be able to edit shared data, and their edits should be pushed to other connected team members.
Are Socket.io rooms a reasonable way of achieving this?
i.e. (roughly speaking):
All connected team members will join the same room (dynamically created upon first team member connecting).
Any edits received by the
server will be broadcast to the room (in addition to being persisted,
etc).
On the client-side, any edits received will be used to update
the shared data displayed in the browser accordingly.
Obviously it will need to somehow handle simultaneous updates to the same data.
Does this seem like a reasonable approach?
Might I need to consider something more robust, such as having a Redis database to hold the shared data during an editing session (with it being 'flushed' to the persistant DB at regular intervals)?
All you need is Socket.IO (with RedisStore) and Express.js. With Socket.IO you can setup rooms and also limit the access per room to only users who are auth.
Using Redis you can make your app scale outside a process.
Useful links for you to read:
Handling Socket.IO, Express and sessions
Scaling Socket.IO
How to reuse redis connection in socket.io?
socket.io chat with private rooms
How to handle user and socket pairs with node.js + redis
Node.js, multi-threading and Socket.io