Skip to content

Instantly share code, notes, and snippets.

@erubboli
Created May 6, 2011 12:23
Show Gist options
  • Save erubboli/958858 to your computer and use it in GitHub Desktop.
Save erubboli/958858 to your computer and use it in GitHub Desktop.
Faye example
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Auctions Test</title>
<script type="text/javascript" charset="utf-8" src="node_modules/faye/faye-browser.js"></script>
<script type="text/javascript" charset="utf-8" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.js"></script>
<script type="text/javascript" charset="utf-8">
bayeux_client = new Faye.Client('http://localhost:8000/auctions');
$(".subscribe_button").live('click',function(ev){
var id = $(this).data('auction-id');
bayeux_client.subscribe("/"+id,function(message){
alert(message.action+" auction "+id)
});
});
$(".bid_button").live('click',function(ev){
var id = $(this).data('auction-id');
bayeux_client.publish("/"+id, {action: 'bid '});
});
</script>
</head>
<body id="faye">
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td>0</td>
<td>monitor</td>
<td><span id="auction_0_reset" class="bid_button" data-auction-id="0">bid</span></td>
<td><span id="auction_0_subscribe" class="subscribe_button" data-auction-id="0">subscribe</span></td>
</tr>
<tr>
<td>1</td>
<td>keyboard</td>
<td><span id="auction_1_reset" class="bid_button" data-auction-id="1">bid</span></td>
<td><span id="auction_1_subscribe" class="subscribe_button" data-auction-id="1">subscribe</span></td>
</tr>
</table>
</body>
</html>
var http = require('http'),
faye = require('faye');
var bayeux = new faye.NodeAdapter({
mount: '/auctions',
timeout: 45
});
// Handle non-Bayeux requests
var server = http.createServer(function(request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('Hello, non-Bayeux request');
response.end();
});
bayeux.attach(server);
server.listen(8000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment