Comments (15)
I have the same problem. I am able to sent messages from the client but it is never received by the server.
connection is never called even though I get info - handshake authorized cBaOEKhzCtlntCPxOvNv
in the logs
Client
var socket = io.connect( window.location.protocol + '//' + window.location.host , {secure: true});
socket.on('session', function (session){
console.log(session);
})
Server
sessionSockets.on('connection', function (err, socket, session) {
socket.emit('session', session);
});
from session.socket.io.
I haven't tried it yet but
https://github.com/eiriklv/session.socket.io seems to have a fix for 4.0
You can add it to package.json by
"session.socket.io": "http://github.com/eiriklv/session.socket.io/tarball/master"
from session.socket.io.
Yes, I use this https://github.com/eiriklv/session.socket.io s
The problem was the following:
"var sessionSockets = new SessionSockets(io, sessionStore, cookieParser);"
in "cookieParser" it is necessary to put the brackets like this:
"var sessionSockets = new SessionSockets(io, sessionStore, cookieParser());"
And it worked.
from session.socket.io.
@GeneralZero it is also published as session.socket.io-express4 on npm
from session.socket.io.
unfortunately it doesn't work for me. I use socket.io v1.0.6 and sessionSockets.on('connection', ...) does not fired
from session.socket.io.
@hunterok727 session.socket.io only works for [email protected]. For [email protected] look at socket.io-handshake. It's also on npm :)
from session.socket.io.
thanks! I've tried to use express v4 and socket.io v1.0.6. with socket.io-handshake, but io.on('connection', function(socket)) doesn't work
from session.socket.io.
@hunterok727 could you provide an example?
from session.socket.io.
I know, it might listen strange, but now it works :) and I don't change any line of code.
There is my code:
var express = require('express');
var path = require('path');
var favicon = require('static-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var routes = require('./routes/index');
var users = require('./routes/users');
var session = require('express-session');
var RedisStore = require('connect-redis')(session);
var socketHandshake = require('socket.io-handshake');
var sessionStore = new RedisStore({});
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(favicon());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
app.use(cookieParser());
app.use(require('less-middleware')(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({store: sessionStore, key:'sid', secret: 'verysecretkey'}));
app.use('/', routes);
app.use('/users', users);
/// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
/// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
var server = app.listen(3001, function() {
console.log('Listening on port %d', server.address().port);
});
var io = require('socket.io').listen(server);
io.use(socketHandshake({store: sessionStore, key:'sid', secret:'verysecretkey', parser:cookieParser()}));
io.on('connection', function (socket) {
console.log('connected');
});
module.exports = app;
from session.socket.io.
@hunterok727 then all is good in the hood :)
from session.socket.io.
I changed my code to @hunterok727 's in the hope that it works just as well, but unfortunately io.on('connection', function(socket)) doesn't still work. I use express: ~4.4.1 and socket.io 1.0.6
from session.socket.io.
I managed to work around similar issues I had with Express 4 and express-session
package.
My code was something along these lines:
var app = express();
var io = require('socket.io');
var session = require('express-session')({
name: 'cookiename',
secret: 'secret',
resave: false,
saveUninitialized: true
});
app.use(session);
var server = http.Server(app);
var socket = io(server);
socket.on('connection', function (client) {
session(client.handshake, {}, function() {
// The above call embedded sessionID and session.into client.handshake. Its callback doesn't pass anything.
client.handshake.session.test = 'test';
client.handshake.session.save();
});
});
Hope this helps anyone.
from session.socket.io.
as @chechenev said, I put the brackets to cookieParser and it works :)
from session.socket.io.
Thanks @eiriklv for supporting express 4 in the meantime.
I've added support for express 4 just now. It's also published on npm.
from session.socket.io.
Great stuff @wcamarao! No problem :-)
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
- 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.