socket.io first prototype

This commit is contained in:
Manuel Araoz 2014-01-13 18:13:41 -03:00
parent 399182233b
commit 2e959fa81c
7 changed files with 46 additions and 4 deletions

View File

@ -32,7 +32,9 @@
"afterEach",
"it",
"inject",
"expect"
"expect",
"$"
],
"indent": false, // Specify indentation spacing
"devel": true, // Allow development statements e.g. `console.log();`.

View File

@ -13,3 +13,6 @@ head
link(rel='stylesheet', href='/lib/bootstrap/dist/css/bootstrap.min.css')
link(rel='stylesheet', href='/css/common.css')
script(src='/socket.io/socket.io.js')
script(src='/lib/jquery/jquery.js')

View File

@ -2,3 +2,10 @@ extends layouts/default
block content
section.container(data-ng-view)
div.row
div.span4
Test
div.span4
Test2

14
app/views/sockets/main.js Normal file
View File

@ -0,0 +1,14 @@
'use strict';
var Transaction = require('../../models/Transaction');
module.exports = function(app, io) {
io.set('log level', 1); // reduce logging
io.sockets.on('connection', function(socket) {
socket.emit('tx', Transaction.findOne());
socket.on('my other event', function(data) {
console.log(data);
});
});
};

View File

@ -60,7 +60,9 @@
"grunt-nodemon": "~0.1.2",
"grunt-mocha-test": "~0.8.1",
"should": "~2.1.1",
"view-helpers": "latest"
"view-helpers": "latest",
"socket.io": "~0.9.16"
},
"devDependencies": {
"grunt-contrib-watch": "latest",

View File

@ -1,6 +1,15 @@
'use strict';
angular.module('mystery.system').controller('IndexController', ['$scope', 'Global', 'Index', function ($scope, Global, Index) {
angular.module('mystery.system').controller('IndexController', ['$scope', 'Global', 'Index', function($scope, Global, Index) {
$scope.global = Global;
$scope.index = Index;
}]);
$(document).ready(function() {
var socket = io.connect('http://localhost');
socket.on('tx', function(data) {
console.log(data);
});
});

View File

@ -56,9 +56,14 @@ require('./config/express')(app, db);
//Bootstrap routes
require('./config/routes')(app);
// socket.io
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
require('./app/views/sockets/main.js')(app,io);
//Start the app by listening on <port>
var port = process.env.PORT || config.port;
app.listen(port);
server.listen(port);
console.log('Express app started on port ' + port);
//expose app