Skip to content

Commit

Permalink
Merge develop into master
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmitchell committed Mar 7, 2020
2 parents 1f6c0d9 + 9c082d2 commit 231bbd7
Show file tree
Hide file tree
Showing 20 changed files with 362 additions and 662 deletions.
22 changes: 6 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
language: swift
xcode_project: Rocc.xcodeproj # path to your xcodeproj folder
xcode_scheme: Rocc
osx_image: xcode10.2
osx_image: xcode11.3
env:
global:
- LC_CTYPE=en_US.UTF-8
- LANG=en_US.UTF-8
- IOS_FRAMEWORK_SCHEME="Rocc"
- TVOS_FRAMEWORK_SCHEME=""
- OSX_FRAMEWORK_SCHEME="RoccMac"
- IOS_SDK=iphonesimulator12.2
- TVOS_SDK=appletvsimulator12.2
- OSX_SDK=macosx10.14
- OSX_FRAMEWORK_SCHEME="Rocc"
- IOS_SDK=iphonesimulator13.2
- TVOS_SDK=appletvsimulator13.2
- OSX_SDK=macosx10.15
matrix:
- DESTINATION="OS=11.0.1,name=iPhone 5s" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=11.0.1,name=iPhone 8 Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=11.1,name=iPhone 8" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=11.2,name=iPhone 8" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=11.1,name=iPhone 8 Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=11.2,name=iPhone 8 Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=12.0,name=iPhone 8 Plus" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=12.0,name=iPhone X" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=12.2,name=iPhone Xʀ" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=12.2,name=iPhone XS Max" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="arch=x86_64" SCHEME="$OSX_FRAMEWORK_SCHEME" SDK="$OSX_SDK" RUN_TESTS="NO" BUILD_EXAMPLE="NO" POD_LINT="NO"
- DESTINATION="OS=13.3,name=iPhone 11 Pro Max" SCHEME="$IOS_FRAMEWORK_SCHEME" SDK="$IOS_SDK" RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO"
script:
- set -o pipefail
- xcodebuild -version
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<a href="https://travis-ci.org/simonmitchell/rocc">
<img alt="Build Status" src="https://travis-ci.org/simonmitchell/rocc.svg">
</a>
<a href="https://swift.org/blog/swift-4-2-released/">
<img alt="Swift 5.0" src="http://img.shields.io/badge/swift-5.0-brightgreen.svg">
<a href="https://swift.org/blog/swift-5-1-released/">
<img alt="Swift 5.0" src="http://img.shields.io/badge/swift-5.1-brightgreen.svg">
</a>
<a href="https://github.com/simonmitchell/rocc/blob/master/README.md">
<img alt="MIT" src="https://img.shields.io/badge/license-MIT-brightgreen.svg">
Expand Down
414 changes: 30 additions & 384 deletions Rocc.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

48 changes: 29 additions & 19 deletions Rocc/Device Discovery/DeviceDiscovery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
//

import Foundation
#if os(iOS)
import ThunderRequest
#elseif os(macOS)
import ThunderRequestMac
#endif

import SystemConfiguration
import os
Expand All @@ -33,7 +29,8 @@ protocol DeviceDiscovererDelegate {
/// - Parameters:
/// - discoverer: The discoverer object that discovered a device.
/// - discovered: The device that it discovered.
func deviceDiscoverer<T: DeviceDiscoverer>(_ discoverer: T, discovered device: Camera)
/// - isCached: Whether the device was loaded from a cached xml discovery file.
func deviceDiscoverer<T: DeviceDiscoverer>(_ discoverer: T, discovered device: Camera, isCached: Bool)
}

/// A protocol to be implemented by device discovery implementations
Expand Down Expand Up @@ -73,10 +70,13 @@ public protocol CameraDiscovererDelegate {

/// Called when a camera device is discovered
///
/// - Note: if `isCached == true` you should be cautious auto-connecting to the camera (Especially if it's a transfer device) as cameras in transfer mode can advertise multiple connectivity methods and the correct one may not be returned until it's passed to you with `isCached == false`.
///
/// - Parameters:
/// - discoverer: The discoverer object that discovered a device.
/// - discovered: The device that it discovered.
func cameraDiscoverer(_ discoverer: CameraDiscoverer, discovered device: Camera)
/// - isCached: Whether the camera was loaded from a cached xml file url.
func cameraDiscoverer(_ discoverer: CameraDiscoverer, discovered device: Camera, isCached: Bool)
}

/// A class which enables the discovery of cameras
Expand All @@ -85,10 +85,10 @@ public final class CameraDiscoverer {
/// A delegate which will have methods called on it when cameras are discovered or an error occurs.
public var delegate: CameraDiscovererDelegate?

private var discoveredCameras: [Camera] = []
private var discoveredCameras: [(camera: Camera, isCached: Bool)] = []

/// A map of cameras by the SSID the local device was connected to when they were discovered
public var camerasBySSID: [String?: [Camera]] = [:]
public var camerasBySSID: [String?: [(camera: Camera, isCached: Bool)]] = [:]

var discoverers: [DeviceDiscoverer] = []

Expand Down Expand Up @@ -133,20 +133,30 @@ public final class CameraDiscoverer {

extension CameraDiscoverer: DeviceDiscovererDelegate {

func deviceDiscoverer<T>(_ discoverer: T, didError error: Error) where T : DeviceDiscoverer {
delegate?.cameraDiscoverer(self, didError: error)
}

func deviceDiscoverer<T>(_ discoverer: T, discovered device: Camera) where T : DeviceDiscoverer {
func deviceDiscoverer<T>(_ discoverer: T, discovered device: Camera, isCached: Bool) where T : DeviceDiscoverer {

guard !discoveredCameras.contains(where: {
$0.identifier == device.identifier
}) else {
if let previouslyDiscoveredCamera = discoveredCameras.enumerated().first(where: {
$0.element.camera.identifier == device.identifier
}) {
// If we went from non-cached, to cached, let the delegate know!
if previouslyDiscoveredCamera.element.isCached && !isCached {
discoveredCameras[previouslyDiscoveredCamera.offset] = (device, isCached)
if var camerasForSSID = camerasBySSID[Reachability.currentWiFiSSID], let indexInCamerasForSSID = camerasForSSID.firstIndex(where: { $0.camera.identifier == device.identifier }) {
camerasForSSID[indexInCamerasForSSID] = (device, isCached)
camerasBySSID[Reachability.currentWiFiSSID] = camerasForSSID
}
delegate?.cameraDiscoverer(self, discovered: device, isCached: false)
}
return
}

camerasBySSID[Reachability.currentWiFiSSID, default: []].append(device)
discoveredCameras.append(device)
delegate?.cameraDiscoverer(self, discovered: device)
camerasBySSID[Reachability.currentWiFiSSID, default: []].append((device, isCached))
discoveredCameras.append((device, isCached))
delegate?.cameraDiscoverer(self, discovered: device, isCached: isCached)
}


func deviceDiscoverer<T>(_ discoverer: T, didError error: Error) where T : DeviceDiscoverer {
delegate?.cameraDiscoverer(self, didError: error)
}
}
18 changes: 7 additions & 11 deletions Rocc/Device Discovery/UDPDeviceDiscoverer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

import Foundation
import os
#if os(macOS)
import ThunderRequestMac
#else
import ThunderRequest
#endif
import SystemConfiguration

extension UserDefaults {
Expand Down Expand Up @@ -96,7 +92,7 @@ class UDPDeviceDiscoverer: DeviceDiscoverer {

urls.forEach { (url) in

parseDeviceInfo(at: url) { [weak self] (error) in
parseDeviceInfo(at: url, isCached: true) { [weak self] (error) in
guard let strongSelf = self else {
return
}
Expand Down Expand Up @@ -170,7 +166,7 @@ class UDPDeviceDiscoverer: DeviceDiscoverer {
Logger.log(message: "Did find device at \(device.ddURL.absoluteString)", category: "UDPDeviceDiscoverer")
os_log("Did find device at: %{public}@", log: self.log, type: .debug, device.ddURL.absoluteString)

self.parseDeviceInfo(at: device.ddURL)
self.parseDeviceInfo(at: device.ddURL, isCached: false)
}
}

Expand All @@ -185,7 +181,7 @@ class UDPDeviceDiscoverer: DeviceDiscoverer {
udpClient.finishSearching(with: callback)
}

private func parseDeviceInfo(at url: URL, callback: ((_ error: Error?) -> Void)? = nil) {
private func parseDeviceInfo(at url: URL, isCached: Bool, callback: ((_ error: Error?) -> Void)? = nil) {

let lastPathComponent = url.lastPathComponent
let baseURL = url.deletingLastPathComponent()
Expand All @@ -210,7 +206,7 @@ class UDPDeviceDiscoverer: DeviceDiscoverer {

Logger.log(message: "Parsing device info", category: "UDPDeviceDiscoverer")
os_log("Parsing device info", log: strongSelf.log, type: .debug)
strongSelf.parseDevice(from: stringResponse, baseURL: baseURL, callback: { [weak strongSelf] parsed in
strongSelf.parseDevice(from: stringResponse, isCached: isCached, baseURL: baseURL, callback: { [weak strongSelf] parsed in

// If we parsed a device, cache it's url!
guard parsed else { return }
Expand Down Expand Up @@ -247,7 +243,7 @@ class UDPDeviceDiscoverer: DeviceDiscoverer {
}
}

func parseDevice(from stringRepresentation: String, baseURL: URL, callback: @escaping (_ bool: Bool) -> Void) {
func parseDevice(from stringRepresentation: String, isCached: Bool, baseURL: URL, callback: @escaping (_ bool: Bool) -> Void) {


}
Expand All @@ -259,10 +255,10 @@ class UDPDeviceDiscoverer: DeviceDiscoverer {
delegate?.deviceDiscoverer(self, didError: error)
}

func sendDeviceToDelegate(_ camera: Camera) {
func sendDeviceToDelegate(_ camera: Camera, isCached: Bool) {

Logger.log(message: "Letting delegate know about discovered device with name: \(camera.name ?? "Unknown")", category: "UDPDeviceDiscoverer")
os_log("Letting delegate know about discovered device with name: %{public}@", log: log, type: .debug, camera.name ?? "Unknown")
delegate?.deviceDiscoverer(self, discovered: camera)
delegate?.deviceDiscoverer(self, discovered: camera, isCached: isCached)
}
}
14 changes: 3 additions & 11 deletions Rocc/Device Discovery/UPnPParsers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,7 @@ internal final class UPnPDeviceParser: NSObject, XMLParserDelegate {
guard scope.last == elementName else { return }

foundCharacters = foundCharacters.trimmingCharacters(in: .whitespacesAndNewlines)

os_log("Parser did start element: %@\nCurrent scope:%@", log: log, type: .debug, elementName, scope)


defer {
currentElement = scope.removeLast()
foundCharacters = ""
Expand Down Expand Up @@ -344,9 +342,7 @@ internal final class UPnPFolderParser: NSObject, XMLParserDelegate {

currentElement = elementName
scope.append(elementName)

os_log("Parser did start element: %@\nCurrent scope:%@", log: log, type: .debug, elementName, scope)


switch elementName {
case "container":
currentFolder = attributeDict
Expand All @@ -368,7 +364,6 @@ internal final class UPnPFolderParser: NSObject, XMLParserDelegate {
defer {
currentElement = scope.removeLast()
foundCharacters = ""
os_log("Parser did end element: %@\nCurrent scope:%@", log: log, type: .debug, elementName, scope)
}

switch elementName {
Expand Down Expand Up @@ -592,9 +587,7 @@ internal final class UPnPFileParser: NSObject, XMLParserDelegate {

currentElement = elementName
scope.append(elementName)

os_log("Parser did start element: %@\nCurrent scope:%@", log: log, type: .debug, elementName, scope)


switch elementName {
case "item":
currentFile = attributeDict
Expand All @@ -619,7 +612,6 @@ internal final class UPnPFileParser: NSObject, XMLParserDelegate {
defer {
currentElement = scope.removeLast()
foundCharacters = ""
os_log("Parser did end element: %@\nCurrent scope:%@", log: log, type: .debug, elementName, scope)
}

switch elementName {
Expand Down
8 changes: 4 additions & 4 deletions Rocc/Helpers/Logging/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@

import Foundation
import os.log
#if os(macOS)
import ThunderRequestMac
#elseif os(iOS)
import ThunderRequest
#endif

/// A simple class for logging to a given file url
public final class Logger {
Expand Down Expand Up @@ -67,6 +63,10 @@ public final class Logger {

private func log(_ message: String, category: String) {

#if DEBUG
print("[\(category)] \(message)")
#endif

guard let fileURL = fileURL, let logQueue = logQueue else { return }

logQueue.sync {
Expand Down
8 changes: 1 addition & 7 deletions Rocc/Helpers/Networking/SOAPRequestBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
import os.log

import Foundation
#if os(iOS)
import ThunderRequest
#elseif os(macOS)
import ThunderRequestMac
#endif


struct SOAPRequestBody {

Expand Down Expand Up @@ -105,8 +102,6 @@ internal final class SOAPResponseParser: NSObject, XMLParserDelegate {

currentElement = elementName
scope.append(elementName)

os_log("Parser did start element: %@\nCurrent scope:%@", log: log, type: .debug, elementName, scope)
}

func parser(_ parser: XMLParser, foundCharacters string: String) {
Expand All @@ -122,7 +117,6 @@ internal final class SOAPResponseParser: NSObject, XMLParserDelegate {
defer {
currentElement = scope.removeLast()
foundCharacters = ""
os_log("Parser did end element: %@\nCurrent scope:%@", log: log, type: .debug, elementName, scope)
}

// We are inside the device info object
Expand Down
Loading

0 comments on commit 231bbd7

Please sign in to comment.