A few months back I did a pairing session Chris Hunt and together we built a Node Chat app using the very convenient Getting Started Guide on Socket.io's doc page. We successfully completed the guide and deployed the app with minor hiccups.
Once a month here at work, we take part in a "hack day" where we can work on any project that is vaguely relevant to the business we are in or the company we work for. I took on the challenge to creating a new chat app and possibly implementing as a special feature at work.
One thing I noticed right after completing the app was the lack of user names displayed inline. While chatting with Chris on our app, it was easy to know which messages were not mine, but it would have been nice to know in case I needed to review the history.
Knowing the little node I knew I starting looking into the redis and socket.io-redis npm's and figure thats what I needed to save the username when prompted, but after a bit of time scaling the api and documentation it turned out it was only needed to save the printed chat messages for the session.
I was dissappointed when I did not find a blog post on the subject, but eventually found an old youtube video explaining exactly what I needed to know.
Each user can login with a session or socket and within each socket I needed to save their username. I was actually saving the username to late in the game and every message had the same user's name. I had to access the socket and save the username the same time as the message. Here is an example of the code:
*notice how I am prepending the chat name in the chat message while emitting the socket.
Here is the jQuery providing the chat in my view:
I create a new socket call to save my username that was collect from a javascript prompt and voila, the user's username got displayed each time they printed a message. I am pretty proud that I was able to complete and publish the chat app to heroku in time to present in our hack day presentation meeting.
*I made the dangerous decision of publicly displaying a chat to a projector screen.
As far as redis, I only need that to save the previous chat messages, which for the purpose of my feature, it is not needed. There is still work to be done on the front end and how it will be render to make it a new feature, but I am pretty proud of this little guy - My Chat App.
This is my personal blog and journey in learning a new skill, Web Developing. In only 7 months I made a career change into this field by dedicating 25(avg) hours a week in studying Ruby. #All words are my own, except the ones I copy and pasted.
Showing posts with label socket_io. Show all posts
Showing posts with label socket_io. Show all posts
Saturday, January 31, 2015
Friday, December 5, 2014
Pairing in node with a Healthy Hacker
I had the opportunity yesterday afternoon to pair with Chris Hunt, host of the new podcast Healthy Hacker. After listening to the "Growing as a Programmer" he made an interesting announcement that I have not yet heard anyone else do at his caliber of programming. He was offering free time to pair with him in 30min increments. I signed up rathe quickly after noticing a number of open spots.
At the time of signing up you have to put in a subject to pair on for the session; With me being really ambitious I chose a subject I had zero experience in, node.js's socket_io plugin. I planned on messing around with it prior, in hopes to add live chat to my Ruby Newbies page, but it didn't happen. I got extremely side tracked with learning Ember and updating my Chuych app.
My overall impression of pairing with an absolute stranger on a subject I had no knowledge on, was great. Not only did we finish the socket_io tutorial, we also got it pushed to heroku and tested it out live. I did the driving in the pairing, while Chris navigated through the documentation, which was extremely valuable in me learning. We did get hung up on pushing a node/express.js project to heroku, since both our experience were in Rails, but he was able to pin point in the docs how to update the server to the heroku environment variable.
I am actually pretty stoked to continue to work on this project on my own and implement it with the RubyNewbies things. Node is a new frontier for me and I hope to continue exploring the various plugins and frameworks associated with it. To view our code check it out here.
If you are interested in pairing with Chris, checkout his calendar and sign up soon, but there seem to be very limited spots available.
At the time of signing up you have to put in a subject to pair on for the session; With me being really ambitious I chose a subject I had zero experience in, node.js's socket_io plugin. I planned on messing around with it prior, in hopes to add live chat to my Ruby Newbies page, but it didn't happen. I got extremely side tracked with learning Ember and updating my Chuych app.
My overall impression of pairing with an absolute stranger on a subject I had no knowledge on, was great. Not only did we finish the socket_io tutorial, we also got it pushed to heroku and tested it out live. I did the driving in the pairing, while Chris navigated through the documentation, which was extremely valuable in me learning. We did get hung up on pushing a node/express.js project to heroku, since both our experience were in Rails, but he was able to pin point in the docs how to update the server to the heroku environment variable.
I am actually pretty stoked to continue to work on this project on my own and implement it with the RubyNewbies things. Node is a new frontier for me and I hope to continue exploring the various plugins and frameworks associated with it. To view our code check it out here.
If you are interested in pairing with Chris, checkout his calendar and sign up soon, but there seem to be very limited spots available.
Subscribe to:
Posts (Atom)



