Finally getting session.id from within socket.io connection!
This commit is contained in:
		
							parent
							
								
									41674ca3f3
								
							
						
					
					
						commit
						e8ca268cde
					
				
							
								
								
									
										33
									
								
								server.js
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								server.js
									
									
									
									
									
								
							@ -96,39 +96,12 @@ app.get('/logout', function(req, res){
 | 
			
		||||
 | 
			
		||||
var http = require('http').Server(app);
 | 
			
		||||
var io = require('socket.io')(http);
 | 
			
		||||
 | 
			
		||||
//io.set('authorization', function (handshakeData, accept) {
 | 
			
		||||
    //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);
 | 
			
		||||
	//}
 | 
			
		||||
    //}
 | 
			
		||||
//});
 | 
			
		||||
var iosess = require('socket.io-express-session');
 | 
			
		||||
io.use(iosess(session));
 | 
			
		||||
 | 
			
		||||
io.on('connection', function(socket){
 | 
			
		||||
    //winston.info('a user connected');
 | 
			
		||||
    winston.info('sessio id, '+ socket.handshake.session.id);
 | 
			
		||||
    fileSystem.readFile(notePath, {encoding: 'utf-8'}, function(err,data){
 | 
			
		||||
        if (!err){
 | 
			
		||||
            winston.info('file read on connection');
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user