Finally getting session.id from within socket.io connection!

This commit is contained in:
jkaplon 2017-04-20 15:55:03 -04:00
parent 41674ca3f3
commit e8ca268cde

View File

@ -96,39 +96,12 @@ app.get('/logout', function(req, res){
var http = require('http').Server(app); var http = require('http').Server(app);
var io = require('socket.io')(http); var io = require('socket.io')(http);
var iosess = require('socket.io-express-session');
//io.set('authorization', function (handshakeData, accept) { io.use(iosess(session));
//if (handshakeData.headers.cookie) {
//if (handshakeData.headers.cookie) {
//winston.info('cookie object test, ' + handshakeData.headers.cookie);
//winston.info('parse test 1, ' + cookieParser.signedCookies(handshakeData.headers.cookie, 'here kitty kitty'));
//winston.info('parse test 2, ' + cookieParser.signedCookie(handshakeData.headers.cookie['connect.sid'], 'here kitty kitty'));
//winston.info('parse test 3, ' + cookieParser.signedCookie(handshakeData.headers.cookie, 'here kitty kitty'));
//handshakeData.sessionID = cookieParser.signedCookie(handshakeData.headers.cookie['connect.sid'], 'here kitty kitty');
//winston.info('sess test 1, ' + session); // this prints alot!
//winston.info('sess test 2, ' + session.id); // undefined
//winston.info('Got session ID = ' + handshakeData.sessionID); // undefined
// save the session store to the data object
// (as required by the Session constructor)
//handshakeData.sessionStore = session.store;
//session.store.get(handshakeData.sessionID, function (err, session) {
//if (err || !session) {
//accept('Error', false);
//} else {
// create a session object, passing data as request and our
// just acquired session data
//handshakeData.session = new Session(handshakeData, session);
//accept(null, true);
//}
//});
//} else {
//return accept('No cookie transmitted.', false);
//}
//}
//});
io.on('connection', function(socket){ io.on('connection', function(socket){
//winston.info('a user connected'); //winston.info('a user connected');
winston.info('sessio id, '+ socket.handshake.session.id);
fileSystem.readFile(notePath, {encoding: 'utf-8'}, function(err,data){ fileSystem.readFile(notePath, {encoding: 'utf-8'}, function(err,data){
if (!err){ if (!err){
winston.info('file read on connection'); winston.info('file read on connection');