This is more of a proposal to track adding support for web sockets to Hyperspace. I believe it would be an interesting use case that could be helpful.
Implementation
I propose adding a new class named WebSocketBackendService that conforms to BackendServiceProtocol. It will behave very similarly to BackendService, but will add two key functions.
func listen<T>(for type: T, perform: (T) -> Void) where T: Decodable
func send<T>(message: T) async throws
Alternatives Considered
I have considered registering decodable types in the service initializer, but I believe that losing the type information would be pretty rough in the implementation. I like how the above listen function would maintain type information which allows the implementers to treat listening to messages similarly to routing URLs.
Drawbacks
Bloat. Adding web sockets is a bit outside the initial scope of Hyperspace, but I believe it is appropriate for this framework since it's an Apple-supplied and supported API.
This is more of a proposal to track adding support for web sockets to Hyperspace. I believe it would be an interesting use case that could be helpful.
Implementation
I propose adding a new class named
WebSocketBackendServicethat conforms toBackendServiceProtocol. It will behave very similarly toBackendService, but will add two key functions.Alternatives Considered
I have considered registering decodable types in the service initializer, but I believe that losing the type information would be pretty rough in the implementation. I like how the above
listenfunction would maintain type information which allows the implementers to treat listening to messages similarly to routing URLs.Drawbacks
Bloat. Adding web sockets is a bit outside the initial scope of Hyperspace, but I believe it is appropriate for this framework since it's an Apple-supplied and supported API.