Permalink
Browse files

Initial installation of socket.io

  • Loading branch information...
1 parent 69f2e77 commit 5e9d0396265ed1b7235d9a873106d750db7dbdfa @Aaronontheweb Aaronontheweb committed Apr 13, 2012
Showing with 33 additions and 1 deletion.
  1. +22 −0 lib/server.js
  2. +4 −1 lib/views/index.jade
  3. +7 −0 lib/views/partials/socketio
View
@@ -8,6 +8,8 @@ var express = require('express')
var app = module.exports = express.createServer();
+var io = require('socket.io').listen(app);
+
// Configuration
app.configure(function(){
@@ -29,9 +31,29 @@ app.configure('production', function(){
app.use(express.errorHandler());
});
+//Configure socket.io
+io.configure(function () {
+ //IIS doesn't yet support WebSockets, so using XHR-polling will improve client latency on Azure (no socket failovers)
+ io.set("transports", ["xhr-polling"]);
+ io.set("polling duration", 10);
+});
+
//Catch-all routes
//app.all('*?', initializeSession);
+/* socket-io magic */
+io.sockets.on('connection', function (socket) {
+ socket.emit('news', { hello: 'world' });
+ socket.on('my other event', function (data) {
+ console.log(data);
+ });
+
+ socket.on('disconnect', function () {
+ io.sockets.emit('user disconnected');
+ });
+
+});
+
// Routes
require("./routes/site")(app); //All of the root-level routes
require("./routes/user")(app); //All of the user-auth routes
View
@@ -9,4 +9,7 @@
.six.columns
textarea(class='oversize expand input-text', rows='2', name='message[body]', id='message.body', required)
.two.columns.pull-four
- input(type="submit", value="Send", class='nice small radius blue button')
+ input(type="submit", value="Send", class='nice small radius blue button')
+
+block append scripts
+ include partials/socketio
@@ -0,0 +1,7 @@
+script(src="/socket.io/socket.io.js")
+script
+ var socket = io.connect('http://localhost');
+ socket.on('news', function (data) {
+ console.log(data);
+ socket.emit('my other event', { my: 'data' });
+ });

0 comments on commit 5e9d039

Please sign in to comment.