Skip to content

Commit

Permalink
fixup API docs
Browse files Browse the repository at this point in the history
use consistent formatting
  • Loading branch information
andrewjl-mux committed Jun 5, 2024
1 parent 0794bc3 commit fe4a9d4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 53 deletions.
88 changes: 36 additions & 52 deletions Sources/MuxUploadSDK/PublicAPI/DirectUpload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,28 @@ public typealias DirectUploadResult = Result<DirectUpload.SuccessDetails, Direct
/// ```swift
/// let upload = DirectUpload(
/// uploadURL: myDirectUploadURL,
/// videoFileURL: myVideoFileURL,
/// inputFileURL: myInputFileURL,
/// )
///
/// upload.progressHandler = { state in
/// self.uploadScreenState = .uploading(state)
/// print("Upload Progress: \(state.progress.fractionCompleted ?? 0)")
/// }
///
/// upload.resultHandler = { result in
/// switch result {
/// case .success(let success):
/// self.uploadScreenState = .done(success)
/// self.upload = nil
/// NSLog("Upload Success!")
/// print("Upload Success!")
/// case .failure(let error):
/// self.uploadScreenState = .failure(error)
/// NSLog("!! Upload error: \(error.localizedDescription)")
/// print("Upload Error: \(error.localizedDescription)")
/// }
/// }
///
/// self.upload = upload
/// upload.start()
/// ```
///
/// 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
/// this topic, see ``UploadManager``
///
/// Uploads created by this SDK are globally managed by default,
/// and can be resumed after failures or after an application
/// restart or termination. For more see ``UploadManager``.
public final class DirectUpload {

var input: UploadInput {
Expand All @@ -71,7 +67,7 @@ public final class DirectUpload {

private var inspectionResult: UploadInputFormatInspectionResult?

/// Indicates the status of the upload input as it goes
/// The status of the upload input as the upload goes
/// through its lifecycle
public enum InputStatus {
/// Upload initialized and not yet started
Expand Down Expand Up @@ -138,9 +134,7 @@ public final class DirectUpload {
}
}

/**
Handles a change in the input status of the upload
*/
/// Handles a change in the input status of the upload
public typealias InputStatusHandler = (InputStatus) -> ()

/**
Expand Down Expand Up @@ -170,27 +164,18 @@ public final class DirectUpload {

internal var fileWorker: ChunkedFileUploader?

/**
Represents the state of an upload in progress.
*/
/// Represents the state of an upload when it is being
/// sent to Mux over the network
public struct TransportStatus : Sendable, Hashable {
/**
The percentage of file bytes received by the server
accepting the upload
*/
/// The percentage of file bytes received at the
/// upload destination
public let progress: Progress?
/**
A timestamp indicating when this status was generated
*/
/// Timestamp from when this update was generated
public let updatedTime: TimeInterval
/**
The start time of the upload, nil if the upload
has never been started
*/
/// The start time of the upload, nil if the upload
/// has never been started
public let startTime: TimeInterval?
/**
Indicates if the upload has been paused
*/
/// Indicates if the upload has been paused
public let isPaused: Bool
}

Expand Down Expand Up @@ -398,17 +383,15 @@ public final class DirectUpload {
return fileWorker?.inputFileURL
}

/**
The remote endpoint that this object uploads to
*/
/// URL of the remote upload destination
public var uploadURL: URL {
return uploadInfo.uploadURL
}
// TODO: Computed Properties for some other UploadInfo properties

/**
Begins the upload. You can control what happens when the upload is already started. If `forceRestart` is true, the upload will be restarted. Otherwise, nothing will happen. The default is not to restart
*/

/// Starts the upload.
/// - Parameter forceRestart: if true, the upload will be
/// restarted. If false the upload will resume from where
/// it left off if paused, otherwise the upload will change.
public func start(forceRestart: Bool = false) {

let videoFile = (input.sourceAsset as! AVURLAsset).url
Expand Down Expand Up @@ -725,19 +708,20 @@ public final class DirectUpload {
inputStatusHandler?(inputStatus)
}

/**
Suspends the execution of this upload. Temp files and state will not be changed. The upload will remain paused in this state
even after process death.
Use ``start(forceRestart:)``, passing `false` to start the process over where it was left.
Use ``cancel()`` to remove this upload completely
*/

/// Suspends upload execution. Temporary files will be
/// kept unchanged and the upload can be resumed by calling
/// ``start(forceRestart:)`` with forceRestart set to `false`
/// to resume the upload from where it left off.
///
/// Call ``cancel()`` to permanently halt the upload.
public func pause() {
fileWorker?.pause()
}

/**
Cancels an ongoing download. State and Delegates will be cleared. Your delegates will recieve no further calls
*/
/// Cancels an upload that has already been started.
/// Any delegates or handlers set prior to this will
/// receive no further updates.
public func cancel() {
fileWorker?.cancel()
uploadManager.acknowledgeUpload(id: id)
Expand Down Expand Up @@ -908,9 +892,9 @@ extension DirectUpload {
}
}

/**
An fatal error that ocurred during the upload process. The last-known state of the upload is available, as well as the Error that stopped the upload
*/
/// An unrecoverable error occurring while the upload was
/// executing The last-known state of the upload is available,
/// as well as the Error that stopped the upload
public struct DirectUploadError : Error {
/// Represents the possible error cases from a ``DirectUpload``
public enum Kind : Int {
Expand Down
2 changes: 1 addition & 1 deletion Sources/MuxUploadSDK/PublicAPI/DirectUploadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public final class DirectUploadManager {
}

/// Returns all uploads currently-managed uploads.
/// Uploads are managed while in-progress or compelted.
/// Uploads are managed while in-progress or completed.
/// Uploads become un-managed when canceled, or if the process dies after they complete
public func allManagedDirectUploads() -> [DirectUpload] {
// Sort upload list for consistent ordering
Expand Down

0 comments on commit fe4a9d4

Please sign in to comment.