-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Why overwrites query by handshake? #3592
Comments
It's a bug that I've encountered as well. I still need to test if it's fixed in v3, but have a look at #3495 for a workaround in v2. |
Yes, that's a known quirk in Socket.IO v2, which should be fixed in v3. The explanation can be found in the migration guide: https://socket.io/docs/migrating-from-2-x-to-3-0/#Add-a-clear-distinction-between-the-Manager-query-option-and-the-Socket-query-option As a workaround for Socket.IO v2, you can explicitly create your Socket instance on the client-side. Instead of: const socket = io({
query: {
token: "abc"
}
}); You can write: const { Manager } = require("socket.io-client");
const manager = new Manager();
const socket = manager.socket("/", {
query: {
token: "abc"
}
}); In this case, you can update the // client-side
socket.query.token = "def";
// server-side
io.on("connect", (socket) => {
console.log(socket.handshake.query.token); // def
}); |
@darrachequesne Would there be a possibility to merge #3496 into the 2.4.x branch? It looks to me that the problem is simply that the http query overrides the socket specific query, while the socket specific query should actually override the http query instead (see #3495 (comment)). |
When I use
socket.io
multiplexing feat, setup ws connection by query{type: ''}
, and then I updated query{type: 'share'}
, but it not received in server side, I saw code as followsocket.io/lib/socket.js
Lines 116 to 120 in 2a1aa1c
So why overwrites query by handshake? And now I use
forceNew=true
to disable multiplexing featThe text was updated successfully, but these errors were encountered: