Giter Site home page Giter Site logo

Comments (14)

tanema avatar tanema commented on June 27, 2024

one problem I see is

sessionSockets = require('session.socket.io'),
sessionSockets = new sessionSockets(io, sessionStore, cookieParser);

and have you checked if there is an error on connection?

Also I may be wrong but it is also good practice to do the server.listen() very last after your socket setup

from session.socket.io.

wcamarao avatar wcamarao commented on June 27, 2024

@alexcroox any progress based on @tanema's suggestions?

from session.socket.io.

alexcroox avatar alexcroox commented on June 27, 2024

I don't understand what @tanema is pointing out, this is my current code:

(I moved server.listen to the bottom of the app)

var express = require('express'),
    app = express(),
    http = require('http'),
    cookieParser = express.cookieParser('testingthis'),
    sessionStore = new connect.middleware.session.MemoryStore();

app.configure(function () {
    app.use(cookieParser);
    app.use(express.session({ store: sessionStore }));
});

var server = http.createServer(app),
    io = require('socket.io').listen(server),
    sessionSockets = require('session.socket.io'),
    sessions = new sessionSockets(io, sessionStore, cookieParser);

sessions.on('connection', function (err, socket, session) {

    session.foo = 'bar';
    session.save();
    // ERROR HERE - TypeError: Cannot set property 'foo' of undefined

Basically session is undefined.

from session.socket.io.

wcamarao avatar wcamarao commented on June 27, 2024

I can't catch any problem by looking at the code, would you please try running the example from the project source?

from session.socket.io.

alexcroox avatar alexcroox commented on June 27, 2024

debug - websocket writing 5:::{"name":"session","args":[null]}

(is the output of me trying the example)

from session.socket.io.

wcamarao avatar wcamarao commented on June 27, 2024

I'm not sure what do you mean by that log output. Have you made progress on trying the example?

from session.socket.io.

coronelrc avatar coronelrc commented on June 27, 2024

having the same problem, there are times that session comes undefined inside the

sessionSockets.on('connection', function (err, socket, session) {
}

isn't session supposed to be defined all the time while inside that clause? I can't understand what the replies are really pointing out to, doesn't seem to solve any problem. Anyone there have ideas?

from session.socket.io.

coronelrc avatar coronelrc commented on June 27, 2024

should there be a callback if session is ready? i find it strange for session to be undefined inside that block

from session.socket.io.

alexcroox avatar alexcroox commented on June 27, 2024

It's undefined because something isn't setup correctly, I'm yet to find out what.

from session.socket.io.

tanema avatar tanema commented on June 27, 2024

Maybe this will help, this is my working setup with redis, but you could change the session store to anything else.

var express = require('express'),
     routes = require('./routes'),
     http = require('http'),
     path = require('path'),
     sessionSecret = "secret",
     cookieParser = express.cookieParser(sessionSecret),
     RedisStore = require("connect-redis")(express),
     sessionStore = new RedisStore(),
     SessionSockets = require('session.socket.io'),
     app = express();

app.configure(function(){
  app.set('port', process.env.PORT || 3001);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'hjs');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(cookieParser);
  app.use(express.session({ store: sessionStore }));
  app.use(express.static(path.join(__dirname, 'public')));
  app.use(app.router);
});

var server = http.createServer(app),
    io = require('socket.io').listen(server);

var SessionSockets = require('session.socket.io'),
     sessionSockets = new SessionSockets(io, sessionStore, cookieParser);

sessionSockets.on('connection', function (err, socket, session) {

from session.socket.io.

coronelrc avatar coronelrc commented on June 27, 2024

5th line throws an error since session is not defined (Cannot read property 'room' of undefined) you guys have ideas?

sessionSockets.on('connection', function (err, socket, session) {
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>');
room = socket.room = 'Lobby';
//socket.leave(socket.room)
if(session.room!==undefined){
socket.room = session.room;
}
}

from session.socket.io.

wcamarao avatar wcamarao commented on June 27, 2024

I'm closing this for inactivity. The module seems to be working fine, as feedback from other people and my local tests. If it's still not working for you, I recommend starting with the example, and making changes in baby steps, until you have it customized the way you need, so you may move forward with your app.

from session.socket.io.

nil1511 avatar nil1511 commented on June 27, 2024

I had the same problem i.e. session is undefined for me the problem was that in on client javascript
let it be io.connect(); rather than io.connect('localhost:3000')

from session.socket.io.

ArthurGerbelot avatar ArthurGerbelot commented on June 27, 2024

I have the same problem, and no solution..

It try to throw err on session.Sockets.on('connection') bracket and it's return :
"Error: could not look up session by key: connect.sid ...."

Someone have ideas ?

from session.socket.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.