Description
Hello,
Been using this framework for quite some time now, and have just been wondering is there is a middleware approach to handling incoming SocketClient handlers? What I mean by this is something that resembles Express' middleware handlers, but in this case I'm thinking of having something that can parse the JSON packets that the client recieves.
The reason I'm asking is because I'm taking advantage of Swift 4's Encodable/Decodable protocols to parse Rest response bodies with my own API and I just realized that this would be quite useful for SocketIO-client-swift.
Is there a way to do this with a middleware-like method i'm not finding?
Otherwise, might it be possible to do this by adding an Encodable-type parameter to .on methods? Where if this parameter is provided for the handler, then your client engine would attempt to cast the incoming packet to an array of that Encodable-type? And subsequently, send the error cought by the do block into the client's 'error' handler.
In terms of error handling, i believe it would be rather straightforward since you would simply have to add do-catch blocks in certain areas of the socketclient code where needed. Especially since The Encodable/Decodable errors would be produced by users implementing the custom classes anyways, so you would only have to maintain the generic nature of the errors as they are pushed on to the 'error' handler. Perhaps these errors could be distinguished by a specific error prefix, something like "Custom Encodable Packet Error:.." etc.
I think this would be a great addition to Socket.io if it isn't already implemented! If this is already implemented, let me know!
Cheers