-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Support Codable Messages #103
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dnKaratzas I've added the logging APIs needed to be able to inject it in. A few things to discuss but thanks for the PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this! But I want to have a good look at this before it gets merged.
First of all, sending and receiving JSON as text is a very common and valid use case. But I'd prefer that this API doesn't imply that 'binary' means 'UTF-8 encoded JSON Codable types'. If I'm using binary, which doesn't happen much anyways, I'm probably not sending JSON Codable types. I'm using a binary format of something.
I would love to not have all unnecessary APIs added. Specifically the (binary) WebSocketSendType. But also the event types, because I don't think there's a 'standard' for websocket events anywhere. And if there is, this should be documented as being said standard.
Also, the implementation assumes that an event's contents are optional. For me, that would never be the case, unless I'd mark the event as WebSocketevent<MyEvent?>
.
In Short:
I love Codable messages, not so fond of adding the rest to something like WebSocketKit.
And while sending Codable data is supported, receiving Codable data only works on the Event
type. I'd prefer seeing an onJSONText(MyEvent.self) { ws, event in .. }
(#103, fixes #62).
Many Thanks to @MihaelIsaev for the inspiration!
Those changes adds support to send
Codable
messages and receive events in special JSON format:{ "event": "<event name>" }
or
{ "event": "<event name>", "data": <anything> }
The event
data
will be decoded to the providedType
.Here is a demo:
The code will become much cleaner as you can give on events a handler!