-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #258 from mapbox/pad-telemetry-sync
Utilize core-based synchronisation
- Loading branch information
Showing
51 changed files
with
274 additions
and
2,914 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import Foundation | ||
|
||
final class FileSystem: NSObject { | ||
private let archiver: Archiver | ||
|
||
init(archiver: Archiver) { | ||
self.archiver = archiver | ||
} | ||
} | ||
|
||
extension FileSystem: FileSystemInterface { | ||
func archiveFiles(filePaths: [String], archivePath: String, callback: @escaping SuccessCallback) { | ||
DispatchQueue.global(qos: .utility).async { | ||
do { | ||
try self.archiver.archive(filePaths.map(URL.init(fileURLWithPath:)), | ||
destination: URL(fileURLWithPath: archivePath)) | ||
} catch { | ||
assertionFailure("ERROR: archiving failed with error: \(error.localizedDescription)") | ||
callback(false) | ||
return | ||
} | ||
|
||
callback(true) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Foundation | ||
|
||
final class Media: NSObject { | ||
private let recorder: FrameRecorder | ||
private let videoTrimmer: VideoTrimmer | ||
|
||
init(recorder: FrameRecorder, videoTrimmer: VideoTrimmer) { | ||
self.recorder = recorder | ||
self.videoTrimmer = videoTrimmer | ||
} | ||
} | ||
|
||
extension Media: MediaInterface { | ||
func startVideoRecording(filePath: String) { | ||
recorder.startRecording(to: filePath, settings: .lowQuality) | ||
} | ||
|
||
func stopVideoRecording() { | ||
recorder.stopRecording() | ||
} | ||
|
||
func makeVideoClips(inputFilePath: String, clips: [VideoClip], callback: @escaping SuccessCallback) { | ||
var success = true | ||
let group = DispatchGroup() | ||
|
||
for clip in clips { | ||
group.enter() | ||
videoTrimmer.trimVideo(source: inputFilePath, clip: clip) { error in | ||
if error != nil { | ||
success = false | ||
} | ||
group.leave() | ||
} | ||
} | ||
|
||
group.notify(queue: DispatchQueue.global(qos: .utility)) { | ||
callback(success) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Foundation | ||
|
||
typealias TelemetryFileMetadata = [String: String] | ||
|
||
final class Telemetry: NSObject { | ||
private let networkClient: NetworkClient | ||
|
||
init(networkClient: NetworkClient) { | ||
self.networkClient = networkClient | ||
} | ||
} | ||
|
||
extension Telemetry: TelemetryInterface { | ||
func setSyncUrl(_ url: String) { | ||
networkClient.set(baseURL: URL(string: url)) | ||
} | ||
|
||
func sendTelemetry(name: String, entries: [TelemetryEntry]) { | ||
let entries = Dictionary(entries.map { ($0.key, $0.value) }) { first, _ in | ||
assertionFailure("Duplicated key in telemetry entries.") | ||
return first | ||
} | ||
|
||
networkClient.sendEvent(name: name, entries: entries) | ||
} | ||
|
||
func sendTelemetryFile(path: String, metadata: TelemetryFileMetadata, callback: @escaping SuccessCallback) { | ||
networkClient.upload(file: path, metadata: metadata) { error in callback(error == nil) } | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import Foundation | ||
import MapboxVisionNative | ||
|
||
protocol NetworkClient { | ||
func set(baseURL: URL?) | ||
func upload(file: URL, toFolder folderName: String, completion: @escaping (Error?) -> Void) | ||
func sendEvent(name: String, entries: [String: Any]) | ||
func upload(file: String, metadata: TelemetryFileMetadata, completion: @escaping (Error?) -> Void) | ||
func cancel() | ||
} |
Oops, something went wrong.