lib/socket.js
function getUserFromSocket(socket, callback) {
        let wait = false;
        try {
            if (socket.handshake.headers.cookie && (!socket.request || !socket.request._query || !socket.request._query.user)) {
                let cookie = decodeURIComponent(socket.handshake.headers.cookie);
                let m = cookie.match(/connect\.sid=(.+)/);
                if (m) {
                    // If session cookie exists
                    let c = m[1].split(';')[0];
                    let sessionID = cookieParser.signedCookie(c, that.settings.secret);
                    if (sessionID) {
                        // Get user for session
                        wait = true;
                        that.settings.store.get(sessionID, function (err, obj) {
                            if (obj && obj.passport && obj.passport.user) {
                                socket._sessionID = sessionID;
                                if (typeof callback === 'function') {
                                    callback(null, obj.passport.user);
                                } else {
                                    that.adapter.log.warn('[getUserFromSocket] Invalid callback')
                                }
                            } else {
                                if (typeof callback === 'function') {
                                    callback('unknown user');
                                } else {
                                    that.adapter.log.warn('[getUserFromSocket] Invalid callback')
                                }
                            }
                        });
                    }
                }
            }
            if (!wait) {
                let user = socket.request._query.user;
                let pass = socket.request._query.pass;
                if (user && pass) {
                    wait = true;
                    that.adapter.checkPassword(user, pass, function (res) {
                        if (res) {
                            that.adapter.log.debug('Logged in: ' + user);
                            if (typeof callback === 'function') {
                                callback(null, user);
                            } else {
                                that.adapter.log.warn('[getUserFromSocket] Invalid callback')
                            }
                        } else {
                            that.adapter.log.warn('Invalid password or user name: ' + user + ', ' + pass[0] + '***(' + pass.length + ')');
                            if (typeof callback === 'function') {
                                callback('unknown user');
                            } else {
                                that.adapter.log.warn('[getUserFromSocket] Invalid callback')
                            }
                        }
                    });
                }
            }
        } catch (e) {
            that.adapter.log.error(e);
            wait = false;
        }
        if (!wait && typeof callback === 'function') {
            callback('Cannot detect user');
        }
    }
function getUserFromSocket(socket, callback) {
        let wait = false;
        try {
            if (socket.handshake.headers.cookie && (!socket.request || !socket.request._query || !socket.request._query.user)) {
                let cookie = decodeURIComponent(socket.handshake.headers.cookie);
                let m = cookie.match(/connect\.sid=(.+)/);
                if (m) {
                    // If session cookie exists
                    let c = m[1].split(';')[0];
                    let sessionID = cookieParser.signedCookie(c, that.settings.secret);
                    if (sessionID) {
                        // Get user for session
                        wait = true;
                        that.settings.store.get(sessionID, function (err, obj) {
                            if (obj && obj.passport && obj.passport.user) {
                                socket._sessionID = sessionID;
                                if (typeof callback === 'function') {
                                    callback(null, obj.passport.user);
                                } else {
                                    that.adapter.log.warn('[getUserFromSocket] Invalid callback')
                                }
                            } else {
                                if (typeof callback === 'function') {
                                    callback('unknown user');
                                } else {
                                    that.adapter.log.warn('[getUserFromSocket] Invalid callback')
                                }
                            }
                        });
                    }
                }
            }
            if (!wait) {
                let user = socket.request._query.user;
                let pass = socket.request._query.pass;
                if (user && pass) {
                    wait = true;
                    that.adapter.checkPassword(user, pass, function (res) {
                        if (res) {
                            that.adapter.log.debug('Logged in: ' + user);
                            if (typeof callback === 'function') {
                                callback(null, user);
                            } else {
                                that.adapter.log.warn('[getUserFromSocket] Invalid callback')
                            }
                        } else {
                            that.adapter.log.warn('Invalid password or user name: ' + user + ', ' + pass[0] + '***(' + pass.length + ')');
                            if (typeof callback === 'function') {
                                callback('unknown user');
                            } else {
                                that.adapter.log.warn('[getUserFromSocket] Invalid callback')
                            }
                        }
                    });
                }
            }
        } catch (e) {
            that.adapter.log.error(e);
            wait = false;
        }
        if (!wait && typeof callback === 'function') {
            callback('Cannot detect user');
        }
    }
function getUserFromSocket ( socket , callback ) { let wait = false ; try { if ( socket . handshake . headers . cookie && ( ! socket . request || ! socket . request . _query || ! socket . request . _query . user ) ) { let cookie = decodeURIComponent ( socket . handshake . headers . cookie ) ; let m = cookie . match ( / connect\.sid=(.+) / ) ; if ( m ) { // If session cookie exists
 let c = m [ 1 ] . split ( ';' ) [ 0 ] ; let sessionID = cookieParser . signedCookie ( c , that . settings . secret ) ; if ( sessionID ) { // Get user for session
 wait = true ; that . settings . store . get ( sessionID , function ( err , obj ) { if ( obj && obj . passport && obj . passport . user ) { socket . _sessionID = sessionID ; if ( typeof callback === 'function' ) { callback ( null , obj . passport . user ) ; } else { that . adapter . log . warn ( '[getUserFromSocket] Invalid callback' ) } } else { if ( typeof callback === 'function' ) { callback ( 'unknown user' ) ; } else { that . adapter . log . warn ( '[getUserFromSocket] Invalid callback' ) } } } ) ; } } } if ( ! wait ) { let user = socket . request . _query . user ; let pass = socket . request . _query . pass ; if ( user && pass ) { wait = true ; that . adapter . checkPassword ( user , pass , function ( res ) { if ( res ) { that . adapter . log . debug ( 'Logged in: ' + user ) ; if ( typeof callback === 'function' ) { callback ( null , user ) ; } else { that . adapter . log . warn ( '[getUserFromSocket] Invalid callback' ) } } else { that . adapter . log . warn ( 'Invalid password or user name: ' + user + ', ' + pass [ 0 ] + '***(' + pass . length + ')' ) ; if ( typeof callback === 'function' ) { callback ( 'unknown user' ) ; } else { that . adapter . log . warn ( '[getUserFromSocket] Invalid callback' ) } } } ) ; } } } catch ( e ) { that . adapter . log . error ( e ) ; wait = false ; } if ( ! wait && typeof callback === 'function' ) { callback ( 'Cannot detect user' ) ; } }
Extract user name from socket
Extract user name from socket