Swiftpack.co - yesleon/WebSocketTaskPublisher as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by yesleon.
yesleon/WebSocketTaskPublisher v1.0
WebSocketPublisher let you use Combine for WebSocket tasks.
⭐️ 1
🕓 3 years ago
iOS macOS
.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: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

3 years ago

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