socket.io-client-dart
socket.io-client-dart copied to clipboard
onConnectError does not trigger on middleware reject
onConnectError does not trigger on middleware reject, also as other events connecting, error ,disconnect and others completely broken.
Server version: 4.6.1 Client version: 2.0.2
Server code:
const io = new Server();
io.use(async (socket, next) => {
next(new Error("authentication error"));
});
io.listen(3000);
Client code:
_socket = io(
'http://localhost:3000',
OptionBuilder()
.setTransports(['websocket'])
.enableForceNew()
.disableAutoConnect()
.setAuth(
{'token': 'asd', 'roomId': roomId, 'clientId': clientId},
)
.build(),
);
_socket.onConnecting((data) {
debugPrint('connecting');
});
_socket.onConnectError((data) {
debugPrint('connect error');
});
_socket.onConnect((data) {
debugPrint('connect');
});
_socket.onDisconnect((data) {
debugPrint('disconnect');
});
_socket.onError((data) {
debugPrint('error');
});
_socket.onAny((event, data) {
debugPrint('onAny - event: $event, data: $data');
});
_socket.connect();
Result:
Restarted application in 40ms.
onAny - event: error, data: {message: authentication error}
Same problem!
same here
same
I think you can fix with using socket.on('error' ,onError); I don't know why socket.onError not work
@phamconganh, thanks! This solved our problem. Using socket.on('error') works for us, I'm not sure why it didn't work with socket.on('connect_error') or socket.onConnectError. Interestingly, on the client web package, socket.on('connect_error') works fine.