-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Closed
Description
So I was struggling the past day with emitting data to a single client from my server-side. I genuinely gone trough every page of wiki and google result I could find with the keywords used and today I found out that it was all because I had my custom event inside my io.configure method.
My code looked following: (this did not work)
io.configure(function (){
io.set('authorization', function (handshakeData, callback) {
if (handshakeData.xdomain != false) {
io.sockets.on('connection', function (socket) {
socket.disconnect();
});
}
callback(null, true); // error first callback style
});
io.sockets.on('connection', function (socket) {
blabla
socket.on('customevent', function () {
io.sockets.socket(socket.id).emit('data', { dataexample: data });
});
});
});
But then again, this worked:
io.configure(function (){
io.set('authorization', function (handshakeData, callback) {
if (handshakeData.xdomain != false) {
io.sockets.on('connection', function (socket) {
socket.disconnect();
});
}
callback(null, true); // error first callback style
});
});
io.sockets.on('connection', function (socket) {
blabla
socket.on('customevent', function () {
io.sockets.socket(socket.id).emit('data', { dataexample: data });
});
});
Basically, the websocket ended up stacking the emitted data on every refresh, so that when one client emitted his private event, it triggered them all for every client.
Anyhow, I would be interested in accessing the handshakeData object inside my events, so I decided to open this issue.
I'm glad to demonstrate more when I get back from school.
Metadata
Metadata
Assignees
Labels
No labels