-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
@OnConnect连接触发两次,setAuthorizationListener无法获取到authToken。 #983
Comments
You can try setting up a namespace. |
请问解决了吗 |
这个问题怎么解决? |
不要将SpringAnnotationScanner注入到IOC里面, 这个类有个bean后置处理器, 会扫描所有带有@Onconnect, @OnDisconnect, @onevent的监听器并添加到默认命令空间/中, 如果又配置了自定义的, 则@Onconnect, @OnDisconnect每次都会触发两次, 但是@onevent不会触发两次, 这点没有去细究源码 |
已经破案了,要在客户端设置namespace,并且在server端也要addNamespace,使用默认的namespace它就会触发两次connect事件 |
不要用SpringAnnotationScanner这个就行了 |
怎么不使用这个?具体点 |
看我上面回答, 不要注入这个类就不会触发扫描connect时间到默认命令空间了,如果注入了且你在自定义namespace里面配置了connect监听就会触发两次. 可以去看下这个scanner的源码 |
那个没用,跟那个没啥关系,我刚才试了的,就是不能用那个默认的namespace |
// @bean |
normal namespace needs to delete that codes. it will run normally and only fire once message |
为啥我删除了这段代码也不行呀,还要改别的吗? |
请问一下,是怎么解决的 |
我试了下,都不行。看作者怎么解决吧 |
我也是这个问题 没发解决 |
版本:java17,netty-socketio 2.0.9
版本: socket.io-client 4.7.5,postMan
前端:
` socketInst = io(socketUrl, {
withCredentials: true,
reconnectionAttempts: 120,
autoConnect: false,
auth: {
token: token,
},
query: {
operatorId: userInfo.operatorId,
operatorName: userInfo.operatorName,
clientType: '21001',
},
// transports: ['websocket', 'polling'],
});
socketInst.on('connect', () => {
console.log('客户端' + socketInst.id + '链接成功');
});
`
configuration.setAuthorizationListener( new AuthorizationListener() { @Override public AuthorizationResult getAuthorizationResult(HandshakeData handshakeData) { // 这里执行一次,无法获取到autoToken,导致无法鉴权。 return AuthorizationResult.SUCCESSFUL_AUTHORIZATION; } });
这里执行一次,无法获取到autoToken,导致无法鉴权。
@Onconnect
每次连接会执行两次,第一次
client.getHandshakeData().getAuthToken()
是null。第二次
client.getHandshakeData().getAuthToken()
正确获取到token。The text was updated successfully, but these errors were encountered: