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

Ping-pong for latency doesnt seem to work anymore #1400

Closed
1 of 2 tasks
tiborhercz opened this issue Nov 10, 2020 · 6 comments
Closed
1 of 2 tasks

Ping-pong for latency doesnt seem to work anymore #1400

tiborhercz opened this issue Nov 10, 2020 · 6 comments
Labels
documentation Improvements or additions to documentation

Comments

@tiborhercz
Copy link

You want to:

  • report a bug
  • request a feature

Current behaviour

What is actually happening?

Pong event on the client is not fired/triggered, even with pingInterval enabled/set on the server

Steps to reproduce (if the current behaviour is a bug)

https://github.com/Tiboonn/socket.io-fiddle
In the fork above the version of socket.io and socket.io-client are 3.0.0 which the 'pong' event doesnt work on.
If you change both versions in the packege.json to 2.3.0 and reinstall the packages the 'pong' event is working

Expected behaviour

What is expected?

I am expecting to get the latency is ms with the following code block on the client side

socket.on('pong', function (ms) {
    console.log(ms)
})

Setup

  • OS: Ubuntu 20.04
  • browser: Firefox/Chrome (tested multiple)
  • socket.io version: 3.0.0

Other information (e.g. stacktraces, related issues, suggestions how to fix)

@hadimostafapour
Copy link

After reading v3 documentation I noticed pong event was removed but in breaking changes its not mentioned.

Is there any workaround at the moment?

@hadimostafapour
Copy link

Also this mentioned in following commit:

be8c314

Seems this feature was removed due engine.io...

@tiborhercz
Copy link
Author

@hadimostafapour Good find!!! :)
I think I will take the code from the commit you mentioned and implement it myself :D

@darrachequesne
Copy link
Member

Hi! You are absolutely right, this should be included in the migration guide.

You should be able to reproduce the behavior with:

// server-side
io.on("connection", (socket) => {
  socket.on("ping", (cb) => {
    if (typeof cb === "function")
      cb();
  });
});

// client-side
setInterval(() => {
  const start = Date.now();

  socket.volatile.emit("ping", () => {
    const latency = Date.now() - start;
    // ...
  });
}, 5000);

@darrachequesne darrachequesne added the documentation Improvements or additions to documentation label Nov 12, 2020
@tiborhercz
Copy link
Author

@darrachequesne Thanks for the code snippet!!

darrachequesne added a commit to socketio/socket.io-website that referenced this issue Nov 12, 2020
@darrachequesne
Copy link
Member

Added here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/#No-more-%E2%80%9Cpong%E2%80%9D-event-for-retrieving-latency

Thanks for the feedback 👍

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

No branches or pull requests

3 participants