HenningM / express-ws

WebSocket endpoints for express applications
BSD 2-Clause "Simplified" License
877 stars 142 forks source link

open event not emitted on connection #119

Open arthurmougin opened 5 years ago

arthurmougin commented 5 years ago

Unexpected behavior :

    app.ws('/',function(ws,req){
        console.log('socket requested\n');

        ws.on('open',function(){
            console.log("new connection.");
            ws.send("welcome");
        });

        ws.on('message',function (data) {
            console.log("message:" ,data);
            ws.send(data);
        })
        ....

On the first connection and after the first message, this code echoed only

socket requested

                                    // expected : new connection.

message: {"message":"message emitted"}

while the open event should be emitted between those 2 logs.

Tested on Ubuntu on a Dell and rapsbian on rpi3B+

ruettenm commented 5 years ago

I've the same issue

brian221 commented 4 years ago

I was struggling with the same issue/concept. The initial connection where 'socked requested' is logged in your example above IS the open event. The open event emission is abstracted from the underlying ws implementation.

app.ws('/',function(ws,req){
        console.log('socket requested\n');
        console.log("new connection.");
        ws.send("welcome");

        ws.on('message',function (data) {
            console.log("message:" ,data);
            ws.send(data);
        })
       ....