Skip to content

Commit 4954075

Browse files
daytime-emandrewjl-muxrefactornator
authored
Fill out the rest of the docc + fix doc errors/formatting (#22)
* NFC: call into upload manager reference (#14) * api: Remove extraneous MIME type and retry time config fields, add opt-out for event tracking (#16) * Remove videoMIMEType and retryBaseTime * Add config option for opt-out * Check opt-out * Report app name as bundle id * doc: Example App v1 (#15) * Add FakeBackend skeleton * Add the fake backend rest objects * Do the upload backend * Some widgets and colors * Styles or views * Some comments * Add prototype to nav * Ok * Minor indentation fixes * Minor formatting fix * I have mastered your puny buttons * Figuring it out * Ok now we're getting somewhere hypothetically * one last update * Don't need an environment object * Start with the pick flow * I guess we don't need the width * And a little tweaking * Upload CTA can be smarter than this * now for a view model * Move over permission request * Permission Request Success * No crash probs * up * Now to extract a thumbnail * Thumbnail extraction test * Ready to add other states * Error View * Do Processing View * now to hook it up * This thumbnail sucks * Ok now the thumbnail is in at least * Try to post an upload * Working authorization * Add some more headers for the fake backend * Add credentials but the data is off * Fake backend now works * Still works * TODO done * Time to start uploading * Fix bug in forceRestart * come back to that * Progress updates look broken * Fix the upload POST body * Cool regression * Debug * Fix the thumbnail rendering * Now what * Add listener for Uploads Updated * Auto acknowledge uploads * not time for nav * Rearrange the Upload CTA stuff * Updating more stuff * now we're navigating * Figuring it out * Time to start on the upload list * Added more listy stuff * list container * Now it works * Empty list * Hashable * Notify delegates but something doesn't seem to be working * Now working it out * Making it work * Thumbnail in the list items maybe * OK I got it * Figured out thumbnails * Work on it * Work * So far so good * ugh * Making progress * Progress View * Ok * Now we're talking * Ok now we have a status line * Now we are good * Appropriately scope the create-upload viewmodel * Now we are getting to the end * Save old uploads for a while * ont an error * Remove old example UI * cleanup * project * Remove another old UI component * Yknow this isn't really mvvm to begin with * Label cleanup * oh dang forgot the app icon * oh wow that didn't build * Add a Mux Asset catalog * Add Mux assets to a catalog * CTA vis * The list needs to actually scroll * Rename *Screen to *View * Use task instead of onAppear * Don't commit those * Fix permission prompt * AnyObject * Brackets * Update Sources/MuxUploadSDK/Public API/UploadManager.swift Co-authored-by: AJ Lauer Barinov <102617203+andrewjl-mux@users.noreply.github.com> * Generics --------- Co-authored-by: Liam Lindner <liam@mux.com> Co-authored-by: AJ Lauer Barinov <102617203+andrewjl-mux@users.noreply.github.com> * Remove spaces from directory names (for ease of life when scripting) (#18) * Document mux error case * Add doc for muxUploadSDK * Done * more doc * doc just keeps improving" * MuxUpload even nicer docs * Add more doc * Conflict markers * Update Sources/MuxUploadSDK/PublicAPI/MuxUpload.swift Co-authored-by: Liam Lindner <liam@mux.com> * Update Sources/MuxUploadSDK/PublicAPI/UploadManager.swift Co-authored-by: Liam Lindner <liam@mux.com> --------- Co-authored-by: AJ Lauer Barinov <102617203+andrewjl-mux@users.noreply.github.com> Co-authored-by: Liam Lindner <liam@mux.com>
1 parent fa58afc commit 4954075

File tree

4 files changed

+78
-19
lines changed

4 files changed

+78
-19
lines changed

Sources/MuxUploadSDK/PublicAPI/MuxErrorCase.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77

88
import Foundation
99

10+
/// Represents the possible error cases from a ``MuxUpload``
1011
public enum MuxErrorCase : Int {
11-
case unknown = -1,
12-
cancelled = 0,
13-
file = 1,
14-
http = 2,
15-
connection = 3
12+
/// The cause of the error is not known
13+
case unknown = -1
14+
/// The upload was cancelled
15+
case cancelled = 0
16+
/// The input file could not be read or processed
17+
case file = 1
18+
/// The upload could not be completed due to an HTTP error
19+
case http = 2
20+
/// The upload could not be completed due to a connection error
21+
case connection = 3
1622
}

Sources/MuxUploadSDK/PublicAPI/MuxUpload.swift

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,43 @@
77

88
import Foundation
99

10-
/**
11-
Uploads a video file to a previously-created Direct Upload. Create instances of this object using ``Builder``
12-
13-
TODO: usage here
14-
*/
10+
///
11+
/// Uploads a video file to a previously-created Mux Video Direct Upload.
12+
///
13+
/// This class is part of a full-stack workflow for uploading video files to Mux Video. In order to use this object you must first have
14+
/// created a [Direct Upload](https://docs.mux.com/guides/video/upload-files-directly) on your server backend.
15+
/// Then, use the PUT URL created there to upload your video file.
16+
///
17+
/// For example:
18+
/// ```swift
19+
/// let upload = MuxUpload(
20+
/// uploadURL: myMuxUploadURL,
21+
/// videoFileURL: myVideoFileURL,
22+
/// )
23+
///
24+
/// upload.progressHandler = { state in
25+
/// self.uploadScreenState = .uploading(state)
26+
/// }
27+
///
28+
/// upload.resultHandler = { result in
29+
/// switch result {
30+
/// case .success(let success):
31+
/// self.uploadScreenState = .done(success)
32+
/// self.upload = nil
33+
/// NSLog("Upload Success!")
34+
/// case .failure(let error):
35+
/// self.uploadScreenState = .failure(error)
36+
/// NSLog("!! Upload error: \(error.localizedDescription)")
37+
/// }
38+
/// }
39+
///
40+
/// self.upload = upload
41+
/// upload.start()
42+
/// ```
43+
///
44+
/// Uploads created by this SDK are globally managed by default, and can be resumed after failures or even after process death. For more information on
45+
/// this topic, see ``UploadManager``
46+
///
1547
public final class MuxUpload : Hashable, Equatable {
1648

1749
private let uploadInfo: UploadInfo
@@ -50,6 +82,12 @@ public final class MuxUpload : Hashable, Equatable {
5082

5183
}
5284

85+
/// Creates a new `MuxUpload` with the given confguration
86+
/// - Parameters
87+
/// - uploadURL: the PUT URL for your direct upload
88+
/// - videoFileURL: A URL to the input video file
89+
/// - retriesPerChunk: The number of times each chunk of the file upload can be retried before failure is declared
90+
/// - optOutOfEventTracking: This SDK collects performance and reliability data that helps make the Upload SDK the best it can be. If you do not wish to share this information with Mux, you may pass `true` for this parameter
5391
public convenience init(
5492
uploadURL: URL,
5593
videoFileURL: URL,
@@ -213,11 +251,13 @@ public final class MuxUpload : Hashable, Equatable {
213251
}
214252
}
215253

254+
/// Two`MuxUpload`s with the same ``MuxUpload/videoFile`` and ``MuxUpload/uploadURL`` are considered equivalent
216255
public static func == (lhs: MuxUpload, rhs: MuxUpload) -> Bool {
217256
lhs.videoFile == rhs.videoFile
218257
&& lhs.uploadURL == rhs.uploadURL
219258
}
220259

260+
/// This object's hash is computed based on its ``MuxUpload/videoFile`` and its ``MuxUpload/uploadURL``
221261
public func hash(into hasher: inout Hasher) {
222262
hasher.combine(videoFile)
223263
hasher.combine(uploadURL)

Sources/MuxUploadSDK/PublicAPI/SDK.swift renamed to Sources/MuxUploadSDK/PublicAPI/MuxUploadSDK.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,24 @@ import Foundation
99
import OSLog
1010

1111
///
12-
/// Exposes SDK metadata. Has some extensions that hide global data
12+
/// Metadata and logging for this SDK
1313
///
1414
public enum MuxUploadSDK {
1515
}
1616

1717
public extension MuxUploadSDK {
18+
19+
/// The `Logger` being used to log events from this SDK
1820
static var logger: Logger? = nil
1921

22+
/// Enables logging by adding a `Logger` with `subsystem: "Mux"` and `category: "Upload"`
2023
static func enableDefaultLogging() {
2124
logger = Logger(subsystem: "Mux", category: "MuxUpload")
2225
}
2326

27+
/// Uses the specified `Logger` to log events from this SDK
2428
static func useLogger(logger: Logger) {
2529
self.logger = logger
2630
}
31+
2732
}

Sources/MuxUploadSDK/PublicAPI/UploadManager.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,25 @@
77

88
import Foundation
99

10-
/// Manages uploads in-progress by the Mux Upload SDK.
11-
/// If your ``MuxUpload`` is managed, you can get a new handle to it using ``getStartedUpload(ofFile:)``
10+
/// Manages uploads in-progress by the Mux Upload SDK. Uploads are managed globally by default and can be started, paused,
11+
/// or cancelled from anywhere in your app.
1212
///
13-
/// To create a new upload, use ``MuxUpload``
13+
/// This class is used to find and resume uploads previously-created via ``MuxUpload``. Upload tasks created by ``MuxUpload``
14+
/// are, by defauly globally managed. If your ``MuxUpload`` is managed, you can get a new handle to it anywhere by using
15+
/// ``findStartedUpload(ofFile:)`` or ``allManagedUploads()``
1416
///
17+
/// ## Handling failure, backgrounding, and process death
1518
/// Managed uploads can be resumed where they left off after process death, and can be accessed anywhere in your
16-
/// app without needing to manually track the tasks or their state
19+
/// app without needing to manually track the tasks or their state. Managed uploads only survive process death if they
20+
/// were paused, in progress, or have failed. Success must be handled by you, even if it occurs, eg, during a `BGTask`
1721
///
18-
/// Managed uploads only survive process death if they were paused or in progress. Success and failure must be handled
19-
/// by you, even if those events occur during (for instance) a ``BGTask``
22+
/// ```swift
23+
/// // Call during app init
24+
/// UploadManager.resumeAllUploads()
25+
/// let restartedUploads = UploadManager.allManagedUploads()
26+
/// // ... do something with the restrted uploads, like subscribing to progress updates for instance
27+
/// ```
2028
///
21-
/// (see ``MuxUpload.Builder.manage(automatically:)``)
2229
public final class UploadManager {
2330

2431
private var uploadersByURL: [URL : ChunkedFileUploader] = [:]
@@ -68,7 +75,7 @@ public final class UploadManager {
6875
}
6976

7077
/// Resumes all upload that were paused or interrupted
71-
/// It can be handy to call this in your ``AppDelegate`` to resume uploads that have been killed by the process dying
78+
/// It can be useful to call this during app initialization to resume uploads that have been killed by the process dying
7279
public func resumeAllUploads() {
7380
Task.detached { [self] in
7481
for upload in await uploadActor.getAllUploads() {
@@ -147,6 +154,7 @@ public final class UploadManager {
147154

148155
/// A delegate that handles changes to the list of active uploads
149156
public protocol UploadsUpdatedDelegate: AnyObject {
157+
/// Called when the global list of uploads changes. This happens whenever a new upload is started, or an existing one completes or fails
150158
func uploadListUpdated(with list: [MuxUpload])
151159
}
152160

0 commit comments

Comments
 (0)