Skip to content

Use a UUID string as MuxUpload internal identifier #30

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

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
3 changes: 1 addition & 2 deletions Sources/MuxUploadSDK/PublicAPI/MuxUpload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class MuxUpload : Hashable, Equatable {

private let uploadInfo: UploadInfo
private let manageBySDK: Bool
private let id: Int
private let id: String = UUID().uuidString
private let uploadManager: UploadManager

private var lastSeenStatus: Status = Status(progress: Progress(totalUnitCount: 0), updatedTime: 0, startTime: 0, isPaused: false)
Expand Down Expand Up @@ -276,7 +276,6 @@ public final class MuxUpload : Hashable, Equatable {
private init (uploadInfo: UploadInfo, manage: Bool = true, uploadManager: UploadManager) {
self.uploadInfo = uploadInfo
self.manageBySDK = manage
self.id = Int.random(in: Int.min...Int.max)
self.uploadManager = uploadManager
}

Expand Down
10 changes: 5 additions & 5 deletions Sources/MuxUploadSDK/PublicAPI/UploadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public final class UploadManager {
public func resumeUpload(ofFile: URL) async -> MuxUpload? {
let fileUploader = await uploadActor.getUpload(ofFileAt: ofFile)
if let nonNilUploader = fileUploader {
nonNilUploader.addDelegate(withToken: Int.random(in: Int.min...Int.max), uploaderDelegate)
nonNilUploader.addDelegate(withToken: UUID().uuidString, uploaderDelegate)
return MuxUpload(wrapping: nonNilUploader, uploadManager: self)
} else {
return nil
Expand All @@ -79,7 +79,7 @@ public final class UploadManager {
public func resumeAllUploads() {
Task.detached { [self] in
for upload in await uploadActor.getAllUploads() {
upload.addDelegate(withToken: Int.random(in: Int.min...Int.max), uploaderDelegate)
upload.addDelegate(withToken: UUID().uuidString, uploaderDelegate)
}
}
}
Expand Down Expand Up @@ -108,10 +108,10 @@ public final class UploadManager {
internal func findUploaderFor(videoFile url: URL) -> ChunkedFileUploader? {
return uploadersByURL[url]
}
internal func registerUploader(_ fileWorker: ChunkedFileUploader, withId id: Int) {

internal func registerUploader(_ fileWorker: ChunkedFileUploader, withId id: String) {
uploadersByURL.updateValue(fileWorker, forKey: fileWorker.uploadInfo.videoFile)
fileWorker.addDelegate(withToken: id + 1, uploaderDelegate)
fileWorker.addDelegate(withToken: UUID().uuidString, uploaderDelegate)
Task.detached {
await self.uploadActor.updateUpload(
fileWorker.uploadInfo,
Expand Down
6 changes: 3 additions & 3 deletions Sources/MuxUploadSDK/Upload/ChunkedFileUploader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ChunkedFileUploader {
let uploadInfo: UploadInfo
var currentState: InternalUploadState { get { _currentState } }

private var delegates: [Int : ChunkedFileUploaderDelegate] = [:]
private var delegates: [String : ChunkedFileUploaderDelegate] = [:]

private let file: ChunkedFile
private var currentWorkTask: Task<(), Never>? = nil
Expand All @@ -26,11 +26,11 @@ class ChunkedFileUploader {
private var lastReadCount: UInt64 = 0
private let reporter = Reporter()

func addDelegate(withToken token: Int, _ delegate: ChunkedFileUploaderDelegate) {
func addDelegate(withToken token: String, _ delegate: ChunkedFileUploaderDelegate) {
delegates.updateValue(delegate, forKey: token)
}

func removeDelegate(withToken: Int) {
func removeDelegate(withToken: String) {
delegates.removeValue(forKey: withToken)
}

Expand Down