Created
October 11, 2010 22:23
-
-
Save jcoglan/621332 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var faye = require('faye'), | |
sys = require('sys'); | |
var client = new faye.Client('http://127.0.0.1:8000/faye'); | |
client.subscribe('/messages', function(message) { | |
// This should never run due to server-side extension | |
sys.puts(sys.inspect(message)); | |
}); | |
setInterval(function() { | |
client.publish('/messages', {hello: 'world'}); | |
}, 1000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'), | |
sys = require('sys'), | |
faye = require('faye'); | |
var serverProtection = { | |
incoming: function(message, callback) { | |
if (message.channel !== '/meta/subscribe' || message.subscription !== '/messages') | |
return callback(message); | |
if (!message.ext || message.ext.authToken !== 'whatever') | |
message.error = 'I need an authToken!'; | |
callback(message); | |
} | |
}; | |
var clientAuthentication = { | |
outgoing: function(message, callback) { | |
if (message.channel !== '/meta/subscribe' || message.subscription !== '/messages') | |
return callback(message); | |
message.ext = message.ext || {}; | |
message.ext.authToken = 'whatever'; | |
callback(message); | |
} | |
}; | |
var server = http.createServer(), | |
bayeux = new faye.NodeAdapter({mount: '/faye', timeout: 45}); | |
bayeux.addExtension(serverProtection); | |
bayeux.attach(server); | |
server.listen(8000); | |
var client = bayeux.getClient(); | |
client.addExtension(clientAuthentication); | |
client.subscribe('/messages', function(message) { | |
sys.puts(sys.inspect(message)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment