Skip to content

Instantly share code, notes, and snippets.

@thedaniel
Created February 2, 2012 03:07
Show Gist options
  • Save thedaniel/1721166 to your computer and use it in GitHub Desktop.
Save thedaniel/1721166 to your computer and use it in GitHub Desktop.
capability client.js
$(function(){
var Spire = require('./spire.io.js');
var Subscription = require('./spire/api/subscription');
var spire = new Spire();
$.get('/discover', function(data){
var spireSubscription;
var spireChannel;
spire.subscriptionFromUrlAndCapability(data.subscription, function(err, subscription) {
if (err){
console.error(err);
}
spireSubscription = subscription;
spireSubscription.addListener('message', function(message){
$('.emesrever').val(message.content);
});
spireSubscription.startListening();
});
spire.channelFromUrlAndCapability(data.channel, function(err, channel){
spireChannel = channel;
});
var setUpListener = function(){
if (spireChannel && spireSubscription) {
console.log('Setting up listeners...');
$('.loading').hide();
$('.content').show();
$('.submit.button').click(function(e){
e.stopPropagation();
e.preventDefault();
spireChannel.publish($('.reverseme').val(), function(err, msg){
console.log('Sent message: ', msg);
});
});
} else {
console.log('waiting for discovery...');
setTimeout(setUpListener, 500);
}
};
setUpListener();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment