Skip to content
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

How do you pass a callback to emit to express.io.route #115

Open
chicheongweng opened this issue Dec 17, 2014 · 1 comment
Open

How do you pass a callback to emit to express.io.route #115

chicheongweng opened this issue Dec 17, 2014 · 1 comment

Comments

@chicheongweng
Copy link

With pure socket io, I can pass callback to emit as follows:

server side:
socket.on('data', function(data, callback) {
process data from client;
callback && callback(true);
}

client side:
socket.emit('data', {name:value}, function(data) { console.log('The server got something'); }

But if I use express.io on the server side, the below code does not work because the callback is null.
express.io.route('data', function(req, callback) {
process data from client;
callback && callback(true); <--- This does not work because callback is undefined
}

So how do I do the callback to client side's emit on the server side using expressio?

@woojoo666
Copy link

needed this functionality too, trying this:

app.io.route('ready', function (socket) {
    console.log('Client connected');
    socket.io.emit('news', { hello: 'world' });
    socket.io.route('my other event', function (data) {
        console.log(data);
    });
});

gives "undefined is not a function" error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants