getnamo / SocketIOClient-Unreal

Socket.IO client plugin for the Unreal Engine.
Other
898 stars 240 forks source link

"connect_error" Messages Aren't Passed Through to Unreal Engine Client #427

Open BillSempsrott opened 5 months ago

BillSempsrott commented 5 months ago

Socket.io servers emit a "connect_error" event whenever there is a connection failure.

For example, connection middleware functions can be used to add functionality to the connection process (for authentication, logging, etc.). If a middleware function has a problem, it can fail by returning an error, in which case the connection attempt will fail.

Here is an example of a server code snippet where the middleware function fails and returns an error:

io.use((socket, next) => {
    // Problem with authentication...return an error
    next(new Error("ERROR_AUTHENTICATION_INVALID"));
});

The above code will cause the server to emit a "connect_error" message. In the Socket.io Javascript client, "connect_error" messages can be received as follows:

socket.on("connect_error", (error) => {
    console.log(error.message);
});

"connect_error" messages are not currently passed all the way through by the Unreal Engine client. They do, however, make it through to the underlying Socket.io protocol wrapper classes. In sio_socket.cpp, for example, these messages are received in the on_message_packet function, where they are identified as packet::type_error (see screenshot).

image

It would be great if the plugin could pass the "connect_error" messages through to the SocketIONative class via a new callback called "OnConnectError" or equivalent, as this would allow users of the Unreal Engine client to respond properly to connection errors.