views:

185

answers:

1

Hi, all,

I tried to put the module "LearnBoost's Socket.IO-Node", all works, except event 'onClientMessage'

Tell, in what there can be a problem, thanks!

...sorry for my english

io.listen(server, {

onClientConnect: function(client){
    client.send(json({ buffer: buffer }));
    client.broadcast(json({ announcement: client.sessionId + ' connected' }));
},

onClientDisconnect: function(client){
    client.broadcast(json({ announcement: client.sessionId + ' disconnected' }));
},

onClientMessage: function(message, client){
    var msg = { mess: [client.sessionId, message] };
    buffer.push(msg);
    if (buffer.length > 15) {
        buffer.shift();
    }
    client.broadcast(json(msg));

}
A: 

It seems that they changed the API.

Your example now should be written like that:

server = io.listen(server);
server.on('connection', function(client){
    client.send(json({ buffer: buffer }));
    client.broadcast(json({ announcement: client.sessionId + ' connected' }));

    client.on('disconnect', function(){
        client.broadcast(json({ announcement: client.sessionId + ' disconnected' }));
    });

    client.on('message', function(msg){
        var msg = { mess: [client.sessionId, message] };
        buffer.push(msg);
        if (buffer.length > 15) {
            buffer.shift();
        }
        client.broadcast(json(msg));
    });
});
Mike Korobov

related questions