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

Bugfix/ios return created cache task #345

Merged
merged 2 commits into from
Jul 16, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Added ActiveQualityChanged event support for iOS.

### Fixed

- Fixed an issue where on iOS the createTask method (CacheAPI) was not returning the created task.

## [7.6.0] - 24-07-01

### Added
Expand Down
4 changes: 3 additions & 1 deletion ios/THEOplayerRCTBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ @interface RCT_EXTERN_REMAP_MODULE(THEORCTCacheModule, THEOplayerRCTCacheAPI, RC
rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(createTask:(NSDictionary)src
params:(NSDictionary)params)
params:(NSDictionary)params
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(startCachingTask:(nonnull NSString *)id)

Expand Down
10 changes: 7 additions & 3 deletions ios/cache/THEOplayerRCTCacheAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ let CACHE_EVENT_PROP_TASKS: String = "tasks"
let CACHE_TAG: String = "[CacheAPI]"

let ERROR_MESSAGE_CACHE_API_UNSUPPORTED_FEATURE = "Cache API is not supported for tvOS"
let ERROR_CODE_CREATE_CACHINGTASK_FAILED = "create_cachingtask_failure"
let ERROR_MESSAGE_CREATE_CACHINGTASK_FAILURE = "Creating a new cachingTask failed."

@objc(THEOplayerRCTCacheAPI)
class THEOplayerRCTCacheAPI: RCTEventEmitter {
Expand Down Expand Up @@ -140,22 +142,24 @@ class THEOplayerRCTCacheAPI: RCTEventEmitter {
] as [String : Any])
}

@objc(createTask:params:)
func createTask(_ src: NSDictionary, params: NSDictionary) -> Void {
@objc(createTask:params:resolver:rejecter:)
func createTask(_ src: NSDictionary, params: NSDictionary, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
if DEBUG_CACHE_API { PrintUtils.printLog(logText: "[NATIVE] createTask triggered on Cache API.") }
let params = THEOplayerRCTCachingParametersBuilder.buildCachingParameters(params)
let (sourceDescription, _) = THEOplayerRCTSourceDescriptionBuilder.buildSourceDescription(src)
if let srcDescription = sourceDescription,
let newTask = THEOplayer.cache.createTask(source: srcDescription, parameters: params) {
if DEBUG_CACHE_API { PrintUtils.printLog(logText: "[NATIVE] New cache task created with id \(newTask.id)") }

resolve(THEOplayerRCTCacheAggregator.aggregateCacheTask(task: newTask))
// emit onAddCachingTaskEvent
self.sendEvent(withName: "onAddCachingTaskEvent", body: [
CACHE_EVENT_PROP_TASK: THEOplayerRCTCacheAggregator.aggregateCacheTask(task: newTask)
])

// attach the state and progress listeners to the new task
self.attachTaskListenersToTask(newTask)
} else {
reject(ERROR_CODE_CREATE_CACHINGTASK_FAILED, ERROR_MESSAGE_CREATE_CACHINGTASK_FAILURE, nil)
}
}

Expand Down
Loading