This article is part of our series of tutorials ‘Building Realtime Applications’, updated on a regular basis.

Let’s say you’re working remote, but – alas – alone and out of the loop, you want to see who’s in the office right now. Maybe a storm has hit your project, or maybe you just want to see the kind faces of friends who now seem very, very far away. “Who’s in the office?”, you say to yourself, pacing your living room. Who indeed?

Well thanks to this new application, you can now find out in realtime!

What Is It?

‘Who’s In?’ is a very simple app that tracks live who comes and goes from work. It’s built from a local script that runs from the office and a free Heroku application. The script and the Heroku app chat to each other every couple of minutes to keep track of who’s in the office.

And the best part about it? It takes less than five minutes to set up.

Sped Up Comings And Goings

Wow! How Do I Set It Up?

For ease of use, we’ve created a very easy command-line interface that helps your office set up its own ‘Who’s In?’. Type this into your terminal:

  $ gem install pusher-whos-in
  $ pusher-whos-in init

The first command installs a gem that both initializes deployment and sets up a binary executable that scans your local network. The second command, when entered, should take you to the deployment page on Heroku.

Heroku deployment page

All you have to do is: name your app, choose the ‘United States’ region option, then click the shiny ‘Deploy For Free’ button.

This will set up your very own Heroku application, provisioned with a free Mongo database and a free Pusher add-on.

Now view your app and add some users. Simply enter their name and MAC and email addresses. ‘Who’s In’ will use the MAC addresses to identify whether your colleague is knocking about on your local network, and use their email address to fetch their gravatar.

Adding Users

And here’s the final step:

  $ pusher-whos-in run _your_app_name_

If your Heroku URL is mcdiddys-peeps.herokuapp.com, then type pusher-whos-in run mcdiddys-peeps. As this script requires root privileges, enter your password. (This will be explained further below).

The moment of truth! Go back to your app and you should see the page populated with some much-missed faces – opaque if they’re in, transparent if not.

So that Pusher’s Sandbox limits are not encroached upon, this page updates only every two minutes.

Furthermore, if you don’t wish to use the gem, or if you only want to run the app locally, you use the simple steps documented here.

How Does It Work, Then?

The pusher-whos-in run command runs a script every two minutes. This script uses NMap, which normally is used as a security scanner to discover hosts on a local network (thus requiring root privileges), to scan for MAC addresses.

  macs=( $(sudo nmap -sn 192.168.1.0/24 | grep -Eio "([0-9A-F]{2}:){5}[0-9A-F]{2}") )

The script then process the $macs array into JSON, and posts it to the Sinatra server running on Heroku. To do so, it uses your Heroku Pusher keys for Basic Authentication, having got them from your Heroku instance with the Pusher add-on.

  curl -X POST -d "$json" $WHOSIN_URL -u admin:$AUTH_KEY >/dev/null 2>&1
  # N.B. Outside the purposes of this demo, one should never post from a privileged script(!)

The server then goes through the users in MongoDB, and sets present to true or false depending on whether their known MAC address was present in the posted list.

Then it triggers a simple Pusher event to the client, carrying all the people JSON objects stored in the database:

  Pusher['people_channel'].trigger('people_event', people)

On the front-end, as it’s my framework of choice, I used AngularJS with the new Pusher-Angular library to take the people and assign them to scope:


angular.module('WhosIn', ['pusher-angular']).controller('AppCtrl', function($scope, $pusher, $http){ var client = new Pusher(pusherKey); var pusher = $pusher(client); var peopleChannel = pusher.subscribe('people_channel'); peopleChannel.bind('people_event', function(data){ $scope.people = data; }); });

Then using HTML, CSS and Angular {{expressions}} we can render everyone on the page, along with their gravatars and when they were last seen.

Can I Make It Better?

Absolutely, and we encourage you to!

We acknowledge that this is merely one of many ways you can show who’s in the office. If you can think of a better way, feel more than free to fork our Github repo and send us a pull request.

Here are some other ways you might improve on our app:

  • Integrate it with HipChat and Slack. Perhaps you could create a bot to reply with the list of people present in the office?
  • Tighten security. You could perhaps do this by easily introducing private channels to your Pusher connections, or by creating a workaround that skips the need to HTTP post from a privileged script.
  • Play with the UI.
  • Create logs and visualisations of who comes and goes.

No doubt you have plenty ideas of your own – so, now we’ll leave it to you!

For more about building realtime applications, check out our tutorials library, updated on a regular basis.
  • This is cool Jamie!

    We actually created an entire application around a similar concept of connecting remote workers with presence and included multi-party video and text chat too. We also use pusher on our backend to achieve this! Give it a try :)

    https://www.sqwiggle.com

    • Daniel Scholtus

      This is a very legitimate advertising comment.
      But I love sqwiggle, so kudos!

  • We made something we called Presence almost 2 years back, and we still use it in our lab. It does the same thing (mac address collection, but we use multiple sensors for it: wifi, lan, and bluetooth). Every person has identities, and we have a lot of data, which we correlate for some fun stats. Here’s a screenshot as well: https://imgur.com/5kEDw0e

    • Guest

      Screenshot didn’t upload in last comment.

  • Jorge Andrade

    ooohh!! that´s amazing!

  • John

    Hi,

    I have just installed on heroku using the github script, but the application seems to be having some issues with gravatar-ultimate (I’m seeing this in the console: https://people-whos-in.herokuapp.com/%7B%7Bperson.gravatar%7D%7D Failed to load resource: the server responded with a status of 404 (Not Found))

    Any ideas on how to resolve this?

    • Jamie

      Hi John,

      Ah! That’s just an initial error as the CSS is trying to load in the hexagons’ background images before any have rendered. It shouldn’t affect the functionality of the application. Is everything going smoothly besides this?

      Awesome that you’re trying this out! Let me know how you get on.

      • John

        Unfortunately the app does not display any hexagons after I try to add a user. You can see for yourself: https://people-whos-in.herokuapp.com/ try to add a user, and they won’t show up :(

        • Jamie

          Ah they just appeared! It’s only when you start triggering do they appear – I’ll make it so that people are always on-screen soon, for sure. Really appreciate the feedback!

          • John

            Sasha is in, I will set up a new instance that doesn’t have all the duplicates, but it will use the same url as above, is there any way to delete a user, or do I just need to go into the database and manually delete?

          • Jamie

            Currently not, as I just wanted to make a proof of concept for now. At the moment you can just go into your Heroku console and delete from there. But I’ll add a delete button asap, for sure

          • John

            Great. Have removed the duplicates, so feel free to do whatever you want on that instance. Let me know if you update it, as I would like to get a working version before I try to tie it in with our phone system ;)

  • Good info. Lucky me I came across your blog by chance (stumbleupon).
    I have book-marked it for later!

    Feel free to visit my site :: Jacksonville SEO company

  • Winter travel can be quite a fun experience as long as you take
    the proper precautions. These come in variations, colors, and sizes.
    Who knows once your likely to come with an emergency,
    and a charged phone is crucial. This is beneficial when you’re on the highway
    driving to whichever destination. Educate kids simply how much
    you really care and love for them.

  • People who mentally picture an ideal catch
    to get a touchdown become better sportsmen. In the end you have to exert more effort to make it work.
    If you are going to try and slim down, good for you and all the best.

  • Finally the end stage of the cycle of recurrent herpes labialis
    happens. Flu sore frequently is painful, as a result of blisters and local swelling.
    This may provide immediate respite from the signs and symptoms of herpes.

  • The motto is usually to build your website effective-it should bring dollars in,
    not merely adorn the net world. Also, some contains provide site templates at no cost on their customers.

    After the afternoon your small business can’t survive without customers.
    Professionals contain the experience required to produce a site which is both functional and visually appealing.

  • However things does not always have to be this way.

    And moet likely, they are land line information only.

    Thanks to the growth iin mobile andd communications technology, huge online databases store millions of numbers and related
    information.

  • These following improvements makes the knowledge enjoyable
    for those. Lots of people use Firefox and post topics the links appear as inactive.
    I remember when i beat the drum against those who’d impinge on our civil
    rights. I’m not sure in regards to the wisdom of trusting someone to not
    break the law once they curently have broken what the law states.
    The 2 then provide an awkward lunch with Cuddy and Lucas.

  • Hello dear visitor. I’m Caitlin Goetsch. To pay a
    visit to ballet is a product I by no means give up.
    Utah is where my property is. In his professional life he is a
    payroll clerk. See what’s new on my website here: http://blackhat.community/forums/

  • Howdy just wanted to give you a quick heads up.
    The text in your article seem to be running off the screen in Chrome.
    I’m not sure if this is a formatting issue or something to do with web browser compatibility but I thought I’d post to let you know.
    The design look great though! Hope you get the problem fixed soon. Kudos

  • The more important the page, car loans generally it will listed.
    As a result the composition of the article much easier as you progress.

    The affiliate can earn some residual income by simply placing an advertisement on its website.
    Should it be a client, friend or supplier, it doesn’t
    hurt to compel. Amounts to you is stop teetering as well as obtain on with the wine.

  • Hello! I’ve been following your weblog for some time now and finally got the courage to go ahead and give you a shout
    out from Humble Texas! Just wanted to say keep up the good
    job!

  • However, some parents consider saving money by not hiring a agency.
    Drinking, which leads to misjudging speed or distance is
    a known regarding accidents. You can also ready your finances better.
    Personal injury claims could be a nightmare to along with if you
    don’t have insurance to cover yourself for anything you do to you have.
    This shows the player have confidence in their abilities.

  • art

    Confused about using eBay’s classifieds format?
    She pointed the car south for the 20-minute holiday getaway.

    It will come from a unique place it really is covered in diamonds.

    The Ash shoes and boots accumulating have all of it.
    Some within the best first dates perfect have, are the ones where require speak about your backgrounds, your lives, your jobs, or anything that way.

  • Hello dear visitor. I am Art an individual can call me anything you like.
    The thing she adores most is to act but she is struggling
    in order to time get rid of. Mississippi has always been his
    living place. Credit authorising is the way she makes a living but soon her husband and her
    start their own home based business. I’m not good at webdesign we might in order to be check my website:
    http://tutorialdl.com/

  • I think this is among the most significant
    info for me. And i am glad reading your article. But should remark on few general things, The web site style is wonderful, the articles is really
    great : D. Good job, cheers

  • And if you return guide is designed to on time, no service charge!
    The simplest limitation Apple puts on people may be the hardware these people can choose from.
    School administrators are bothered regarding this problem.
    Apple’s marketing is phenomenal, making everything they’ve
    got look hip and cool down. Synthetic this could be utterly fascinating to watch operate.
    The common answer is surely a “Cell phone”.

  • Grover Keefer is my name hence there is no think appears
    a little bit quite good when you say the idea. The thing he adores
    most is researching cryptography and now he has time to consider
    new things. Indiana is where my home is and I am plan on changing
    out. In my professional life I am an accounting officer for doing pretty good financially.

    If you want to find out more away my website: http://myphambanbuon.vn/

  • Being the actual part about this let you know would enter cast i
    for almost kind behind acting circumstance I longed for in the future.
    As most of the Globe add it, “Rather than assets its the vast majority vulnerable members, the Chapel had long been putting them all in harm’s way” (Boston Globe, 3).

  • I seriously love your site.. Excellent colors & theme. Did you make this web site yourself? Please reply back as I’m wantring to reate my own personal blog and would love to learn where you gott this from or juswt what the theme is named. Cheers!

  • It is further down the line that needs more attention,
    especially bearing in mind that the execution of the policies which relate to domestic banking systems
    and aggregate demand management will be in the hands of the national governments,
    with a degree of shared sovereignty. First you will have to visit your state’s department of motor vehicles or department of
    public safety to know the procedure to sell a ca without a
    title. * Has filed accounts at Companies House
    for at least two years.

  • gucci brown flats
    gucci shoes on sale http://www.butitta.com/gucci-shoes.asp

  • We absolutely love your blog and find the majority of
    your post’s to be just what I’m looking for. Would you offer guest
    writers to write content for you? I wouldn’t mind publishing a post or elaborating on many of the subjects you write regarding here.
    Again, awesome blog!

    my web-site … garcinia cambogia best brand

  • Jayden Lawson

    Thanks for the simple tutorial! However – every time I try and run pusher-whos-in *my-app-name* – it says “invalid command. Use –help for more information”.

    What am I missing? I have set up my new app at heroku twice, and have entered two staff member’s details on the website. FYI – the web interface for my app wouldn’t work in the latest version of Chrome on the Mac. Looks like the attached, and neither icon reacts to a click.

    It does work in Safari though, but after I enter the details and safe, the modal window just disappears and I’m back to the one “add user” icon. Is that what’s supposed to happen?

About Jamie Patel

Jamie is one of Pusher's Growth Engineers, and loves playing with new technology and working some realtime magic on them. Originally a literature graduate and founder of two magazines, he enjoys exploring the creative side of coding and is continually looking to learn new things.