Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove prefix use in public APIs and respell Upload as DirectUpload #84

Merged
merged 19 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ class ThumbnailModel: ObservableObject {
}

private let asset: AVAsset
private let upload: MuxUpload
private let upload: DirectUpload
private var thumbnailGenerator: AVAssetImageGenerator?

@Published var thumbnail: CGImage?
@Published var uploadProgress: MuxUpload.TransportStatus?
@Published var uploadProgress: DirectUpload.TransportStatus?

init(asset: AVAsset, upload: MuxUpload) {
init(asset: AVAsset, upload: DirectUpload) {
self.asset = asset
self.upload = upload

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class UploadCreationModel : ObservableObject {
}
}

@discardableResult func startUpload(preparedMedia: PreparedUpload, forceRestart: Bool) -> MuxUpload {
let upload = MuxUpload(
@discardableResult func startUpload(preparedMedia: PreparedUpload, forceRestart: Bool) -> DirectUpload {
let upload = DirectUpload(
uploadURL: preparedMedia.remoteURL,
videoFileURL: preparedMedia.localVideoFile
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import MuxUploadSDK
class UploadListModel : ObservableObject {

init() {
UploadManager.shared.addUploadsUpdatedDelegate(
DirectUploadManager.shared.addDelegate(
Delegate(
handler: { uploads in

Expand Down Expand Up @@ -40,17 +40,17 @@ class UploadListModel : ObservableObject {
)
}

@Published var lastKnownUploads: [MuxUpload] = Array()
@Published var lastKnownUploads: [DirectUpload] = Array()
}

fileprivate class Delegate: UploadsUpdatedDelegate {
let handler: ([MuxUpload]) -> Void
func uploadListUpdated(with list: [MuxUpload]) {
handler(list)
fileprivate class Delegate: DirectUploadManagerDelegate {
let handler: ([DirectUpload]) -> Void

func didUpdate(managedDirectUploads: [DirectUpload]) {
handler(managedDirectUploads)
}

init(handler: @escaping ([MuxUpload]) -> Void) {
init(handler: @escaping ([DirectUpload]) -> Void) {
self.handler = handler
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct UploadListScreen: View {
}
}

extension MuxUpload {
extension DirectUpload {
var objectIdentifier: ObjectIdentifier {
ObjectIdentifier(self)
}
Expand Down Expand Up @@ -51,7 +51,7 @@ fileprivate struct ListContainerView: View {
fileprivate struct ListItem: View {

@StateObject var thumbnailModel: ThumbnailModel
let upload: MuxUpload
let upload: DirectUpload

var body: some View {
ZStack(alignment: .bottom) {
Expand Down Expand Up @@ -130,7 +130,7 @@ fileprivate struct ListItem: View {
}
}

private func statusLine(status: MuxUpload.TransportStatus?) -> String {
private func statusLine(status: DirectUpload.TransportStatus?) -> String {
guard let status = status, let progress = status.progress, let startTime = status.startTime, startTime > 0 else {
return "missing status"
}
Expand All @@ -152,14 +152,14 @@ fileprivate struct ListItem: View {
return "\(formattedMBytes) MB in \(formattedTime)s (\(formattedDataRate) KB/s)"
}

private func elapsedBytesOfTotal(status: MuxUpload.TransportStatus) -> String {
private func elapsedBytesOfTotal(status: DirectUpload.TransportStatus) -> String {
guard let progress = status.progress else {
return "unknown"
}
return "\(progress.completedUnitCount / 1000)KB"
}

init(upload: MuxUpload) {
init(upload: DirectUpload) {
self.upload = upload
_thumbnailModel = StateObject(
wrappedValue: {
Expand Down Expand Up @@ -214,7 +214,7 @@ struct UploadListItem_Previews: PreviewProvider {
static var previews: some View {
ZStack {
WindowBackground
let upload = MuxUpload(uploadURL: URL(string: "file:///")!, videoFileURL: URL(string: "file:///")!)
let upload = DirectUpload(uploadURL: URL(string: "file:///")!, videoFileURL: URL(string: "file:///")!)
ListItem(upload: upload)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ struct UploadProgressView: View {
}
}

private func uploadStatus(uploadState: AppUploadState) -> MuxUpload.Status? {
private func uploadStatus(uploadState: AppUploadState) -> DirectUpload.Status? {
switch uploadState {
case .done(let success): return success.finalState
case .uploading(let status): return status
default: return nil
}
}

private func dataRateTxt(status: MuxUpload.Status?) -> String {
private func dataRateTxt(status: DirectUpload.Status?) -> String {
guard let status = status, let progress = status.progress else {
return ""
}
Expand All @@ -69,7 +69,7 @@ struct UploadProgressView: View {
}
}

private func elapsedBytesOfTotal(status: MuxUpload.Status) -> String {
private func elapsedBytesOfTotal(status: DirectUpload.Status) -> String {
guard let progress = status.progress else {
return "unknown"
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import MuxUploadSDK
let directUploadURL: URL = /* Fetch the direct upload URL created before */
let videoInputURL: URL = /* File URL to your video file. See Test App for how to retrieve a video from PhotosKit */

let upload = MuxUpload(
let upload = DirectUpload(
uploadURL: directUploadURL,
inputFileURL: videoInputURL,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class UploadInputStandardizationWorker {

func standardize(
sourceAsset: AVAsset,
maximumResolution: UploadOptions.InputStandardization.MaximumResolution,
maximumResolution: DirectUploadOptions.InputStandardization.MaximumResolution,
outputURL: URL,
completion: @escaping (AVAsset, AVAsset?, Error?) -> ()
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class UploadInputStandardizer {
func standardize(
id: String,
sourceAsset: AVAsset,
maximumResolution: UploadOptions.InputStandardization.MaximumResolution,
maximumResolution: DirectUploadOptions.InputStandardization.MaximumResolution,
outputURL: URL,
completion: @escaping (AVAsset, AVAsset?, Error?) -> ()
) {
Expand Down
8 changes: 4 additions & 4 deletions Sources/MuxUploadSDK/InternalUtilities/ChunkedFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ChunkedFile {
/// Reads the next chunk from the file, advancing the file for the next read
/// This method does synchronous I/O, so call it in the background
func readNextChunk() -> Result<FileChunk, Error> {
MuxUploadSDK.logger?.info("--readNextChunk(): called")
SDKLogger.logger?.info("--readNextChunk(): called")
do {
guard fileHandle != nil else {
return Result.failure(ChunkedFileError.invalidState("readNextChunk() called but the file was not open"))
Expand All @@ -62,7 +62,7 @@ class ChunkedFile {
fileHandle: fileHandle,
fileURL: fileURL
)
MuxUploadSDK.logger?.info("Opened file with len \(String(describing: fileSize)) at path \(fileURL.path)")
SDKLogger.logger?.info("Opened file with len \(String(describing: fileSize)) at path \(fileURL.path)")
} catch {
throw ChunkedFileError.fileHandle(error)
}
Expand All @@ -75,7 +75,7 @@ class ChunkedFile {
do {
try fileHandle?.close()
} catch {
MuxUploadSDK.logger?.warning("Swallowed error closing file: \(error.localizedDescription)")
SDKLogger.logger?.warning("Swallowed error closing file: \(error.localizedDescription)")
}
state = nil
}
Expand All @@ -87,7 +87,7 @@ class ChunkedFile {
}

private func doReadNextChunk() throws -> FileChunk {
MuxUploadSDK.logger?.info("--doReadNextChunk")
SDKLogger.logger?.info("--doReadNextChunk")
guard let fileHandle = fileHandle, let fileURL = fileURL else {
throw ChunkedFileError.invalidState("doReadNextChunk called without file handle. Did you call open()?")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ extension Reporter {
func reportUploadSuccess(
inputDuration: Double,
inputSize: UInt64,
options: UploadOptions,
options: DirectUploadOptions,
uploadEndTime: Date,
uploadStartTime: Date,
uploadURL: URL
Expand Down Expand Up @@ -133,7 +133,7 @@ extension Reporter {
errorDescription: String,
inputDuration: Double,
inputSize: UInt64,
options: UploadOptions,
options: DirectUploadOptions,
uploadEndTime: Date,
uploadStartTime: Date,
uploadURL: URL
Expand Down Expand Up @@ -173,7 +173,7 @@ extension Reporter {
func reportUploadInputStandardizationSuccess(
inputDuration: Double,
inputSize: UInt64,
options: UploadOptions,
options: DirectUploadOptions,
nonStandardInputReasons: [UploadInputFormatInspectionResult.NonstandardInputReason],
standardizationEndTime: Date,
standardizationStartTime: Date,
Expand Down Expand Up @@ -216,7 +216,7 @@ extension Reporter {
inputDuration: Double,
inputSize: UInt64,
nonStandardInputReasons: [UploadInputFormatInspectionResult.NonstandardInputReason],
options: UploadOptions,
options: DirectUploadOptions,
standardizationEndTime: Date,
standardizationStartTime: Date,
uploadCanceled: Bool,
Expand Down
18 changes: 9 additions & 9 deletions Sources/MuxUploadSDK/InternalUtilities/UploadInput.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ struct UploadInput {
)
case standardizationFailed(AVAsset, UploadInfo)
case awaitingUploadConfirmation(UploadInfo)
case uploadInProgress(UploadInfo, MuxUpload.TransportStatus)
case uploadPaused(UploadInfo, MuxUpload.TransportStatus)
case uploadSucceeded(UploadInfo, MuxUpload.Success)
case uploadFailed(UploadInfo, MuxUpload.UploadError)
case uploadInProgress(UploadInfo, DirectUpload.TransportStatus)
case uploadPaused(UploadInfo, DirectUpload.TransportStatus)
case uploadSucceeded(UploadInfo, DirectUpload.SuccessDetails)
case uploadFailed(UploadInfo, DirectUploadError)
}

var status: Status
Expand Down Expand Up @@ -83,7 +83,7 @@ struct UploadInput {
}
}

var transportStatus: MuxUpload.TransportStatus? {
var transportStatus: DirectUpload.TransportStatus? {
switch status {
case .ready:
return nil
Expand Down Expand Up @@ -122,7 +122,7 @@ extension UploadInput {
}

mutating func processStartNetworkTransport(
startingTransportStatus: MuxUpload.TransportStatus
startingTransportStatus: DirectUpload.TransportStatus
) {
if case UploadInput.Status.underInspection = status {
status = .uploadInProgress(uploadInfo, startingTransportStatus)
Expand All @@ -132,16 +132,16 @@ extension UploadInput {
}

mutating func processUploadSuccess(
transportStatus: MuxUpload.TransportStatus
transportStatus: DirectUpload.TransportStatus
) {
if case UploadInput.Status.uploadInProgress(let info, _) = status {
status = .uploadSucceeded(info, MuxUpload.Success(finalState: transportStatus))
status = .uploadSucceeded(info, DirectUpload.SuccessDetails(finalState: transportStatus))
} else {
return
}
}

mutating func processUploadFailure(error: MuxUpload.UploadError) {
mutating func processUploadFailure(error: DirectUploadError) {
status = .uploadFailed(uploadInfo, error)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// MuxUpload+AVFoundation.swift
// DirectUpload+AVFoundation.swift
//

import AVFoundation
import Foundation

extension MuxUpload {
extension DirectUpload {

/// Initializes a MuxUpload from an ``AVAsset``
/// Initializes a DirectUpload from an ``AVAsset``
///
/// - Parameters:
/// - uploadURL: the URL of your direct upload, see
Expand All @@ -20,7 +20,7 @@ extension MuxUpload {
public convenience init(
uploadURL: URL,
inputAsset: AVAsset,
options: UploadOptions
options: DirectUploadOptions
) {
self.init(
input: UploadInput(
Expand Down
Loading