I've been following Meteor since the anouncements early last year, and recently I decided to get a better grasp of the framework and practices by writing a Smart Package for the ecosystem.
Smart packages are not yet an official part of Meteor, but they are an active part of the ecosystem - thanks to Atmosphere and Meteorite - I recommend you check it out. While you're on the path, you can also learn about how to use NPM with Meteor on John Kats' blog.
The Interface
The initial goal was to enable someone to add rooms / lobby / queueing / messaging to their app with a few lines of code. I got this idea from how Meteor implements user auth / registration in their apps. Here's how they do it:
{{ loginButtons }}
Yep. That's it.
The above is (basically) how you add user auth to your app. Given the fact that a dev may not want to show the lobby, or allow people to create rooms (they handle it on the back end), I figured I'd need to offer a little more control for what they show.
With those constraints, the following was my objective for an interface:
Since the templates needed to be modular - I couldn't rely on just using the regular syntax of Template.[templateName].[helperFunction].
Instead I created my own - and I'm glad I did. For example, here's the bit of code backing the {{ roomsList }} template:
Handlebars.registerHelper('roomsList', function(){ var roomsInList = Rooms.find({}).fetch(); var res = '<div class="roomList">'; for (var i = 0; i < roomsInList.length; i++) { res = res + '<div class="listedRoom">' + '<span class="listedRoomName">' + roomsInList[i].name + '</span>' + '<span class="listedRoomCount">' + roomsInList[i].users.length + ' user(s)' + '</span>' + '<button id="' + roomsInList[i]._id + '" class="button joinRoom">' + 'Join' + '</button>' + '</div>'; } res = res + '</div>'; return new Handlebars.SafeString(res); });
Using Heartbeats
Another issue I ran into was removing users from the system when they closed the browser window without explicitly leaving their room.
The solution I used was a heartbeat timer. In essence, when someone entered a room I'd have the client start pinging the server at a heartbeat interval. When the ping stopped, and the time on the server passed a certain point, I removed the user and assumed they'd left.
How to Create & Test
The best reource I found when creating my package was Tyler Johnson's blog post on the topic.
Also, the README for my smart package walks you through how to set up a Meteorite-managed application.
Unexpected Issues
Surprisingly, some of the largest challenges I faced came when pushing updates to the package on Atmosphere. After the initial release, I fixed a few bugs and went to update things. But after several hours and trying everything I (and Google) could think of, my update still wasn't pushing.
I'm asking around, and as soon as I get the problem solved, I'll post what I learned.
Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
✓ Live Streaming✓ Interactive Chat✓ Private Shows✓ HD Quality
Anya is LIVE right now
FREE
Free to watch • No registration required • HD streaming