Skip to content

Instantly share code, notes, and snippets.

@ajtrichards
Created April 30, 2013 09:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajtrichards/5487672 to your computer and use it in GitHub Desktop.
Save ajtrichards/5487672 to your computer and use it in GitHub Desktop.
Faye PUB/SUB server
<script type="text/javascript" src="http://localhost:8000/faye/client.js"></script>
<script type="text/javascript">
/*
** Script to handle notifications
*/
var client = new Faye.Client('http://localhost:8000/faye',{
timeout: 120
});
client.subscribe('/messages', function(message){
alert('We got a message: ' + message.text);
});
</script>
var faye = require('faye'),
fayeRedis = require('faye-redis');
var server = new faye.NodeAdapter({
mount: '/faye',
timeout: 45
});
server.listen(8000);
server.bind('handshake', function (client_id){
console.log('Handshake: ' + client_id);
});
server.bind('subscribe', function (client_id, channel){
console.log('Subscribe: ' + client_id + ', Channel: ' + channel);
});
server.bind('publish', function(client_id, channel, data){
console.log('C: ' + client_id + ', Chan: ' + channel);
console.log(data);
});
server.bind('disconnect', function(client_id){
console.log('disconnected: ' + client_id);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment