Swiftpack.co -  pierrickrouxel/SSDPClient as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
pierrickrouxel/SSDPClient
SSDP client for Swift
.package(url: "https://github.com/pierrickrouxel/SSDPClient.git", from: "v0.2.2")

SSDPClient GitHub license GitHub release Github stable

SSDP client for Swift using the Swift Package Manager. Works on iOS, macOS, tvOS, watchOS and Linux.

Installation

GitHub spm

SSDPClient is available through Swift Package Manager. To install it, add the following line to your Package.swift dependencies:

.package(url: "https://github.com/pierrickrouxel/SSDPClient.git", from: "0.2.2")

Usage

SSDPClient can be used to discover SSDP devices and services :

import SSDPClient

class ServiceDiscovery {
    let client = SSDPDiscovery()

    init() {
        self.client.delegate = self
        self.client.discoverService()
    }
}

To handle the discovery implement the SSDPDiscoveryDelegate protocol :

extension ServiceDiscovery: SSDPDiscoveryDelegate {
    func ssdpDiscovery(_: SSDPDiscovery, didDiscoverService: SSDPService) {
        // ...
    }
}

Discovery

SSDPDiscovery provides two instance methods to discover services :

  • discoverService(forDuration duration: TimeInterval = 10, searchTarget: String = "ssdp:all") - Discover SSDP services for a duration.

  • stop() - Stop the discovery before the end.

Delegate

The SSDPDiscoveryDelegate protocol defines delegate methods that you should implement when using SSDPDiscovery discover tasks :

  • func ssdpDiscovery(_ discovery: SSDPDiscovery, didDiscoverService service: SSDPService) - Tells the delegate a requested service has been discovered.

  • func ssdpDiscovery(_ discovery: SSDPDiscovery, didFinishWithError error: Error) - Tells the delegate that the discovery ended due to an error.

  • func ssdpDiscoveryDidStart(_ discovery: SSDPDiscovery) - Tells the delegate that the discovery has started.

  • func ssdpDiscoveryDidFinish(_ discovery: SSDPDiscovery) - Tells the delegate that the discovery has finished.

Service

SSDPService is the discovered service. It contains the following attributes :

  • host: String - The host of service
  • location: String? - The value of LOCATION header
  • server: String? - The value of SERVER header
  • searchTarget: String? - The value of ST header
  • uniqueServiceName: String? - The value of USN header

Test

Run test:

swift test

GitHub

link
Stars: 19
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

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