|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
var path = require('path');
|
|
|
|
|
var sockets = require('path');
|
|
|
|
|
var websockets = require('../socket.io');
|
|
|
|
|
var continuationLocalStorage = require('continuation-local-storage');
|
|
|
|
|
var APP_NAMESPACE = require(path.join(__dirname, '../../package.json')).name;
|
|
|
|
|
var namespace = continuationLocalStorage.createNamespace(APP_NAMESPACE);
|
|
|
|
@ -7,18 +9,14 @@ var cls = {};
|
|
|
|
|
|
|
|
|
|
cls.http = function (req, res, next) {
|
|
|
|
|
namespace.run(function() {
|
|
|
|
|
namespace.set('http', {req: req, res: res});
|
|
|
|
|
namespace.set('request', req);
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
cls.socket = function (socket, payload, event, next) {
|
|
|
|
|
namespace.run(function() {
|
|
|
|
|
namespace.set('ws', {
|
|
|
|
|
socket: socket,
|
|
|
|
|
payload: payload,
|
|
|
|
|
// if it's a null event, then we grab it from the payload
|
|
|
|
|
event: event || ((payload || {}).data || [])[0]});
|
|
|
|
|
namespace.set('request', websockets.reqFromSocket(socket, payload, event));
|
|
|
|
|
next();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
@ -33,7 +31,6 @@ cls.set = function (key, value) {
|
|
|
|
|
|
|
|
|
|
cls.setItem = cls.set;
|
|
|
|
|
cls.getItem = cls.set;
|
|
|
|
|
cls.getNamespace = cls.storage;
|
|
|
|
|
cls.namespace = namespace;
|
|
|
|
|
cls.continuationLocalStorage = continuationLocalStorage;
|
|
|
|
|
|
|
|
|
|