Swiftpack.co -  Package - yesleon/WebSocketTaskPublisher
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
yesleon/WebSocketTaskPublisher
WebSocketPublisher let you use Combine for WebSocket tasks.
.package(url: "https://github.com/yesleon/WebSocketTaskPublisher.git", from: "v1.0")

WebSocketTaskPublisher

This module let you use Combine for WebSocket tasks.

Usage

let url = URL(string: "wss://example.com")!

self.subscription = URLSession.shared
    .webSocketTaskPublisher(for: url, taskConfigurationHandler: { task in
    
        // Optionally use or retain the generated task here.
        task.send(.string("Something something"))
        task.ping()
        self.webSocketTask = task
    })
    .sink(receiveCompletion: { completion in
        switch completion {
        case .finished:
            break
        case .failure(let error):
        
            // Handle all errors here.
            print(error)
        }
    }, receiveValue: { message in
    
        // Receive all messages here.
        print(message)
    })

GitHub

link
Stars: 1
Last commit: 5 weeks ago

Release Notes

6 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco