What is actually happening?
Pong event on the client is not fired/triggered, even with pingInterval enabled/set on the server
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
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)
})
After reading v3 documentation I noticed pong
event was removed but in breaking changes its not mentioned.
Is there any workaround at the moment?
Also this mentioned in following commit:
https://github.com/socketio/socket.io-client/commit/be8c3141bdbbdfa59c4d0ca4b3149236e200878f
Seems this feature was removed due engine.io...
@hadimostafapour Good find!!! :)
I think I will take the code from the commit you mentioned and implement it myself :D
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 Thanks for the code snippet!!
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 :+1:
Most helpful comment
Hi! You are absolutely right, this should be included in the migration guide.
You should be able to reproduce the behavior with: