GeoLocation based Communication with Node.js, Redis

Support this website by purchasing prints of my photographs! Check them out here.

Here's a fun project I worked on most of Sunday: | ephemeral demo

It is a chat app using Node.js, but with a twist. Messages are only viewable by people who are physically near you. This is a concept I've been trying to squeeze into my games for a long time. Location is determined using the HTML5 GeoLocation API (which is accurate on your phone, not-too-accurate on your laptop, and inexistant on your desktop).

When playing most MMO's, communication is limited to non-physical boundaries, e.g. everyone in your guild, everyone in the continent who wants to trade, everyone in the current map. But, what if you just entered a level on the west side? People on the east side of the level to the west can't hear you, even though they are technically adjacent. Yet, people on the far end of the map can hear you. Also, using /whisper commands to chat to a specific player never felt right easier. Imagine if you had to actually speak quieter, otherwise someone hiding nearby could eavesdrop. Wouldn't that be a fun dynamic?!

This application is a step towards that direction. Communication is based on geohashing, which are a really cool method for converting faces of spheres into hashes. As the length of the hash string increases, the accuracy of the location increases, much like a latitude or longitude number. However, this hash represents BOTH the latitude and the longitude. Check the article out if you're interested, this stuff is pretty sweet.

In Whisper, each message needs to have a loudness applied to it. People visiting the page are the member of several rooms, each one representing a geohash with a different level of accuracy. When sending a message, those messages are applied to a specific room. Moving around in the real world causes the socket to join and leave different rooms transparently to the user. The louder the message, the more generic the room, and the sooner the copy of the data stored in Redis expires (to prevent spam).

Unfortunately, people have to click a level for loudness. A version of this chat I built in PHP years ago would count the number of exclamation points at the end of the message and use that to determine loudness. I might roll that feature into this version as well.

There's still a bit left to do before the project is complete (check out the issues if you're curious). I feel it has a lot of promise, although it is a very simple concept and I feel it will be a fundamental building block for many applications of the future.

Thomas Hunter II Avatar

Thomas has contributed to dozens of enterprise Node.js services and has worked for a company dedicated to securing Node.js. He has spoken at several conferences on Node.js and JavaScript and is an O'Reilly published author.