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

[WIP] add ping method and auto-ping-pong #445

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

cwolters
Copy link
Contributor

@cwolters cwolters commented Dec 13, 2018

Add a ping method and an auto-ping-pong operation to detect interrupted connections and allow auto-reconnect afterwads.


Added a simple ping operation to allow an easy ping/pong.

ws.on('pong', message => {
// message -> {
//    "event":"pong",
//    "ts": 1511545528111,
//    "cid": 123
// }
})
ws.ping(123)

In case of no channel action (e.g. a single auth user where no messages are flying around), the ping/pong messages will keep the lib from reconnecting due to watchdog timeout..

Currently there is no auto-ping-pong build into the lib. You need to build it on top.
Would be a nice extension to the existing watchdog - so that it triggeres a reconnect only if no ping/pong comes through.

@f3rno
Copy link
Contributor

f3rno commented Dec 13, 2018

Thanks for this; could you also add an autoPing option to the WSv2 constructor that sends pings out on an interval when the connection is open? Ideally the interval would be specified with pingInterval or so, maybe defaulting to 1s.

If not I can do it, and would merge this in before, so let me know. Great idea overall.

@cwolters
Copy link
Contributor Author

Hi Cris, I can do it, but it will take a few days before I can work on the topic. So let's keep this pull request and I will update it later.

@cwolters cwolters changed the title added ping method (to receive a pong, and don't trigger re-connect if… [WIP] add ping method and auto-ping-pong Dec 14, 2018
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

Successfully merging this pull request may close these issues.

None yet

2 participants