Comments (14)
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.
@alexcroox any progress based on @tanema's suggestions?
from session.socket.io.
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.
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.
debug - websocket writing 5:::{"name":"session","args":[null]}
(is the output of me trying the example)
from session.socket.io.
I'm not sure what do you mean by that log output. Have you made progress on trying the example?
from session.socket.io.
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.
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.
It's undefined because something isn't setup correctly, I'm yet to find out what.
from session.socket.io.
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.
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.
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.
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.
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)
- get data out of sessionStore HOT 5
- sessionStore not refreshed? HOT 1
- Undefined error HOT 2
- Session is undefined HOT 4
- easyrtc 1.0.7 HOT 2
- Broken when using Express 4.0 because of changed middleware for cookies HOT 2
- Problems with example code in README.md HOT 1
- Please add 4th param "key" to README.md HOT 2
- session.socket.io doesn't work HOT 15
- You can't directly work with session when you're using connect-mongo store HOT 4
- Compatibility with socket.io 1.0.6 ? HOT 4
- Session resets when navigating pages HOT 1
- your example fails in IE HOT 1
- It doesn't set cookies if there are none HOT 2
- Could not lookup session by key HOT 2
- Express 4 session null error HOT 2
- Better solution HOT 2
- socket.emit is not working in session.socket.io
- Session not updating HOT 1
- How to use in koa2?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from session.socket.io.