Changing query parameter issue
Problem
I am hoping I can get some direction on this. Initializing the io with io(url,opts) works with the query parameter. If that query parameter needs to change you can dot into the sio.io.opts object. However, after it is changed that way, it is not able to be changed again. Iteration 0 - Works On Initialization <code> socket = io(options.socket,{query: {_accessToken: 'cow'} }); </code> Server's socket.request._query._accessToken returns 'cow' Iteration 1 -Works When changed the first time <code> socket.io.opts.query._accessToken = 'moo'; </code> Server's socket.request._query._accessToken returns 'moo' Iteration 2 - Doesn't work anymore <code> socket.io.opts.query._accessToken = 'twomoos'; </code> Server's socket.request._query._accessToken returns 'moo'' Although it seems to change on the client side, the server still returns the value of the access token in Iteration 1. Doing some digging, I found that the <code> socket.io.engine.transport.ws </code> contains the URL for the request, but keeps the _accessToken as the iteration 1 variable. <code> ws://192.168.1.8/socket.io/?_accessToken=moo&transport=websocket&sid=mY9rC4km7ASypgDTAAAI </code> I can't change the variable using javascript because it still stays the same. That also seems rather hacky and I'd like to not do that. I haven't put in an issue request for anything, so I hope this counts as a legitimate one.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Changing query parameter issue
So I found one of the ways to resolve this as a workaround is to create a new io.Manager and pass in the new token (after I do socket.destroy() on the original object as a test) <code> socket = io(options.socket); [code block] </code> This seems to effectively reconnect and change the token each time (or any other query params). I don't know if this is what you are supposed to do since most a
Trust Score
1 verification
- 1
So I found one of the ways to resolve this as a workaround is to create a new io
<code> socket = io(options.socket);
textsocket.io = new io.Manager(options.socket,{query: {_accessToken: $auth.getToken()} }); - 2
This seems to effectively reconnect and change the token each time (or any other
This seems to effectively reconnect and change the token each time (or any other query params). I don't know if this is what you are supposed to do since most articles I read suggest changing the opts.query
- 3
Hoping to get some insight or see if we can find if its a bug?
Hoping to get some insight or see if we can find if its a bug?
Validation
Resolved in socketio/socket.io GitHub issue #1677. Community reactions: 0 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep