sockjs / sockjs-node

WebSocket emulation - Node.js server
http://sockjs.org
MIT License
2.09k stars 309 forks source link

No heartbeat is send in the websocket with default options #221

Closed ohardy closed 6 years ago

ohardy commented 7 years ago

Anything to see why ?

njam commented 7 years ago

You mean when connecting to /websocket directly? That's expected behaviour: https://github.com/sockjs/sockjs-node#connecting-to-sockjs-node-without-the-client

ohardy commented 7 years ago

Nope, with sockjs-client

njam commented 7 years ago

Hm, then I don't know. The server should send this h frame every 25seconds I think.

ohardy commented 7 years ago

Any debug that I can enable to see why ?

chabou commented 6 years ago

I think this is related to: https://github.com/sockjs/sockjs-node/blob/14a5c3cf097126bde74436d001816c53a0593d43/src/trans-websocket.coffee#L95-L101

If ws.ping method returns true (client is compatible), SockJS doesn't send an h frame and use protocol mechanism. No frame will be shown in devtools but it works: handler is called on pong and the timeout is cleared. No problem with this on the server side.

But the socket.onheartbeat() event/handler is not called on the client side if ws.ping is used. It is called only if I modify the code to force h frame use.

I would be really happy to make a PR if you lead me down the right path to fix this. I really don't want to switch to engine.io because of this.

cc @majek @brycekahle

brycekahle commented 6 years ago

@chabou What do you need to do on heartbeats? They are a half-baked feature (as you can tell) and really shouldn't be exposed to the user.

chabou commented 6 years ago

@brycekahle This error happens a lot on mobile: https://github.com/sockjs/sockjs-client/issues/64

I found that relying on onkeepalive event was perfect to ensure a healthy connection on the client side.

brycekahle commented 6 years ago

I believe the original question has been answered, so I'm going to close this issue.