-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Struggling to write a session #20
Comments
one problem I see is
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 |
@alexcroox any progress based on @tanema's suggestions? |
I don't understand what @tanema is pointing out, this is my current code: (I moved server.listen to the bottom of the app)
Basically session is undefined. |
I can't catch any problem by looking at the code, would you please try running the example from the project source? |
debug - websocket writing 5:::{"name":"session","args":[null]} (is the output of me trying the example) |
I'm not sure what do you mean by that log output. Have you made progress on trying the example? |
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? |
should there be a callback if session is ready? i find it strange for session to be undefined inside that block |
It's undefined because something isn't setup correctly, I'm yet to find out what. |
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) { |
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) { |
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. |
I had the same problem i.e. session is undefined for me the problem was that in on client javascript |
I have the same problem, and no solution.. It try to throw err on session.Sockets.on('connection') bracket and it's return : Someone have ideas ? |
I am trying to write a session value but I am getting "TypeError: Cannot set property 'foo' of undefined"
The text was updated successfully, but these errors were encountered: