Skip to content
Draft
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
37 changes: 30 additions & 7 deletions Source/Renderer/CDNFileAssetLoader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,50 @@
#import <RiveRuntime/RiveRuntime-Swift.h>

@implementation CDNFileAssetLoader
{}
{
NSMutableArray<NSURLSessionTask*>* _activeTasks;
}

- (instancetype)init
{
if (self = [super init])
{
_activeTasks = [NSMutableArray array];
}
return self;
}

- (void)dealloc
{
for (NSURLSessionTask* task in _activeTasks)
{
[task cancel];
}
}

- (bool)loadContentsWithAsset:(RiveFileAsset*)asset
andData:(NSData*)data
andFactory:(RiveFactory*)factory
{
// TODO: Error handling
// TODO: Track tasks, so we can cancel them if we garbage collect the asset
// loader

if ([[asset cdnUuid] length] > 0)
{
NSURL* URL =
[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",
[asset cdnBaseUrl],
[asset cdnUuid]]];
NSURLSessionTask* task = [[NSURLSession sharedSession]
__block NSURLSessionTask* task = nil;
__weak CDNFileAssetLoader* weakSelf = self;
task = [[NSURLSession sharedSession]
downloadTaskWithURL:URL
completionHandler:^(
NSURL* location, NSURLResponse* response, NSError* error) {
CDNFileAssetLoader* strongSelf = weakSelf;
if (strongSelf)
{
[strongSelf->_activeTasks removeObject:task];
}
if (!error)
{
// Load the data into the reader
Expand Down Expand Up @@ -65,9 +89,8 @@ - (bool)loadContentsWithAsset:(RiveFileAsset*)asset
}
}];

// Kick off the http download
// QUESTION: Do we need to tie this into the RiveFile so we can wait for
// these loads to be completed?
// Track and start the download
[_activeTasks addObject:task];
[task resume];
return true;
}
Expand Down