Skip to content

Commit

Permalink
feat(sockets): add templates
Browse files Browse the repository at this point in the history
  • Loading branch information
balthazar committed Feb 5, 2015
1 parent 85df9e5 commit 479bc32
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
15 changes: 15 additions & 0 deletions api/templates/mongo/socket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

var <%= capitalized %> = require('./<%= name %>.model');

exports.register = function (socket) {

<%= capitalized %>.schema.post('save', function (doc) {
socket.emit('<%= name %>:save', doc);
});

<%= capitalized %>.schema.post('remove', function (doc) {
socket.emit('<%= name %>:remove', doc);
});

}
22 changes: 22 additions & 0 deletions app/templates/server/config/sockets(sockets).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

var config = require('./environment');

module.exports = function (io) {

io.on('connection', function (socket) {

socket.connectDate = new Date();
socket.ip = (socket.handshake.address) ? socket.handshake.address : null;

// sockets inserts

socket.on('disconnect', function () {
console.log('[%d] %s disconnected.', new Date(), socket.ip);
});

console.log('[%d] %s connected.', socket.connectDate, socket.ip);

});

};

0 comments on commit 479bc32

Please sign in to comment.