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