ably-cocoa icon indicating copy to clipboard operation
ably-cocoa copied to clipboard

Basic NSURLSessionWebSocketTask functionality

Open maratal opened this issue 2 years ago • 11 comments

Closes #1540

maratal avatar Nov 28 '22 12:11 maratal

Because this will replace core/critical functionality, it is probably a good idea to introduce it gradually via something like clientOptions.useNativeWebSocket and explicitly ask some clients to give it a try. WDYT @lawrence-forooghian @QuintinWillison

maratal avatar Dec 12 '22 13:12 maratal

I'll probably need to take some time to get some understanding of WebSockets in general (perhaps reading the RFC) before I can give this a proper review. I'll see if I can find some time this week for that, but can't guarantee that I'll be able to.

lawrence-forooghian avatar Dec 12 '22 14:12 lawrence-forooghian

Because this will replace core/critical functionality, it is probably a good idea to introduce it gradually via something like clientOptions.useNativeWebSocket and explicitly ask some clients to give it a try. WDYT @lawrence-forooghian @QuintinWillison

It's definitely worth thinking about ways to get confidence in this change, yeah.

lawrence-forooghian avatar Dec 12 '22 14:12 lawrence-forooghian

I don't think that adding a client option to change core runtime behaviour is going to do anything to explain this to time poor customers, nor drive them to use it. My preference would be to use the tools already available to us to make this change happen (versioning). So, perhaps, we should be discussing this as part of scope for version 2 of this SDK? (i.e. a major version bump) -- this should count as an enhancement from a customer's perspective, as well as from ours as maintainers. FYI, @mikelee638

QuintinWillison avatar Dec 13 '22 08:12 QuintinWillison

@QuintinWillison:

So, perhaps, we should be discussing this as part of scope for version 2 of this SDK? (i.e. a major version bump) -- this should count as an enhancement from a customer's perspective, as well as from ours as maintainers. FYI, @mikelee638

I'm not sure I understand how versioning would help us here – this change is meant to be a backwards-compatible enhancement so it wouldn't warrant a major version bump. If we did want to use versioning to provide customers with a way to opt in to this new code (which, as you say, I'm not sure many would be interested in doing), then it would probably make more sense to use a pre-release version.

lawrence-forooghian avatar Dec 19 '22 20:12 lawrence-forooghian

Thanks for your comments, @lawrence-forooghian. You're right regarding versioning, though perhaps it might be a version 2 scope change if we're going to significantly increment minimum OS runtime version(s). 🤔 You also commented:

I also think that making the change that's proposed here makes sense mainly if we’re intending to drop support for iOS < 13 at some point. If not, then we're just going to end up having to maintain two WebSocket implementations instead of one.

Maintaining two WebSocket implementations is not ideal, both in terms of maintainability of the codebase and how it is tested. So my preference would be to drop support for the older iOS runtimes as soon as we can.

QuintinWillison avatar Jan 03 '23 09:01 QuintinWillison

Taking another look at this, in the context of @umair-ably’s RFC for dropping support for iOS < 14. @maratal, do you remember whether your work here concluded that NSURLSessionWebSocketTask would be an adequate replacement for SocketRocket? Also, I noticed that the Network framework provides WebSocket functionality through NWProtocolWebSocket, also introduced in iOS 13; do you know if/how this differs to NSURLSessionWebSocketTask?

lawrence-forooghian avatar Apr 15 '24 13:04 lawrence-forooghian

I noticed that the Network framework provides WebSocket functionality through NWProtocolWebSocket, also introduced in iOS 13; do you know if/how this differs to NSURLSessionWebSocketTask?

Looks like it's swift only. And NSURLSessionWebSocketTask is an objective-c wrapper around it. That's my conclusion from the first glance.

maratal avatar Apr 15 '24 13:04 maratal

Ah, OK. There is also a C version, though. Apple’s guidance is to favour the Network framework:

Unless you have a specific reason to use URLSession, use Network framework for new WebSocket code.

lawrence-forooghian avatar Apr 15 '24 13:04 lawrence-forooghian

Ah, OK. There is also a C version, though. Apple’s guidance is to favour the Network framework:

Unless you have a specific reason to use URLSession, use Network framework for new WebSocket code.

That's interesting, will check in depth the effort needed to move to c-version, thanks @lawrence-forooghian

maratal avatar Apr 15 '24 14:04 maratal

If we drop support for iOS < 14, as is being proposed, we can then start using Swift inside the codebase anyway

lawrence-forooghian avatar Apr 15 '24 14:04 lawrence-forooghian