WebSocketRequest Development Started

Alamofire has started development of a WebSocketRequest type on the feature/websocket-request branch. WebSocketRequest wraps URLSessionWebSocketTask to provide websocket functionality using Alamofire APIs. We'd like to avoid the mistakes made during DataStreamRequest's developer and start gathering use cases, desired API, and feature requests before fully building out the feature.

Fundamentally, WebSocketRequest won't be too different than DataStreamRequest, with closure handlers that are called as data is received. The biggest difference, obviously, is the ability to send messages back along the socket.

So we're asking the community to tell use your dream websocket features by providing examples of your use, problems you encounter with other websocket libraries or URLSessionWebSocketTask, and features you wish those other libraries had.

5 Likes

This wrapper has made good progress and should now be usable to receive URLSessionWebSocketTask.Message values, as well as sending messages to the server.

A note of caution: URLSessionWebSocketTask seems to have a regression in at least iOS 14.5 / macOS 11.4 where messages received just before a close frame from the server will be dropped. If you control the server, adding a delay before the close frame can workaround the issue. I've found 60ms to be sufficient for local server on a virtualized machine. You should test will real devices for an appropriate delay.

2 Likes

Hi, may I ask what is the current situation regarding the web socket request feature and is there any time plan? Thanks!

1 Like

There is no timeframe for release. You can use it off the branch but the API may be unstable as I polish and add more tests. It's largely feature complete, though I still need some high level APIs as well as more tests.

2 Likes

WebSocketRequest is now available on master under an SPI. I hope to finish up the documentation and tests soon so it can go out in the next release.

3 Likes