Permalink
Browse files

Updating to work with latest and greatest dependencies.

  • Loading branch information...
1 parent 853743c commit a0e7fd16110c9756b9c3aaa600e1fc2824589041 @jslatts committed Jan 25, 2012
Showing 2,342 changed files with 18,159 additions and 475,370 deletions.
View
@@ -3,10 +3,12 @@
//
var NodeChatController = {
init: function(options) {
- var mySocket, user, view, hashpassword;
+ var ioc, user, view, hashpassword;
+
+ ioc = io.connect('http://localhost')
+ this.socket = ioc;
+
- this.socket = new io.Socket(null, {port: 8001});
- mySocket = this.socket;
user = this.userName = options.userName;
hashpassword = this.hashpassword = options.hashpassword
@@ -15,18 +17,18 @@ var NodeChatController = {
view = this.view;
this.socket.on('connect', function () {
-
- mySocket.send({
- event: 'clientauthrequest'
- , user: user
+
+ ioc.emit('clientauthrequest', {
+ user: user
, hashpassword: hashpassword
});
log('Connected! Oh hai!');
});
- this.socket.on('message', function(msg) {view.msgReceived(msg)});
- this.socket.connect();
+ this.socket.on('chat', function(msg) {view.msgReceived(msg)});
+ this.socket.on('initial', function(msg) {view.initReceived(msg)});
+ this.socket.on('update', function(msg) {view.updReceived(msg)});
this.view.render();
View
53 core.js
@@ -33,7 +33,7 @@ var express = require('express')
, app = express.createServer()
, connect = require('connect')
, jade = require('jade')
- , socket = require('socket.io').listen(app);
+ , io = require('socket.io').listen(app);
app.set('view engine', 'jade');
app.set('view options', {layout: false});
@@ -159,20 +159,16 @@ var nodeChatModel = new models.NodeChatModel();
*/
function clientDisconnect(client) {
activeClients -= 1;
- client.broadcast({
- event: 'update'
- , data: activeClients
- });
+ client.broadcast.emit('update', activeClients);
}
/*
* Event handler for new chat messages. Stores the chat in redis and broadcasts it to all connected clients.
*
* @param {object} client
- * @param {object} socket
* @param {json string} msg
*/
-function chatMessage(client, socket, msg) {
+function chatMessage(client, msg) {
var chat = new models.ChatEntry();
chat.mport(msg);
chat.set({name: client.user});
@@ -185,41 +181,36 @@ function chatMessage(client, socket, msg) {
rc.rpush('chatentries', chat.xport(), redis.print);
- socket.broadcast({
- event: 'chat',
- data: chat.xport()
- });
+ io.sockets.emit('chat',chat.xport());
});
}
/*
* Handle the new connection event for socket.
*
*/
-socket.on('connection', function (client) {
+io.sockets.on('connection', function (client) {
var clientPurgatory = purgatory();
- client.on('message', function(message) {
+ client.on('clientauthrequest', function(message) {
if (clientPurgatory.stillInPurgatory()) {
- if(message.event === 'clientauthrequest') {
- //If we can get out of purgatory, set up the client for pubsub
- clientPurgatory.tryToGetOut(message, client, function () {
- activeClients += 1;
- winston.info('clients: ' + activeClients);
- socket.broadcast({
- event: 'update'
- , data: activeClients
- });
-
- client.on('disconnect', function () {
- clientDisconnect(client);
- });
- });
- }
+ //If we can get out of purgatory, set up the client for pubsub
+ clientPurgatory.tryToGetOut(message, client, function () {
+ activeClients += 1;
+ winston.info('clients: ' + activeClients);
+ io.sockets.emit('update', activeClients);
+
+ client.on('disconnect', function () {
+ clientDisconnect(client);
+ });
+ });
}
- else {
- //If this is called, we are not in purgatory, so handle it normally
- chatMessage(client, socket, message);
+ });
+
+ client.on('chat', function(message) {
+ if (!clientPurgatory.stillInPurgatory()) {
+ //If this is called, we are not in purgatory, so handle it normally
+ chatMessage(client, message);
}
});
});
View
@@ -149,8 +149,8 @@
rc.set(rKey, name, function(err, data){
if(err) return fn(new Error('[createNewUserAccount] SET failed for key: ' + rKey + ' for value: ' + name));
- bcrypt.gen_salt(10, function(err, salt) {
- bcrypt.encrypt(pass, salt, function(err, hashPass) {
+ bcrypt.genSalt(10, function(err, salt) {
+ bcrypt.hash(pass, salt, function(err, hashPass) {
rc.set(rKey + '.hashPass', hashPass, function(err, data) {
if(err) return fn(new Error('[createNewUserAccount] SET failed for key: ' + rKey + '.hashPass' + ' for value: ' + hashPass));
Oops, something went wrong.

0 comments on commit a0e7fd1

Please sign in to comment.