Skip to content

Commit

Permalink
Merge pull request #345 from THEOplayer/bugfix/ios-return-created-cac…
Browse files Browse the repository at this point in the history
…he-task

Bugfix/ios return created cache task
  • Loading branch information
wvanhaevre authored Jul 16, 2024
2 parents 7ae95b2 + 57b26ee commit b70f2d6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
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

0 comments on commit b70f2d6

Please sign in to comment.