Merge pull request #56 from ajaximrpg/master
Upgraded code for node 0.8.9
Esse commit está contido em:
+8
-9
@@ -1,7 +1,3 @@
|
|||||||
## This project is no longer under active development and is unsupported.
|
|
||||||
(Also it doesn't work with the latest Node.js.)
|
|
||||||
|
|
||||||
|
|
||||||
# Ajax IM
|
# Ajax IM
|
||||||
|
|
||||||
## What is Ajax IM?
|
## What is Ajax IM?
|
||||||
@@ -24,9 +20,9 @@ community experience.
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Install `Node.js`:
|
Install `Node.js`:
|
||||||
wget http://nodejs.org/dist/node-v0.2.5.tar.gz
|
wget http://nodejs.org/dist/v0.8.9/node-v0.8.9-linux-x86.tar.gz
|
||||||
tar xzf node-v0.2.5.tar.gz
|
tar xzf node-v0.8.9-linux-x86.tar.gz
|
||||||
cd node-v0.2.5
|
cd node-v0.8.9
|
||||||
./configure
|
./configure
|
||||||
make
|
make
|
||||||
make install
|
make install
|
||||||
@@ -34,8 +30,10 @@ Install `Node.js`:
|
|||||||
Install Node Package Manager (`npm`):
|
Install Node Package Manager (`npm`):
|
||||||
See instructions at http://github.com/isaacs/npm.
|
See instructions at http://github.com/isaacs/npm.
|
||||||
|
|
||||||
Install `Express.js` and `Connect` (included automatically):
|
Install `Express.js`, `Connect` and `Cookie`:
|
||||||
npm install express
|
npm install express
|
||||||
|
npm install connect
|
||||||
|
npm install cookie
|
||||||
|
|
||||||
Compile the daemon add-on if you plan on letting the server daemonize itself:
|
Compile the daemon add-on if you plan on letting the server daemonize itself:
|
||||||
cd server/libs/daemon
|
cd server/libs/daemon
|
||||||
@@ -86,7 +84,7 @@ That's it!
|
|||||||
## Node Compatibility
|
## Node Compatibility
|
||||||
|
|
||||||
The `master` branch of Ajax IM is compatible with node --version:
|
The `master` branch of Ajax IM is compatible with node --version:
|
||||||
v0.2.5
|
v0.8.9
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
@@ -224,6 +222,7 @@ Methods:
|
|||||||
|
|
||||||
(The MIT License)
|
(The MIT License)
|
||||||
|
|
||||||
|
Copyright (c) 2012 [Daniel Howard] (http://www.svexpertise.com)
|
||||||
Copyright (c) 2010 [Joshua Gross](http://www.unwieldy.net)
|
Copyright (c) 2010 [Joshua Gross](http://www.unwieldy.net)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
|||||||
+2
-2
@@ -516,8 +516,8 @@ $.extend(AjaxIM.prototype, {
|
|||||||
.attr('id', user_id)
|
.attr('id', user_id)
|
||||||
.data('friend', username)
|
.data('friend', username)
|
||||||
.appendTo(group_item.find('ul'));
|
.appendTo(group_item.find('ul'));
|
||||||
if(status[0] == 'offline')
|
// if(status[0] == 'offline')
|
||||||
user_item.hide();
|
// user_item.hide();
|
||||||
user_item.html(
|
user_item.html(
|
||||||
user_item.html()
|
user_item.html()
|
||||||
.replace('{username}', username)
|
.replace('{username}', username)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ var store = (function(){
|
|||||||
var api = {},
|
var api = {},
|
||||||
win = window,
|
win = window,
|
||||||
doc = win.document,
|
doc = win.document,
|
||||||
|
sessionStorageName = 'sessionStorage',
|
||||||
localStorageName = 'localStorage',
|
localStorageName = 'localStorage',
|
||||||
globalStorageName = 'globalStorage',
|
globalStorageName = 'globalStorage',
|
||||||
storage
|
storage
|
||||||
@@ -20,7 +21,14 @@ var store = (function(){
|
|||||||
return JSON.parse(value)
|
return JSON.parse(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (localStorageName in win && win[localStorageName]) {
|
if (sessionStorageName in win && win[sessionStorageName]) {
|
||||||
|
storage = win[sessionStorageName]
|
||||||
|
api.set = function(key, val) { storage[key] = serialize(val) }
|
||||||
|
api.get = function(key) { return deserialize(storage[key]) }
|
||||||
|
api.remove = function(key) { delete storage[key] }
|
||||||
|
api.clear = function() { storage.clear() }
|
||||||
|
|
||||||
|
} else if (localStorageName in win && win[localStorageName]) {
|
||||||
storage = win[localStorageName]
|
storage = win[localStorageName]
|
||||||
api.set = function(key, val) { storage[key] = serialize(val) }
|
api.set = function(key, val) { storage[key] = serialize(val) }
|
||||||
api.get = function(key) { return deserialize(storage[key]) }
|
api.get = function(key) { return deserialize(storage[key]) }
|
||||||
|
|||||||
+14
-14
@@ -52,20 +52,20 @@ try {
|
|||||||
'./libs/daemon/daemon.node if you would like to use it.');
|
'./libs/daemon/daemon.node if you would like to use it.');
|
||||||
}
|
}
|
||||||
|
|
||||||
var app = express.createServer(
|
var app = express();
|
||||||
express.methodOverride(),
|
//app.set('env', 'development');
|
||||||
express.cookieDecoder(),
|
app.use(express.methodOverride());
|
||||||
express.bodyDecoder(),
|
app.use(express.cookieParser());
|
||||||
require('./middleware/im')({
|
app.use(express.bodyParser());
|
||||||
maxAge: 15 * 60 * 1000,
|
app.use(require('./middleware/im')({
|
||||||
reapInterval: 60 * 1000,
|
maxAge: 15 * 60 * 1000,
|
||||||
authentication: require('./libs/authentication/' + AUTH_LIBRARY)
|
reapInterval: 60 * 1000,
|
||||||
})
|
authentication: require('./libs/authentication/' + AUTH_LIBRARY)
|
||||||
);
|
}));
|
||||||
|
|
||||||
app.set('root', __dirname);
|
app.set('root', __dirname);
|
||||||
|
|
||||||
app.configure('development', function() {
|
if ('development' == app.get('env')) {
|
||||||
app.set('view engine', 'jade');
|
app.set('view engine', 'jade');
|
||||||
app.set('views', __dirname + '/dev/views');
|
app.set('views', __dirname + '/dev/views');
|
||||||
|
|
||||||
@@ -78,11 +78,11 @@ app.configure('development', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.use(express.logger());
|
app.use(express.logger());
|
||||||
app.use('/dev', express.router(require('./dev/app')));
|
require('./dev/app')('/dev', app);
|
||||||
app.use(express.staticProvider(
|
app.use(express.static(
|
||||||
require('path').join(__dirname, '../client')));
|
require('path').join(__dirname, '../client')));
|
||||||
app.use(express.errorHandler({dumpExceptions: true, showStack: true}));
|
app.use(express.errorHandler({dumpExceptions: true, showStack: true}));
|
||||||
});
|
}
|
||||||
|
|
||||||
app.listen(APP_PORT, APP_HOST);
|
app.listen(APP_PORT, APP_HOST);
|
||||||
|
|
||||||
|
|||||||
+8
-7
@@ -1,16 +1,17 @@
|
|||||||
var utils = require('connect/utils');
|
var cookie = require('cookie');
|
||||||
|
|
||||||
module.exports = function(app) {
|
module.exports = function(route, app) {
|
||||||
app.get('/', function(req, res) {
|
app.get(route+'/', function(req, res) {
|
||||||
res.render('chat', {
|
res.render('chat', {
|
||||||
locals: {}
|
locals: {}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/cookie', function(req, res) {
|
app.get(route+'/cookie', function(req, res) {
|
||||||
res.send('cookie set', {
|
res.setHeader('Set-Cookie',
|
||||||
'Set-Cookie': utils.serializeCookie('sessionid', utils.uid(),
|
cookie.serialize('sessionid', require('connect').utils.uid(40),
|
||||||
{path: '/'})
|
{path: '/'})
|
||||||
});
|
);
|
||||||
|
res.send('cookie set');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -2,12 +2,12 @@
|
|||||||
html
|
html
|
||||||
head
|
head
|
||||||
title Ajax IM
|
title Ajax IM
|
||||||
script(src: '/js/jquery-1.4.1.js', type: 'text/javascript')
|
script(src='/js/jquery-1.4.1.js', type='text/javascript')
|
||||||
script(src: '/js/md5.js', type: 'text/javascript')
|
script(src='/js/md5.js', type='text/javascript')
|
||||||
script(src: '/js/store.js', type: 'text/javascript')
|
script(src='/js/store.js', type='text/javascript')
|
||||||
script(src: '/js/cookies.js', type: 'text/javascript')
|
script(src='/js/cookies.js', type='text/javascript')
|
||||||
script(src: '/js/dateformat.js', type: 'text/javascript')
|
script(src='/js/dateformat.js', type='text/javascript')
|
||||||
script(src: '/js/im.js', type: 'text/javascript')
|
script(src='/js/im.js', type='text/javascript')
|
||||||
script(type: 'text/javascript')
|
script(type='text/javascript')
|
||||||
| $(function(){var im = AjaxIM.init({theme: "/themes/default"});});
|
$(function(){var im = AjaxIM.init({theme: "/themes/default"});});
|
||||||
body Hello.
|
body Hello.
|
||||||
@@ -7,7 +7,7 @@ exports.authenticate = function(request, callback) {
|
|||||||
// On failure, redirect user to auth form
|
// On failure, redirect user to auth form
|
||||||
|
|
||||||
callback({
|
callback({
|
||||||
username: 'username' + Math.floor(Math.random() * 1000),
|
username: 'username' + Math.floor(Math.random() * 10),
|
||||||
displayname: 'John Smith',
|
displayname: 'John Smith',
|
||||||
otherinfo: 'any other relevant key/values'
|
otherinfo: 'any other relevant key/values'
|
||||||
});
|
});
|
||||||
@@ -16,9 +16,17 @@ exports.authenticate = function(request, callback) {
|
|||||||
exports.friends = function(request, data, callback) {
|
exports.friends = function(request, data, callback) {
|
||||||
// Create a friends list based on given user data
|
// Create a friends list based on given user data
|
||||||
|
|
||||||
|
|
||||||
callback([
|
callback([
|
||||||
|
'username0',
|
||||||
'username1',
|
'username1',
|
||||||
'username2',
|
'username2',
|
||||||
'username3'
|
'username3',
|
||||||
|
'username4',
|
||||||
|
'username5',
|
||||||
|
'username6',
|
||||||
|
'username7',
|
||||||
|
'username8',
|
||||||
|
'username9'
|
||||||
]);
|
]);
|
||||||
};
|
};
|
||||||
@@ -8,13 +8,14 @@ module.exports = function setupHub(options) {
|
|||||||
|
|
||||||
return function session(req, res, next) {
|
return function session(req, res, next) {
|
||||||
req.sessionStore = store;
|
req.sessionStore = store;
|
||||||
req.sessionID = req.cookies[options.authentication.cookie];
|
|
||||||
|
|
||||||
if(!req.cookies) {
|
if(!req.cookies) {
|
||||||
next(new Error('session requires cookieDecoder to work properly'));
|
next(new Error('session requires cookieParser to work properly'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.sessionID = req.cookies[options.authentication.cookie];
|
||||||
|
|
||||||
if(req.dev) {
|
if(req.dev) {
|
||||||
next();
|
next();
|
||||||
return;
|
return;
|
||||||
@@ -56,7 +57,9 @@ module.exports = function setupHub(options) {
|
|||||||
};
|
};
|
||||||
res.signOff = function() { store.signOff(req.sessionID); };
|
res.signOff = function() { store.signOff(req.sessionID); };
|
||||||
|
|
||||||
next();
|
if(url.parse(req.url).pathname !== '/listen') {
|
||||||
|
next();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
next(new Error(JSON.stringify({
|
next(new Error(JSON.stringify({
|
||||||
|
|||||||
Referência em uma Nova Issue
Bloquear um usuário