Skip to content

Instantly share code, notes, and snippets.

@brlafreniere
Created April 9, 2015 05:31
Show Gist options
  • Save brlafreniere/fdcc66f3b23426e18704 to your computer and use it in GitHub Desktop.
Save brlafreniere/fdcc66f3b23426e18704 to your computer and use it in GitHub Desktop.
if (Meteor.isClient) {
function joinRoom (roomName) {
// Update joinedRooms on successful subscription.
var publishCallbacks = {
onReady: function () {
Meteor.call("updateRoomsJoined", roomName);
Session.set('currentRoom', roomName);
$('#joined-rooms').val(roomName);
},
onError: function () {
}
}
// Check if room exists, create one if not, otherwise subscribe.
if (Rooms.find({name: roomName}).count() === 0) {
Meteor.call('createAndPublishRoom', roomName, function (error, result) {
if (!error) {
Meteor.subscribe(roomName, publishCallbacks);
}
});
} else {
Meteor.subscribe(roomName, publishCallbacks);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment